Sha256: 10ee2627baa6894eb5af6e9c9ed32ca1247bf54a32198a83ef50f2058a2869b6

Contents?: true

Size: 1.1 KB

Versions: 35

Compression:

Stored size: 1.1 KB

Contents

RSpec::Support.require_rspec_support 'differ'

module RSpec
  module Expectations
    class << self
      # @private
      def differ
        RSpec::Support::Differ.new(
          :object_preparer => lambda { |object| RSpec::Matchers::Composable.surface_descriptions_in(object) },
          :color => RSpec::Matchers.configuration.color?
        )
      end

      # Raises an RSpec::Expectations::ExpectationNotMetError with message.
      # @param [String] message
      # @param [Object] expected
      # @param [Object] actual
      #
      # Adds a diff to the failure message when `expected` and `actual` are
      # both present.
      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

        diff = differ.diff(actual, expected)
        message = "#{message}\nDiff:#{diff}" unless diff.empty?

        raise RSpec::Expectations::ExpectationNotMetError, message
      end
    end
  end
end

Version data entries

35 entries across 32 versions & 9 rubygems

Version Path
opal-rspec-0.8.0 rspec-expectations/upstream/lib/rspec/expectations/fail_with.rb
opal-rspec-0.8.0.alpha3 rspec-expectations/upstream/lib/rspec/expectations/fail_with.rb
opal-rspec-0.8.0.alpha2 rspec-expectations/upstream/lib/rspec/expectations/fail_with.rb
opal-rspec-0.8.0.alpha1 rspec-expectations/upstream/lib/rspec/expectations/fail_with.rb
opal-rspec-0.7.1 rspec-expectations/upstream/lib/rspec/expectations/fail_with.rb
opal-rspec-0.7.0 rspec-expectations/upstream/lib/rspec/expectations/fail_with.rb
opal-rspec-0.6.2 rspec-expectations/lib/rspec/expectations/fail_with.rb
opal-rspec-0.7.0.rc.2 rspec-expectations/upstream/lib/rspec/expectations/fail_with.rb
opal-rspec-0.6.1 rspec-expectations/lib/rspec/expectations/fail_with.rb
opal-rspec-0.6.0 rspec-expectations/lib/rspec/expectations/fail_with.rb
opal-rspec-0.6.0.beta1 rspec-expectations/lib/rspec/expectations/fail_with.rb
opal-connect-rspec-0.5.0 rspec-expectations/lib/rspec/expectations/fail_with.rb
able-neo4j-1.0.0 vendor/bundle/jruby/1.9/gems/rspec-expectations-3.1.2/lib/rspec/expectations/fail_with.rb
honeybadger-2.4.0 vendor/gems/ruby/2.2.0/gems/rspec-expectations-3.1.0/lib/rspec/expectations/fail_with.rb
honeybadger-2.4.0 vendor/gems/ruby/2.1.0/gems/rspec-expectations-3.1.0/lib/rspec/expectations/fail_with.rb
honeybadger-2.4.0 vendor/gems/ruby/1.9.1/gems/rspec-expectations-3.1.0/lib/rspec/expectations/fail_with.rb
opal-rspec-0.5.0 rspec-expectations/lib/rspec/expectations/fail_with.rb
logstash-input-beats-2.0.2 vendor/jruby/1.9/gems/rspec-expectations-3.1.2/lib/rspec/expectations/fail_with.rb
logstash-input-beats-2.0.2 vendor/jruby/1.9/gems/logstash-codec-json-2.0.3/vendor/gems/rspec-expectations-3.1.2/lib/rspec/expectations/fail_with.rb
logstash-codec-json-2.0.3 vendor/gems/rspec-expectations-3.1.2/lib/rspec/expectations/fail_with.rb