Guest User

Untitled

a guest
Mar 8th, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.53 KB | None | 0 0
  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
Add Comment
Please, Sign In to add comment