Why no assert_not?

Test::Unit could use a built-in antonym of assert, that succeeds if
its argument is either false or nil.

martin

Martin DeMello wrote:

Test::Unit could use a built-in antonym of assert, that succeeds if
its argument is either false or nil.

Hmm, I would have thought "assert not ..." would work, but there is
something odd in the parsing of 'not' as an argument:

$ ruby -v
ruby 1.8.7 (2010-01-10 patchlevel 249) [x86_64-linux]
$ irb --simple-prompt

not 1

=> false

not 3 < 4

=> false

puts(3 < 4)

true
=> nil

puts(not 3 < 4)

SyntaxError: compile error
(irb):4: syntax error, unexpected kNOT, expecting ')'
puts(not 3 < 4)
        ^
(irb):4: syntax error, unexpected ')', expecting $end
  from (irb):4

puts((not 3 < 4))

false

In the past I've just done assert !(...)

But I think the issue is moot, because writing custom asserts is a
perfectly standard thing to do. That is, just write

  def assert_not(bool, *rest)
    assert(!bool, *rest)
  end

···

from :0
--
Posted via http://www.ruby-forum.com/\.

Test::Unit could use a built-in antonym of assert, that succeeds if
its argument is either false or nil.

this is why minitest has refute, which means it is available in ruby 1.9:

···

On Sep 1, 2010, at 01:19 , Martin DeMello wrote:

./ruby19 -Ilib -rtest/unit -e 'class X < Test::Unit::TestCase; def test_x; refute true; end;end'
Test run options: --seed 53548

Loaded suite -e
Started
F
Finished in 0.000635 seconds.

  1) Failure:
test_x(X) [-e:1]:
Failed refutation, no message given

1 tests, 1 assertions, 1 failures, 0 errors, 0 skips

Test run options: --seed 53548

test-unit 2.x has assert_false and assert_nil if that's any help.
Actually, test-unit 1.x has assert_nil, too, I believe. You can always
add your own.

class Test::Unit::TestCase
  def assert_nil_or_false(condition)
    assert_nil(condition) && assert_false(condition)
  end
end

Regards,

Dan

···

On Sep 1, 2:19 am, Martin DeMello <martindeme...@gmail.com> wrote:

Test::Unit could use a built-in antonym of assert, that succeeds if
its argument is either false or nil.

Yeah, but this one seems universal enough that it ought to be there by default.

martin

···

On Wed, Sep 1, 2010 at 2:37 PM, Brian Candler <b.candler@pobox.com> wrote:

But I think the issue is moot, because writing custom asserts is a
perfectly standard thing to do. That is, just write

def assert_not(bool, *rest)
assert(!bool, *rest)
end

FWIW

Refute isn't a very good antonym for assert.

Refute means to disprove, assert means to claim that something is
true, but doesn't imply truth of that assertion.

Deny or Rebut would be better antonyms.

···

On Wed, Sep 1, 2010 at 5:12 AM, Ryan Davis <ryand-ruby@zenspider.com> wrote:

On Sep 1, 2010, at 01:19 , Martin DeMello wrote:

Test::Unit could use a built-in antonym of assert, that succeeds if
its argument is either false or nil.

this is why minitest has refute, which means it is available in ruby 1.9:

--
Rick DeNatale

Blog: http://talklikeaduck.denhaven2.com/
Github: rubyredrick (Rick DeNatale) · GitHub
Twitter: @RickDeNatale
WWR: http://www.workingwithrails.com/person/9021-rick-denatale
LinkedIn: http://www.linkedin.com/in/rickdenatale

uhhh... you're fired?

···

On Sep 1, 2010, at 12:47 , Daniel Berger wrote:

class Test::Unit::TestCase
def assert_nil_or_false(condition)
   assert_nil(condition) && assert_false(condition)
end
end

deny{} all the way.

Including many of the assert_not_yack_yack() out there should upgrade
to deny_yack_yack(). Less self-contradictory.

Also, Alex Chaffee's Wrong project has an assert{ yack yack } and
deny{ yack yack } where you write _anything_ for the yack yack, and
when it fails (or incorrectly succeeds!) it prints out all the details
of yack yack, including all intermediate variables names and their
values.

I wonder where he got the idea.

···

On Sep 1, 8:23 am, Rick DeNatale <rick.denat...@gmail.com> wrote:

Deny or Rebut would be better antonyms.

--
  Phlip
  Resume for Philip C Plumlee

blah blah blah... I've been through all of this before and in public no less. You had your chance. It is good enough and: "refute".size == "assert".size

···

On Sep 1, 2010, at 08:23 , Rick DeNatale wrote:

Refute isn't a very good antonym for assert.

Refute means to disprove, assert means to claim that something is
true, but doesn't imply truth of that assertion.

Deny or Rebut would be better antonyms.

Hah, that's what I get for not actually trying my own code out first.

module Test::Unit::Assertions
  def assert_nil_or_false(object, message = nil)
    message = build_message(message, '<?> is not false or nil.',
object)
    assert_block(message) do
      object.nil? || object == false
    end
  end
end

Regards,

Dan

···

On Sep 1, 2:12 pm, Ryan Davis <ryand-r...@zenspider.com> wrote:

On Sep 1, 2010, at 12:47 , Daniel Berger wrote:

> class Test::Unit::TestCase
> def assert_nil_or_false(condition)
> assert_nil(condition) && assert_false(condition)
> end
> end

uhhh... you're fired?

Hi --

···

On Thu, 2 Sep 2010, Daniel Berger wrote:

   assert_block(message) do
     object.nil? || object == false

!object would be equivalent there, and faster (about 1/3 the time for a
benchmark of mixed cases).

David

--
David A. Black, Senior Developer, Cyrus Innovation Inc.

   The Ruby training with Black/Brown/McAnally
   Compleat Philadelphia, PA, October 1-2, 2010
   Rubyist http://www.compleatrubyist.com