开发者

Exclamation mark used with assert method in its parameters

Okay this has been lingering in my head for qui开发者_StackOverflow社区te a while now. In ruby on rails unit testing there is an exclamation mark with the assert method. Here is an example

test "No empty values to be inserted" do 
   product = Produce.new
   assert !product.save
end

Let me know the function of the exclamation mark. Quick replies appreciated. Thanks.


! is Logical negation.

  • If product.save is truthy (that is, neither nil nor false), !product.save returns false.
  • If product.save is falsy (that is, either nil or false), !product.save returns true.

Therefore, assert !product.save means that product.save must return falsy for the test to pass.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜