views:

46

answers:

1

Okay this has been lingering in my head for quite 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.

+4  A: 

! 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.

Wayne Conrad
I believe you have a typo up there (first `true`)...
Mladen Jablanović
yeah. Got the idea.
Maxsy
@Mladen Jablanović, Thank you. Fixed.
Wayne Conrad