Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.