开发者

Exclamation mark used with assert method in its parameters

开发者 https://www.devze.com 2022-12-22 02:30 出处:网络
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

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

精彩评论

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