Module: MiniTest::Assertions

Defined in:
lib/minitest/great_expectations.rb

Instance Method Summary collapse

Instance Method Details

#assert_equal_contents(expected, actual, message = nil) ⇒ Object

Contents must be the same, but order doesn’t matter. (In rspec, this is “‘.should =~“`)



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/minitest/great_expectations.rb', line 8

def assert_equal_contents(expected, actual, message = nil)
  e_ary = expected.to_a
  a_ary = actual.to_a
  error_msgs = []
  missing_from_actual = e_ary - a_ary
  unless missing_from_actual.empty?
    error_msgs << "Missing expected elements:\n #{mu_pp missing_from_actual}"
  end
  missing_from_expected = a_ary - e_ary
  unless missing_from_expected.empty?
    error_msgs << "Extraneous actual elements:\n  #{mu_pp missing_from_expected}"
  end
  unless error_msgs.empty?
    message ||= "Expected:\n  #{mu_pp actual}\nto equal contents of:\n  #{mu_pp expected}."
    flunk("#{message}\n#{error_msgs.join("\n")}")
  end
end

#assert_false(obj, msg = nil) ⇒ Object

The first parameter must be “‘false“`, not just coercible to false.



55
56
57
58
# File 'lib/minitest/great_expectations.rb', line 55

def assert_false(obj, msg = nil)
  msg = message(msg) { "<false> expected but was #{mu_pp obj}" }
  assert obj == false, msg
end

#assert_falsy(obj, msg = nil) ⇒ Object



60
61
62
63
# File 'lib/minitest/great_expectations.rb', line 60

def assert_falsy(obj, msg = nil)
  msg = message(msg) { "Expected falsy but was #{mu_pp obj}" }
  assert !obj, msg
end

#assert_includes_all(expected, actual, message = nil) ⇒ Object

Every element in actual must be in expected, but expected may have additional elements.



27
28
29
30
31
32
33
# File 'lib/minitest/great_expectations.rb', line 27

def assert_includes_all(expected, actual, message = nil)
  missing_from_expected = expected.to_a - actual.to_a
  unless missing_from_expected.empty?
    message ||= "Expected:\n  #{mu_pp actual}\nto contain every element in:\n  #{mu_pp expected}."
    flunk("#{message}\nMissing expected elements:\n  #{mu_pp missing_from_expected}")
  end
end

#assert_includes_none(expected, actual, message = nil) ⇒ Object



35
36
37
38
39
40
41
# File 'lib/minitest/great_expectations.rb', line 35

def assert_includes_none(expected, actual, message = nil)
  unexpected = expected.to_a & actual.to_a
  unless unexpected.empty?
    message ||= "Expected:\n  #{mu_pp actual}\nnot to contain any element in:\n  #{mu_pp expected}."
    flunk("#{message}\nUnexpected elements:\n  #{mu_pp unexpected.sort}")
  end
end

#assert_true(obj, msg = nil) ⇒ Object

The first parameter must be “‘true“`, not coercible to true.



44
45
46
47
# File 'lib/minitest/great_expectations.rb', line 44

def assert_true(obj, msg = nil)
  msg = message(msg) { "<true> expected but was #{mu_pp obj}" }
  assert obj == true, msg
end

#assert_truthy(obj, msg = nil) ⇒ Object



49
50
51
52
# File 'lib/minitest/great_expectations.rb', line 49

def assert_truthy(obj, msg = nil)
  msg = message(msg) { "Expected truthy, but was #{mu_pp obj}" }
  assert obj, msg
end