Module: MiniTest::Assertions
- Defined in:
- lib/minitest/great_expectations.rb
Instance Method Summary collapse
-
#assert_equal_contents(expected, actual, message = nil) ⇒ Object
Contents must be the same, but order doesn’t matter.
-
#assert_equal_hash(expected, actual, message = nil) ⇒ Object
Hash keys and values must be the same.
-
#assert_false(obj, msg = nil) ⇒ Object
The first parameter must be “‘false“`, not just coercible to false.
- #assert_falsy(obj, msg = nil) ⇒ Object
-
#assert_includes_all(expected, actual, message = nil) ⇒ Object
Every element in actual must be in expected, but expected may have additional elements.
- #assert_includes_none(expected, actual, message = nil) ⇒ Object
-
#assert_true(obj, msg = nil) ⇒ Object
The first parameter must be “‘true“`, not coercible to true.
- #assert_truthy(obj, msg = nil) ⇒ Object
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, = 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? ||= "Expected:\n #{mu_pp expected}\nDid not match contents of Actual:\n #{mu_pp actual}." flunk("#{}\n#{error_msgs.join("\n")}") end end |
#assert_equal_hash(expected, actual, message = nil) ⇒ Object
Hash keys and values must be the same
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/minitest/great_expectations.rb', line 27 def assert_equal_hash(expected, actual, = nil) e_keys = expected.keys a_keys = actual.keys error_msgs = [] missing_from_actual = e_keys - a_keys unless missing_from_actual.empty? error_msgs << "Missing expected keys:\n #{mu_pp missing_from_actual}" end missing_from_expected = a_keys - e_keys unless missing_from_expected.empty? error_msgs << "Extraneous actual keys:\n #{mu_pp missing_from_expected}" end intersecting_keys = e_keys & a_keys intersecting_keys.each do |ea| exp = expected[ea] act = actual[ea] unless exp == act error_msgs << "Expected [#{mu_pp ea}]: #{mu_pp exp}\nActual [#{mu_pp ea}]: #{mu_pp act}" end end unless error_msgs.empty? ||= "Expected:\n #{mu_pp expected}\ndid not equal Actual:\n #{mu_pp actual}." flunk("#{}\n#{error_msgs.join("\n")}") end end |
#assert_false(obj, msg = nil) ⇒ Object
The first parameter must be “‘false“`, not just coercible to false.
82 83 84 85 |
# File 'lib/minitest/great_expectations.rb', line 82 def assert_false(obj, msg = nil) msg = (msg) { "<false> expected but was #{mu_pp obj}" } assert obj == false, msg end |
#assert_falsy(obj, msg = nil) ⇒ Object
87 88 89 90 |
# File 'lib/minitest/great_expectations.rb', line 87 def assert_falsy(obj, msg = nil) msg = (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.
54 55 56 57 58 59 60 |
# File 'lib/minitest/great_expectations.rb', line 54 def assert_includes_all(expected, actual, = nil) missing_from_expected = expected.to_a - actual.to_a unless missing_from_expected.empty? ||= "Expected:\n #{mu_pp expected}\ndid not contain every element in Actual:\n #{mu_pp actual}." flunk("#{}\nMissing expected elements:\n #{mu_pp missing_from_expected}") end end |
#assert_includes_none(expected, actual, message = nil) ⇒ Object
62 63 64 65 66 67 68 |
# File 'lib/minitest/great_expectations.rb', line 62 def assert_includes_none(expected, actual, = nil) unexpected = expected.to_a & actual.to_a unless unexpected.empty? ||= "Expected:\n #{mu_pp expected}\ncontained elements in Actual:\n #{mu_pp actual}." flunk("#{}\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.
71 72 73 74 |
# File 'lib/minitest/great_expectations.rb', line 71 def assert_true(obj, msg = nil) msg = (msg) { "<true> expected but was #{mu_pp obj}" } assert obj == true, msg end |
#assert_truthy(obj, msg = nil) ⇒ Object
76 77 78 79 |
# File 'lib/minitest/great_expectations.rb', line 76 def assert_truthy(obj, msg = nil) msg = (msg) { "Expected truthy, but was #{mu_pp obj}" } assert obj, msg end |