Method: RSpec::Expectations.fail_with

Defined in:
lib/rspec/expectations/fail_with.rb

.fail_with(message, expected = nil, actual = nil) ⇒ Object

Raises an RSpec::Expectations::ExpectationNotMetError with message. Adds a diff to the failure message when expected and actual are both present.

Parameters:

  • message (String)
  • expected (Object) (defaults to: nil)
  • actual (Object) (defaults to: nil)


27
28
29
30
31
32
33
34
35
36
# File 'lib/rspec/expectations/fail_with.rb', line 27

def fail_with(message, expected=nil, actual=nil)
  unless message
    raise ArgumentError, "Failure message is nil. Does your matcher define the " \
                         "appropriate failure_message[_when_negated] method to return a string?"
  end

  message = ::RSpec::Matchers::MultiMatcherDiff.from(expected, actual).message_with_diff(message, differ)

  RSpec::Support.notify_failure(RSpec::Expectations::ExpectationNotMetError.new message)
end