Skip to content

Commit

Permalink
Merge pull request #333 from rspec/make_match_diffable
Browse files Browse the repository at this point in the history
expect().to match does not give a diff when failing
  • Loading branch information
JonRowe committed Oct 7, 2013
1 parent 9a68dd4 commit 9a500bf
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 1 deletion.
4 changes: 4 additions & 0 deletions Changelog.md
Expand Up @@ -9,6 +9,10 @@ Deprecations
(for Ruby's conditional semantics) or `be true`/`be false`
(for exact equality). (Sam Phippen)

Bug fixes:

* Make the `match` matcher produce a diff output (Jon Rowe, Ben Moss)

### 2.14.3 / 2013-09-22
[full changelog](http://github.com/rspec/rspec-expectations/compare/v2.14.2...v2.14.3)

Expand Down
2 changes: 1 addition & 1 deletion features/diffing.feature
Expand Up @@ -43,7 +43,7 @@ Feature: diffing
actual
string
ACTUAL
actual.should =~ expected
expect(actual).to match expected
end
end
"""
Expand Down
5 changes: 5 additions & 0 deletions lib/rspec/matchers/built_in/match.rb
Expand Up @@ -6,6 +6,11 @@ class Match < BaseMatcher
def match(expected, actual)
actual.match expected
end

def diffable?
true
end

end
end
end
Expand Down
13 changes: 13 additions & 0 deletions spec/rspec/matchers/match_spec.rb
Expand Up @@ -30,6 +30,19 @@
matcher.matches?("string")
expect(matcher.failure_message_for_should).to eq "expected \"string\" to match /rings/"
end

it "provides a diff on failure" do
allow(RSpec::Matchers.configuration).to receive(:color?).and_return(false)

failure_message_that_includes_diff = %r%
\s*Diff:
\s*@@ -1,2 \+1,2 @@
\s*-/bar/
\s*\+"foo"%

expect { expect("foo").to match(/bar/) }.to fail_with(failure_message_that_includes_diff)
end

end

describe "expect(...).not_to match(expected)" do
Expand Down

0 comments on commit 9a500bf

Please sign in to comment.