Sha256: 24339ca3416cdf9662e848cf7e2522ac2ac1ba7f23b47afc92ad7d9635363505
Contents?: true
Size: 1.07 KB
Versions: 5
Compression:
Stored size: 1.07 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 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
5 entries across 5 versions & 1 rubygems