Class: JsonMatcher::Matcher

Inherits:
Object
  • Object
show all
Includes:
Term::ANSIColor
Defined in:
lib/json_matcher.rb

Instance Method Summary collapse

Constructor Details

#initialize(actual, expected, opts = {}) ⇒ Matcher

Returns a new instance of Matcher.



14
15
16
17
18
19
20
21
# File 'lib/json_matcher.rb', line 14

def initialize actual, expected, opts = {}
  @actual = actual
  @expected = expected
  @actual_hash = JSON.parse actual
  @expected_hash = JSON.parse expected
  @options = opts
  @failure_msg = { :extra => {}, :less => {}}
end

Instance Method Details

#similar?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/json_matcher.rb', line 23

def similar?
  @options[:exact] ? equal : equal_without_order
end

#to_sObject



27
28
29
# File 'lib/json_matcher.rb', line 27

def to_s
  red { bold {"Diff:\n+#{@failure_msg[:extra].to_json}\n-#{@failure_msg[:less].to_json}" } }
end