Skip to content

Instantly share code, notes, and snippets.

@samg
Created December 4, 2009 06:38
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 samg/248868 to your computer and use it in GitHub Desktop.
Save samg/248868 to your computer and use it in GitHub Desktop.
require 'rubygems'
require 'spec'
describe "iterative matchers" do
def all_be &block
simple_matcher "all be" do |given, matcher|
matcher.failure_message = "expected #{given.inspect} to all be something"
matcher.negative_failure_message = "expected #{given.inspect} to not all be something"
given.all? &block
end
end
def have_any &block
simple_matcher "have any" do |given, matcher|
matcher.failure_message = "expected #{given.inspect} to have at least one something"
matcher.negative_failure_message = "expected #{given.inspect} to not have any something"
given.any? &block
end
end
it "positive numbers should all be greater than 0" do
[1,2,3].should all_be { |x| x > 0 }
end
it "positive numbers should not have any less than 0" do
[1,2,3].should_not have_any { |x| x < 0 }
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment