Module: RSpec::Expectations

Defined in:
lib/rspec/expectations.rb,
lib/rspec/expectations/differ.rb,
lib/rspec/expectations/errors.rb,
lib/rspec/expectations/handler.rb,
lib/rspec/expectations/version.rb,
lib/rspec/expectations/fail_with.rb,
lib/rspec/expectations/backward_compatibility.rb

Overview

:nodoc:

Defined Under Namespace

Modules: ConstMissing, Version Classes: Differ, ExpectationNotMetError, InvalidMatcherError, NegativeExpectationHandler, PositiveExpectationHandler

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.differObject


4
5
6
# File 'lib/rspec/expectations/fail_with.rb', line 4

def differ
  @differ ||= Differ.new
end

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

raises a RSpec::Expectations::ExpectationNotMetError with message

When a differ has been assigned and fail_with is passed expected and actual, passes them to the differ to append a diff message to the failure message.


13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/rspec/expectations/fail_with.rb', line 13

def fail_with(message, expected=nil, actual=nil) # :nodoc:
  if !message
    raise ArgumentError, "Failure message is nil. Does your matcher define the " +
                         "appropriate failure_message_for_* method to return a string?"
  end

  if actual && expected
    if all_strings?(actual, expected)
      if any_multiline_strings?(actual, expected)
        message << "\nDiff:" << self.differ.diff_as_string(actual, expected)
      end
    elsif no_procs?(actual, expected) && no_numbers?(actual, expected)
      message << "\nDiff:" << self.differ.diff_as_object(actual, expected)
    end
  end

  raise(RSpec::Expectations::ExpectationNotMetError.new(message))
end

Instance Method Details

#differ=(ignore) ⇒ Object


10
11
12
# File 'lib/rspec/expectations/backward_compatibility.rb', line 10

def differ=(ignore)
  RSpec.deprecate("RSpec::Expectations.differ=(differ)", "nothing at all (diffing is now automatic and no longer configurable)")
end