Sha256: 75206d8ac59c0d2df7df20575f73dda0a05f78c4321452981daed5e73fec73d7

Contents?: true

Size: 1.08 KB

Versions: 10

Compression:

Stored size: 1.08 KB

Contents

# Uses the diff_matcher gem to provide advanced matching abilities, along with nice visual representation of the
# diff between JSON.parse(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_json_matching do |expected|
  match do |actual|
    options = { :color_enabled => RSpec::configuration.color_enabled?, :quiet => true }.merge(@options || {})
    @difference = DiffMatcher::Difference.new(expected, JSON.parse(actual), options)
    @difference.matching?
  end

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

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

  failure_message_for_should_not 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

10 entries across 5 versions & 1 rubygems

Version Path
diff_matcher-2.9.0 lib/diff_matcher/rspec/matchers/diff_matcher.rb
diff_matcher-2.9.0 lib/diff_matcher/rspec/matchers/diff_json_matcher.rb
diff_matcher-2.8.1 lib/diff_matcher/rspec/matchers/diff_json_matcher.rb
diff_matcher-2.8.1 lib/diff_matcher/rspec/matchers/diff_matcher.rb
diff_matcher-2.8.0 lib/diff_matcher/rspec/matchers/diff_matcher.rb
diff_matcher-2.8.0 lib/diff_matcher/rspec/matchers/diff_json_matcher.rb
diff_matcher-2.7.1 lib/diff_matcher/rspec/matchers/diff_matcher.rb
diff_matcher-2.7.1 lib/diff_matcher/rspec/matchers/diff_json_matcher.rb
diff_matcher-2.7.0 lib/diff_matcher/rspec/matchers/diff_json_matcher.rb
diff_matcher-2.7.0 lib/diff_matcher/rspec/matchers/diff_matcher.rb