Skip to content

Instantly share code, notes, and snippets.

@leandroh
Forked from lifo/assertion_extensions.rb
Created June 19, 2009 02:20
Show Gist options
  • Save leandroh/132366 to your computer and use it in GitHub Desktop.
Save leandroh/132366 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