Sha256: a59df240f8d09eaef60bf365e43925fae66c9dc7d40212846dc55172413a5bc1

Contents?: true

Size: 1.04 KB

Versions: 6

Compression:

Stored size: 1.04 KB

Contents

# Uses the diff_matcher gem to provide advanced matching abilities, along with nice visual representation of the
# diff between actual and expected. The functionality set is very helpful for comparing hashes.
#
# Usage examples:
#  it { should be_matching(my_var) }
#  it { should be_matching(my_var).with_options(ignore_additional: true) }
#
# Options: by default, color_enabled is controlled by Rspec, and quiet is set to true.
RSpec::Matchers.define :be_matching do |expected|
  match do |actual|
    options = { :color_enabled => RSpec::configuration.color_enabled?, :quiet => true }.merge(@options || {})
    @difference = DiffMatcher::Difference.new(expected, actual, options)
    @difference.matching?
  end

  chain :with_options do |options|
    @options = options
  end

  failure_message do |actual|
    "diff is:\n" + @difference.to_s
  end

  failure_message_when_negated do |actual|
    "diff is:\n" + @difference.to_s
  end

  description do
    "match via DiffMatcher #{expected}" + (@options.blank? ? '' : " with options: #{@options}")
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
diff_matcher-2.9.0 lib/diff_matcher/rspec_3/matchers/diff_matcher.rb
diff_matcher-2.8.1 lib/diff_matcher/rspec_3/matchers/diff_matcher.rb
diff_matcher-2.8.0 lib/diff_matcher/rspec_3/matchers/diff_matcher.rb
diff_matcher-2.7.1 lib/diff_matcher/rspec_3/matchers/diff_matcher.rb
diff_matcher-2.7.0 lib/diff_matcher/rspec_3/matchers/diff_matcher.rb
diff_matcher-2.6.0 lib/diff_matcher/rspec_3/matchers/diff_matcher.rb