Skip to content

Instantly share code, notes, and snippets.

@ion1
Created March 15, 2010 04:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ion1/332500 to your computer and use it in GitHub Desktop.
Save ion1/332500 to your computer and use it in GitHub Desktop.
have_a_member matcher for Rspec 2
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