sconover / wrong

Wrong provides a general assert method that takes a predicate block. Assertion failure messages are rich in detail.
MIT License
434 stars 31 forks source link

wrong causes assert_select to fail #28

Open davidmiani opened 11 years ago

davidmiani commented 11 years ago

I am using rspec with wrong in a rails app. I have the followin in my spec_helper.rb file:

require "wrong/adapters/rspec"
Wrong.config.alias_assert :confirm

However, when I used assert_select, eg:

  assert_select 'tbody > tr', count: 4

I get the error:

RuntimeError: You must pass a block to Wrong's assert and deny methods

The exception is thrown from

~/.rvm/gems/ruby-1.9.3-p125/gems/actionpack-3.2.9/lib/action_dispatch/testing/assertions/selector.rb

on line 297:

assert matches.size >= min, message if min

It seems wrong is taking over Test::Unit's assert function, causing the function to crash. The alias_assert also doesn't help, since it just aliases the method - the assert method is still there.

I am currently using the following as a workaround:

obj = Object.new
class << obj
  include Test::Unit::Assertions
end
Wrong::Assert.send(:define_method, :assert) do |*args, &block|
  obj.assert(*args, &block)
end

It works, but it would be nice if a better solution was available.

alexch commented 11 years ago

assert_select is apparently using Test::Unit but you're only including the rspec adapter. Try requiring the test_unit adapter too and see if that works.

require 'wrong/adapters/test_unit'