Sha256: 46ac2649bae598a26f0b62a4c067edbbb9a898762806100589b966ef13a0ebaf

Contents?: true

Size: 952 Bytes

Versions: 17

Compression:

Stored size: 952 Bytes

Contents

require 'pathname'

require 'rspec/matchers'

class RSpec::Matchers::DSL::Matcher
  attr_writer :expected
end

RSpec::Matchers.define :differ_from do |expected|
  match do |actual|
    case expected
    when Pathname
      @m = have_different_contents
      @m.expected = expected
      @m.matches?(actual)
    when Array
      # If we pass "expected" here, it expects an array.
      # Works here, but not for Pathname or String
      # Hence the need for the attr_writer hack above.
      @m = be_different_array_from
      @m.expected = expected
      @m.matches?(actual)
    when String
      @m = have_different_contents
      @m.expected = expected
      @m.matches?(actual)
    else
      raise "DiffMatcher doesn't know how to match a #{expected.class}"
    end
  end

  failure_message_for_should do |actual|
    @m.failure_message_for_should
  end

  failure_message_for_should_not do |actual|
    @m.failure_message_for_should_not
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
activefacts-1.6.0 spec/helpers/diff_matcher.rb
activefacts-1.5.3 spec/helpers/diff_matcher.rb
activefacts-1.5.2 spec/helpers/diff_matcher.rb
activefacts-1.5.1 spec/helpers/diff_matcher.rb
activefacts-1.5.0 spec/helpers/diff_matcher.rb
activefacts-1.3.0 spec/helpers/diff_matcher.rb
activefacts-1.2.1 spec/helpers/diff_matcher.rb
activefacts-1.2.0 spec/helpers/diff_matcher.rb
activefacts-1.1.0 spec/helpers/diff_matcher.rb
activefacts-1.0.2 spec/helpers/diff_matcher.rb
activefacts-1.0.1 spec/helpers/diff_matcher.rb
activefacts-1.0.0 spec/helpers/diff_matcher.rb
activefacts-0.8.18 spec/helpers/diff_matcher.rb
activefacts-0.8.16 spec/helpers/diff_matcher.rb
activefacts-0.8.15 spec/helpers/diff_matcher.rb
activefacts-0.8.13 spec/helpers/diff_matcher.rb
activefacts-0.8.12 spec/helpers/diff_matcher.rb