Permalink
Browse files

simplify matcher DSL

  • Loading branch information...
1 parent 376eb78 commit 819ecf59447667e61f77caaa68049047be6e62c5 @dchelimsky committed Mar 4, 2009
Showing with 14 additions and 15 deletions.
  1. +4 −4 features/matchers/create_matcher.feature
  2. +8 −9 lib/spec/matchers/matcher.rb
  3. +2 −2 spec/spec/matchers/matcher_spec.rb
@@ -44,14 +44,14 @@ Feature: custom matcher shortcut
And the stdout should match "expected 9 to be a multiple of 4"
And the stdout should match "expected 9 not to be a multiple of 3"
- Scenario: override the failure_message_for(:should)
+ Scenario: override the failure_message_for_should
Given the following spec:
"""
Spec::Matchers.create :be_a_multiple_of do |expected|
match do |actual|
actual % expected == 0
end
- failure_message_for(:should) do |actual|
+ failure_message_for_should do |actual|
"expected that #{actual} would be a multiple of #{expected}"
end
end
@@ -66,14 +66,14 @@ Feature: custom matcher shortcut
And the stdout should match "1 example, 1 failure"
And the stdout should match "expected that 9 would be a multiple of 4"
- Scenario: override the failure_message_for(:should_not)
+ Scenario: override the failure_message_for_should_not
Given the following spec:
"""
Spec::Matchers.create :be_a_multiple_of do |expected|
match do |actual|
actual % expected == 0
end
- failure_message_for(:should_not) do |actual|
+ failure_message_for_should_not do |actual|
"expected that #{actual} would not be a multiple of #{expected}"
end
end
@@ -35,17 +35,16 @@ def negative_failure_message
@failure_message_for_should_not.call(@actual)
end
- def match(&block_passed_to_match)
- @match_block = block_passed_to_match
+ def match(&block)
+ @match_block = block
end
- def failure_message_for(should_or_should_not, &block)
- case should_or_should_not
- when :should
- @failure_message_for_should = block
- when :should_not
- @failure_message_for_should_not = block
- end
+ def failure_message_for_should(&block)
+ @failure_message_for_should = block
+ end
+
+ def failure_message_for_should_not(&block)
+ @failure_message_for_should_not = block
end
private
@@ -37,10 +37,10 @@ module Matchers
description do
"be the boolean #{boolean}"
end
- failure_message_for(:should) do |actual|
+ failure_message_for_should do |actual|
"expected #{actual} to be the boolean #{boolean}"
end
- failure_message_for(:should_not) do |actual|
+ failure_message_for_should_not do |actual|
"expected #{actual} not to be the boolean #{boolean}"
end
end

0 comments on commit 819ecf5

Please sign in to comment.