Skip to content

Instantly share code, notes, and snippets.

@noelrappin
Created June 15, 2009 12:26
Show Gist options
  • Save noelrappin/130073 to your computer and use it in GitHub Desktop.
Save noelrappin/130073 to your computer and use it in GitHub Desktop.
def assert_methods(actual, methods = {})
methods.each do |method, value|
assert_equal(value, actual.send(method),
"For method #{method} expected <#{value}>, got <#{actual.send(method)}>")
end
end
## usage:
assert_methods(@user, :name => "Fred", :email => "fred@fred.com", :comment_count => 12)
## Completely untested version for Matchy
def_matcher :have_values do |receiver, matcher, args|
args.each do |method, value|
assert_equal(value, receiver.send(method),
"For method #{method} expected <#{value}>, got <#{receiver.send(method)}>")
end
end
## usage
@user.should have_values(:name => "Fred", :email => "fred@fred.com", :comment_count => 12)
## Completely untested RSpec version
Spec::Matchers.create :have_values do |methods|
match do |actual|
methods.each do |method, value|
assert_equal(value, actual.send(method),
"For method #{method} expected <#{value}>, got <#{actual.send(method)}>")
end
end
end
## usage
@user.should have_values(:name => "Fred", :email => "fred@fred.com", :comment_count => 12)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment