Rom1
Rom1

Reputation: 3207

not in ruby test/unit assertions

This does not work as I expect:

class FooTest < Test::Unit::TestCase
   def test_foo
      assert(not true)
   end
end

I expected a failing test, instead I get:

SyntaxError: ./test.rb:10: syntax error, unexpected kNOT
assert(not true)

Explanations?

Upvotes: 2

Views: 170

Answers (2)

knut
knut

Reputation: 27855

In addtion to Jörg answer. You may use:

class FooTest < Test::Unit::TestCase
   def test_foo
      assert(! true)
      assert( (not true))
   end
end

Upvotes: 1

J&#246;rg W Mittag
J&#246;rg W Mittag

Reputation: 369458

The reason why you are getting a syntax error is, well, because it's a syntax error: and, or and not aren't allowed in an argument list.

There has been a lengthy discussion about this on the ruby-talk mailinglist, where it was explained exactly why that is the case, but my interpretation basically is "we couldn't figure out how to do it in yacc and switching to a better parser generator was too much work, so we just decided to make it illegal instead".

Upvotes: 7

Related Questions