1
0
Fork 0
mirror of https://github.com/thoughtbot/shoulda-matchers.git synced 2022-11-09 12:01:38 -05:00

Define fail_with_message_including matcher

This commit is contained in:
Yukio Mizuta 2014-01-19 18:29:43 -08:00 committed by Elliot Winkler
parent 4539834239
commit 6d1da0093f

View file

@ -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