Fix safe_assert_block message argument #29

merged 1 commit into from Jun 26, 2013


None yet
2 participants

tiegz commented Jun 26, 2013


Add a default message to safe_assert_block.


You can recreate this bug in the console of a fresh Rails 3.2 app with gem 'shoulda-context', '1.1.3':

require 'test/unit'
require 'shoulda'
include Test::Unit::Assertions
include Shoulda::Context::Assertions
safe_assert_block { true }

which raises this:

ArgumentError: assertion message must be String or Proc, but NilClass was given.
    from /.../lib/ruby/1.9.1/test/unit/assertions.rb:52:in `assert_block'
    from /.../gems/shoulda-context-1.1.3/lib/shoulda/context/assertions.rb:89:in `safe_assert_block'

So when using safe_assert_block without a message parameter (such as in assert_accepts/assert_rejects), you run into this error.

This is because shoulda-context uses the test-unit gem as a development dependency, which adds its own assert_block assertion with a default message (vs no default message in the test/unit version that most people use).

The real problem I think is the use of the test-unit gem because running tests on shoulda-context wouldn't catch this case, although there might be a good reason for it so I just went with a simple solution.

travisjeffery added a commit that referenced this pull request Jun 26, 2013

Merge pull request #29 from tiegz/fix_safe_assert_block
Fix safe_assert_block message argument

@travisjeffery travisjeffery merged commit b89b69f into thoughtbot:master Jun 26, 2013

1 check passed

default The Travis CI build passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment