Created
March 15, 2010 04:21
-
-
Save ion1/332500 to your computer and use it in GitHub Desktop.
have_a_member matcher for Rspec 2
This file contains 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
require 'rspec/matchers' | |
[[:have_a_member, "have a member", :any?], | |
[:have_every_member, "have every member", :all?]]. | |
each do |name, desc, iterator| | |
Rspec::Matchers.define name do |matcher| | |
match do |actual| | |
actual.send(iterator) {|member| matcher.matches? member } | |
end | |
description do | |
begin | |
"#{desc} #{matcher.description}" | |
rescue | |
"#{desc} match #{matcher.inspect}" | |
end | |
end | |
failure_message_for_should do |actual| | |
"expected #{actual.inspect} to #{description}" | |
end | |
failure_message_for_should_not do |actual| | |
"expected #{actual.inspect} not to #{description}" | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment