From f75addd06bbdde925d095a4d27ddd6fbdd9336ba Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Fri, 28 Dec 2012 10:34:26 -0700 Subject: Introduce assert_not to replace 'assert !foo' --- activesupport/lib/active_support/testing/assertions.rb | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'activesupport/lib') 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 object is + # +nil+ or +false+. "Truthy" means "considered true in a conditional" + # like if foo. + # + # 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. # -- cgit v1.2.3