M
Martin DeMello
Test::Unit could use a built-in antonym of assert, that succeeds if
its argument is either false or nil.
martin
its argument is either false or nil.
martin
Martin said:Test::Unit could use a built-in antonym of assert, that succeeds if
its argument is either false or nil.
Test::Unit could use a built-in antonym of assert, that succeeds if
its argument is either false or nil.
./ruby19 -Ilib -rtest/unit -e 'class X < Test::Unit::TestCase; def = test_x; refute true; end;end'
Test run options: --seed 53548
=20
Loaded suite -e
Started
F
Finished in 0.000635 seconds.
=20
1) Failure:
test_x(X) [-e:1]:
Failed refutation, no message given
=20
1 tests, 1 assertions, 1 failures, 0 errors, 0 skips
=20
Test run options: --seed 53548
But I think the issue is moot, because writing custom asserts is a
perfectly standard thing to do. That is, just write
=A0def assert_not(bool, *rest)
=A0 =A0assert(!bool, *rest)
=A0end
this is why minitest has refute, which means it is available in ruby 1.9:
Deny or Rebut would be better antonyms.
Refute isn't a very good antonym for assert.
=20
Refute means to disprove, assert means to claim that something is
true, but doesn't imply truth of that assertion.
=20
Deny or Rebut would be better antonyms.
Test::Unit could use a built-in antonym of assert, that succeeds if
its argument is either false or nil.
class Test::Unit::TestCase
def assert_nil_or_false(condition)
assert_nil(condition) && assert_false(condition)
end
end
uhhh... you're fired?
assert_block(message) do
object.nil? || object == false
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.