diff options
author | Jeremy Kemper <jeremy@bitsweat.net> | 2012-12-28 10:34:26 -0700 |
---|---|---|
committer | Jeremy Kemper <jeremy@bitsweat.net> | 2012-12-28 10:34:26 -0700 |
commit | f75addd06bbdde925d095a4d27ddd6fbdd9336ba (patch) | |
tree | 4fa1026c51d06d3eb57693f42c1f7e86e661bc0e /activesupport/lib | |
parent | 6b18a79abe03046e5f572df26fc201958d5b2d0b (diff) | |
download | rails-f75addd06bbdde925d095a4d27ddd6fbdd9336ba.tar.gz rails-f75addd06bbdde925d095a4d27ddd6fbdd9336ba.tar.bz2 rails-f75addd06bbdde925d095a4d27ddd6fbdd9336ba.zip |
Introduce assert_not to replace 'assert !foo'
Diffstat (limited to 'activesupport/lib')
-rw-r--r-- | activesupport/lib/active_support/testing/assertions.rb | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/activesupport/lib/active_support/testing/assertions.rb b/activesupport/lib/active_support/testing/assertions.rb index 8466049e20..88aebba5c5 100644 --- a/activesupport/lib/active_support/testing/assertions.rb +++ b/activesupport/lib/active_support/testing/assertions.rb @@ -3,6 +3,22 @@ require 'active_support/core_ext/object/blank' module ActiveSupport module Testing module Assertions + # Assert that an expression is not truthy. Passes if <tt>object</tt> is + # +nil+ or +false+. "Truthy" means "considered true in a conditional" + # like <tt>if foo</tt>. + # + # assert_not nil # => true + # assert_not false # => true + # assert_not 'foo' # => 'foo' is not nil or false + # + # An error message can be specified. + # + # assert_not foo, 'foo should be false' + def assert_not(object, message = nil) + message ||= "Expected #{mu_pp(object)} to be nil or false" + assert !object, message + end + # Test numeric difference between the return value of an expression as a # result of what is evaluated in the yielded block. # |