Module: MiniTest::Assertions

Defined in:
lib/json_expressions/minitest/assertions.rb

Instance Method Summary collapse

Instance Method Details

#assert_json_match(exp, act, msg = nil) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/json_expressions/minitest/assertions.rb', line 5

def assert_json_match(exp, act, msg = nil)
  unless JsonExpressions::Matcher === exp
    exp = JsonExpressions::Matcher.new(exp)
  end

  if String === act
    assert act = JSON.parse(act), "Expected #{mu_pp(act)} to be valid JSON"
  end

  assert exp =~ act, ->{ "Expected #{mu_pp(exp)} to match #{mu_pp(act)}\n" + exp.last_error}

  # Return the matcher
  return exp
end

#refute_json_match(exp, act, msg = nil) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/json_expressions/minitest/assertions.rb', line 20

def refute_json_match(exp, act, msg = nil)
  unless JsonExpressions::Matcher === exp
    exp = JsonExpressions::Matcher.new(exp)
  end

  if String === act
    assert act = JSON.parse(act), "Expected #{mu_pp(act)} to be valid JSON"
  end

  refute exp =~ act, "Expected #{mu_pp(exp)} to not match #{mu_pp(act)}"

  # Return the matcher
  return exp
end