[英]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? 解释吗?
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. 为什么你得到一个语法错误的原因是,好,因为它是一个语法错误:
and
, or
,并not
没有在参数列表允许的。
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". 在ruby-talk邮件列表上对此进行了长时间的讨论,其中详细解释了为什么会这样,但我的解释基本上是“我们无法弄清楚如何在
yacc
执行此操作并切换到更好的解析器发电机工作太多,所以我们决定把它变成非法的“。
In addtion to Jörg answer. 另外还有Jörg的回答。 You may use:
你可以使用:
class FooTest < Test::Unit::TestCase
def test_foo
assert(! true)
assert( (not true))
end
end
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.