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
- .differ ⇒ Object
-
.fail_with(message, expected = nil, actual = nil) ⇒ Object
raises a RSpec::Expectations::ExpectationNotMetError with message.
Instance Method Summary collapse
Class Method Details
.differ ⇒ Object
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(, expected=nil, actual=nil) # :nodoc: if ! 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) << "\nDiff:" << self.differ.diff_as_string(actual, expected) end elsif no_procs?(actual, expected) && no_numbers?(actual, expected) << "\nDiff:" << self.differ.diff_as_object(actual, expected) end end raise(RSpec::Expectations::ExpectationNotMetError.new()) end |