Skip to content

Instantly share code, notes, and snippets.

@lifo
Created March 13, 2009 19:43
Show Gist options
  • Save lifo/78731 to your computer and use it in GitHub Desktop.
Save lifo/78731 to your computer and use it in GitHub Desktop.
module AssertionExtensions
def method_missing(method_id, *arguments, &block)
return super unless method_id.to_s =~ /^assert_(not_)?(.*)$/
method = "#{$2}?"
object = arguments.first
if $1
arguments.each do |object|
assert ! object.send(method), "#{method} is not false for #{object}"
end
else
arguments.each do |object|
assert object.send(method), "#{method} is not true for #{object}"
end
end
end
end
class ActiveSupport::TestCase
include AssertionExtensions
end
class PersonTest < ActiveSupport::TestCase
def test_is_admin
assert_admin people(:admin), people(:superuser)
assert_not_admin people(:foo), people(:guest)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment