Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

small refactoring of cover matcher and docs

  • Loading branch information...
commit dc2641021d77a9a52baccd88c1afe5a1abbcf5c6 1 parent f726c0d
@dchelimsky dchelimsky authored
View
3  features/Changelog.md
@@ -2,6 +2,9 @@
[full changelog](http://github.com/rspec/rspec-expectations/compare/v2.6.0.rc2...v2.6.0.rc4)
+* Enhancements
+ * range.should cover(*values) (Anders Furseth)
+
### 2.6.0.rc2 / 2011-04-18
[full changelog](http://github.com/rspec/rspec-expectations/compare/v2.5.0...v2.6.0.rc2)
View
4 features/built_in_matchers/README.md
@@ -65,3 +65,7 @@
[1,2,3].should include(1, 2)
{:a => 'b'}.should include(:a => 'b')
"this string".should include("is str")
+
+## Ranges (1.9 only)
+
+ (1..10).should cover(3)
View
19 lib/rspec/matchers/cover.rb
@@ -13,22 +13,21 @@ module Matchers
# (1..10).should cover(4, 6)
# (1..10).should cover(4, 6, 11) # will fail
# (1..10).should_not cover(11)
- # (1..10).should_not cover(5) # will fail
- def cover(*expected)
- Matcher.new :cover, *expected do |*_expected|
-
+ # (1..10).should_not cover(5) # will fail
+ #
+ # == Warning: Ruby >= 1.9 only
+ def cover(*expected_values)
+ Matcher.new :cover, *expected_values do |*_expected_values|
match_for_should do |actual|
- perform_match(:all?, actual, _expected)
+ _expected_values.all? &cover_value
end
match_for_should_not do |actual|
- perform_match(:none?, actual, _expected)
+ _expected_values.none? &cover_value
end
- def perform_match(predicate, actual, _expected)
- _expected.send(predicate) do |expected|
- actual.cover?(expected)
- end
+ def cover_value
+ lambda {|value| actual.cover?(value)}
end
end
end

3 comments on commit dc26410

@justinko

Nice refactor.

@dchelimsky
Owner

Thanks!

@dchelimsky
Owner

Hey @justinko - check out 0f6cf3d - I think it's even better now :)

Please sign in to comment.
Something went wrong with that request. Please try again.