Sha256: bf884681c93c563be2cab4aa497b5ce28f393fcd375a6a2050063574cc179d74

Contents?: true

Size: 1.82 KB

Versions: 33

Compression:

Stored size: 1.82 KB

Contents

module Spec
  module Expectations
    class << self
      attr_accessor :differ
      
      # raises a Spec::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
        if (Array === message) & (message.length == 3)
          ::Spec.warn(<<-NOTICE

*****************************************************************
DEPRECATION WARNING: you are using deprecated behaviour that will
be removed from a future version of RSpec.

* Support for matchers that return arrays from failure message
methods is deprecated.
* Instead, the matcher should return a string, and expose methods
for the expected() and actual() values.
*****************************************************************
NOTICE
          )
          message, expected, target = message[0], message[1], message[2]
        end
        unless (differ.nil? || expected.nil? || target.nil?)
          if expected.is_a?(String)
            message << "\n\n Diff:" << self.differ.diff_as_string(target.to_s, expected)
          elsif expected.is_a?(Hash) && target.is_a?(Hash)
            message << "\n\n Diff:" << self.differ.diff_as_hash(target, expected)
          elsif !target.is_a?(Proc)
            message << "\n\n Diff:" << self.differ.diff_as_object(target, expected)
          end
        end
        Kernel::raise(Spec::Expectations::ExpectationNotMetError.new(message))
      end
    end
  end
end

Version data entries

33 entries across 33 versions & 11 rubygems

Version Path
rspec-instructure-1.3.3 lib/spec/expectations/fail_with.rb
radiant-1.0.0 ruby-debug/ruby/1.8/gems/rspec-1.3.2/lib/spec/expectations/fail_with.rb
rspec-1.3.2 lib/spec/expectations/fail_with.rb
rspec-1.3.1 lib/spec/expectations/fail_with.rb
rspec-1.3.1.rc lib/spec/expectations/fail_with.rb
rspec-1.3.0 lib/spec/expectations/fail_with.rb
hubbub-0.0.11 lib/vendor/plugins/rspec/lib/spec/expectations/fail_with.rb
hubbub-0.0.10 lib/vendor/plugins/rspec/lib/spec/expectations/fail_with.rb
hubbub-0.0.9 lib/vendor/plugins/rspec/lib/spec/expectations/fail_with.rb
hubbub-0.0.8 lib/vendor/plugins/rspec/lib/spec/expectations/fail_with.rb
hubbub-0.0.6 lib/vendor/plugins/rspec/lib/spec/expectations/fail_with.rb
simple-templater-0.0.1.4 gems/gems/rspec-1.2.9/lib/spec/expectations/fail_with.rb
media-path-0.1.2 vendor/rspec/lib/spec/expectations/fail_with.rb
simple-templater-0.0.1.3 vendor/rspec/lib/spec/expectations/fail_with.rb
pupu-0.0.2.pre vendor/rspec/lib/spec/expectations/fail_with.rb
media-path-0.1.1.pre vendor/rspec/lib/spec/expectations/fail_with.rb
simple-templater-0.0.1.2 vendor/rspec/lib/spec/expectations/fail_with.rb
media-path-0.1.1 vendor/rspec/lib/spec/expectations/fail_with.rb
simple-templater-0.0.1.1 vendor/rspec/lib/spec/expectations/fail_with.rb
pupu-0.0.2 vendor/rspec/lib/spec/expectations/fail_with.rb