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_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 actual}\nto equal contents of:\n #{mu_pp expected}." 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.
55 56 57 58 |
# File 'lib/minitest/great_expectations.rb', line 55 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
60 61 62 63 |
# File 'lib/minitest/great_expectations.rb', line 60 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.
27 28 29 30 31 32 33 |
# File 'lib/minitest/great_expectations.rb', line 27 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 actual}\nto contain every element in:\n #{mu_pp expected}." flunk("#{}\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, = nil) unexpected = expected.to_a & actual.to_a unless unexpected.empty? ||= "Expected:\n #{mu_pp actual}\nnot to contain any element in:\n #{mu_pp expected}." 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.
44 45 46 47 |
# File 'lib/minitest/great_expectations.rb', line 44 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
49 50 51 52 |
# File 'lib/minitest/great_expectations.rb', line 49 def assert_truthy(obj, msg = nil) msg = (msg) { "Expected truthy, but was #{mu_pp obj}" } assert obj, msg end |