Created
June 15, 2009 12:26
-
-
Save noelrappin/130073 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 => "[email protected]", :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 => "[email protected]", :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 => "[email protected]", :comment_count => 12) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment