Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Define fail_with_message_including matcher
- Loading branch information
1 parent
4539834
commit 6d1da00
Showing
1 changed file
with
33 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
RSpec::Matchers.define :fail_with_message_including do |expected| | ||
match do |block| | ||
@actual = nil | ||
|
||
begin | ||
block.call | ||
rescue RSpec::Expectations::ExpectationNotMetError => ex | ||
@actual = ex.message | ||
end | ||
|
||
@actual && @actual.include?(expected) | ||
end | ||
|
||
failure_message_for_should do | ||
msg = "Expectation should have failed with message including '#{expected}'" | ||
|
||
if @actual | ||
msg << ", actually failed with '#{@actual}'" | ||
else | ||
msg << ", but did not fail." | ||
end | ||
|
||
msg | ||
end | ||
|
||
failure_message_for_should_not do | ||
msg = "Expectation should not have failed with message including '#{expected}'" | ||
msg << ", but did." | ||
|
||
msg | ||
end | ||
|
||
end |