daily pastebin goal
47%
SHARE
TWEET

Untitled

a guest Mar 8th, 2018 47 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class FooTest < Test::Unit::TestCase
  2.   include PresenceAssertions
  3.  
  4.   # The options required to get a valid Foo.
  5.   @valid_options = { :name => 'qux', :other => 'bar' }
  6.  
  7.   def test_should_require_name
  8.     assert_presence_of 'Foo', :name
  9.   end
  10. end
  11.  
  12.  
  13. module PresenceAssertions
  14.   def assert_presence_of(klass, attribute)
  15.     obj = create_valid(klass, attribute => nil)
  16.     assert_equal false, obj.valid?
  17.   end
  18.  
  19.   def create_valid(klass, options)
  20.     Object.const_get(klass).create(@valid_options.merge(options))
  21.   end
  22. end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top