Module: Minitest::Assertions

Defined in:
lib/minitest-assert-json-equal.rb

Instance Method Summary collapse

Instance Method Details

#assert_json_equal(json_a, json_b, msg = nil) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/minitest-assert-json-equal.rb', line 9

def assert_json_equal(json_a, json_b, msg=nil)
  a = JSON.parse(json_a)
  b = JSON.parse(json_b)

  msg = message(msg, "") {
    "Expected json to match."
  }

  assert_equal a, b, msg
rescue JSON::ParserError
  msg = message(msg, "") {
    "JSON does not parse."
  }
  flunk msg
end

#refute_json_equal(json_a, json_b, msg = nil) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/minitest-assert-json-equal.rb', line 25

def refute_json_equal(json_a, json_b, msg=nil)
  a = JSON.parse(json_a)
  b = JSON.parse(json_b)

  msg = message(msg, "") {
    "Expected json to match."
  }

  refute_equal a, b, msg
rescue JSON::ParserError
  msg = message(msg, "") {
    "JSON does not parse."
  }
  flunk msg
end