Sha256: 3a4d99a276ad3443333df1a5d352317b73b11dec599f4c08a82c773eff390e0f

Contents?: true

Size: 1.06 KB

Versions: 16

Compression:

Stored size: 1.06 KB

Contents

module Rspec
  module Expectations
    class << self
      attr_accessor :differ
      
      # raises a Rspec::Expectations::ExpectationNotMetError with message
      #
      # When a differ has been assigned and fail_with is passed
      # <code>expected</code> and <code>target</code>, passes them
      # to the differ to append a diff message to the failure message.
      def fail_with(message, expected=nil, target=nil) # :nodoc:
        if message.nil?
          raise ArgumentError, "Failure message is nil. Does your matcher define the " +
                               "appropriate failure_message_for_* method to return a string?"
        end
        unless (differ.nil? || expected.nil? || target.nil?)
          if expected.is_a?(String)
            message << "\nDiff:" << self.differ.diff_as_string(target.to_s, expected)
          elsif !target.is_a?(Proc)
            message << "\nDiff:" << self.differ.diff_as_object(target, expected)
          end
        end
        Kernel::raise(Rspec::Expectations::ExpectationNotMetError.new(message))
      end
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
rspec-expectations-2.0.0.beta.8 lib/rspec/expectations/fail_with.rb
rspec-expectations-2.0.0.beta.7 lib/rspec/expectations/fail_with.rb
rspec-expectations-2.0.0.beta.6 lib/rspec/expectations/fail_with.rb
rspec-expectations-2.0.0.beta.5 lib/rspec/expectations/fail_with.rb
rspec-expectations-2.0.0.beta.4 lib/rspec/expectations/fail_with.rb
rspec-expectations-2.0.0.beta.3 lib/rspec/expectations/fail_with.rb
rspec-expectations-2.0.0.beta.2 lib/rspec/expectations/fail_with.rb
rspec-expectations-2.0.0.beta.1 lib/rspec/expectations/fail_with.rb
rspec-expectations-2.0.0.a10 lib/rspec/expectations/fail_with.rb
rspec-expectations-2.0.0.a9 lib/rspec/expectations/fail_with.rb
rspec-expectations-2.0.0.a8 lib/rspec/expectations/fail_with.rb
rspec-expectations-2.0.0.a7 lib/rspec/expectations/fail_with.rb
rspec-expectations-2.0.0.a6 lib/rspec/expectations/fail_with.rb
rspec-expectations-2.0.0.a5 lib/rspec/expectations/fail_with.rb
rspec-expectations-2.0.0.a4 lib/rspec/expectations/fail_with.rb
rspec-expectations-2.0.0.a3 lib/rspec/expectations/fail_with.rb