Skip to content

Commit

Permalink
Remove misleading docs.
Browse files Browse the repository at this point in the history
They claim you can't use `match` matcher within` match` block,
but this now works.
  • Loading branch information
myronmarston committed Oct 4, 2013
1 parent 9e05e56 commit 805fe7c
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 37 deletions.
28 changes: 0 additions & 28 deletions features/custom_matchers/define_matcher.feature
Original file line number Diff line number Diff line change
Expand Up @@ -338,31 +338,3 @@ Feature: define matcher
| 4 examples, 2 failures |
| expected 9 to be a multiple of 2 |
| expected 9 not to be a multiple of 3 |

Scenario: matching against a regular expression
Given a file named "regular_expression_matcher_spec.rb" with:
"""ruby
# Due to Ruby's method dispatch mechanism, use the `#match_regex` alias
# rather than the `#match` matcher when defining custom matchers via the
# DSL.
RSpec::Matchers.define :be_valid_us_zipcode do
match do |actual|
expect(actual).to match_regex(/\A\d{5}(-\d{4})?\z/)
end
end
describe "30316" do
it { should be_valid_us_zipcode }
end
describe "30316-0001" do
it { should be_valid_us_zipcode }
end
describe "1000-61303" do
it { should_not be_valid_us_zipcode }
end
"""
When I run `rspec regular_expression_matcher_spec.rb`
Then the stdout should contain "3 examples, 0 failures"
9 changes: 0 additions & 9 deletions lib/rspec/matchers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -435,18 +435,9 @@ def include(*expected)
#
# expect(email).to match(/^([^\s]+)((?:[-a-z0-9]+\.)+[a-z]{2,})$/i)
# expect(email).to match("@example.com")
# expect(zipcode).to match_regex(/\A\d{5}(-\d{4})?\z/)
# expect(zipcode).to match_regex("90210")
#
# @note Due to Ruby's method dispatch mechanism, using the `#match` matcher
# within a custom matcher defined via the matcher DSL
# (`RSpec::Matcher.define`) will result Ruby calling the wrong `#match`
# method and raising an `ArgumentError`. Instead, use the aliased
# `#match_regex` method.
def match(expected)
BuiltIn::Match.new(expected)
end

alias_method :match_regex, :match

# With no args, matches if any error is raised.
Expand Down

0 comments on commit 805fe7c

Please sign in to comment.