Module: MiniTest::Assertions
- Defined in:
- lib/minitest-extra-assertions.rb
Instance Method Summary collapse
- #assert_between(*args) ⇒ Object
- #assert_false(obj, msg = nil) ⇒ Object
-
#assert_match(exp, act, msg = nil) ⇒ Object
This actually conflicts with behavior in minitest proper; this mimics the old Test::Unit implementation, relying on the #=~ method of the actual object.
- #assert_true(obj, msg = nil) ⇒ Object
Instance Method Details
#assert_between(*args) ⇒ Object
24 25 26 27 28 29 30 31 32 |
# File 'lib/minitest-extra-assertions.rb', line 24 def assert_between(*args) hi, lo, exp, msg = if args.first.is_a?(Range) [args.first.begin, args.first.end, args[1], args[2]] else args[0..3] end msg = (msg) { "Expected #{mu_pp(exp)} to be between #{mu_pp(lo)} and #{mu_pp(hi)}" } assert (lo < exp && exp < hi) || (hi < exp && exp < lo), msg end |
#assert_false(obj, msg = nil) ⇒ Object
3 4 5 6 |
# File 'lib/minitest-extra-assertions.rb', line 3 def assert_false obj, msg = nil msg = (msg) { "<false> expected but was #{mu_pp(obj)}" } assert obj == false, msg end |
#assert_match(exp, act, msg = nil) ⇒ Object
This actually conflicts with behavior in minitest proper; this mimics the old Test::Unit implementation, relying on the #=~ method of the actual object. Minitest calls #=~ on the matcher instead, which is honestly better by the POLS but makes it much more difficult to test objects that have custom #=~ implementations.
17 18 19 20 21 22 |
# File 'lib/minitest-extra-assertions.rb', line 17 def assert_match exp, act, msg = nil msg = (msg) { "Expected #{mu_pp(exp)} to match #{mu_pp(act)}" } assert_respond_to act, "=~" exp = Regexp.new(Regexp.escape(exp)) if String === exp assert act =~ exp, msg end |
#assert_true(obj, msg = nil) ⇒ Object
8 9 10 11 |
# File 'lib/minitest-extra-assertions.rb', line 8 def assert_true obj, msg = nil msg = (msg) { "<true> expected but was #{mu_pp(obj)}" } assert obj == true, msg end |