[rspec-users] Name collision - how would you handle this?

David Chelimsky dchelimsky at gmail.com
Sun Aug 8 11:38:13 EDT 2010


On Aug 7, 2010, at 4:10 PM, David Chelimsky wrote:

> Hey all,
> 
> It turns out that if you have
> 
> * Rails (2 or 3)
> * Ruby-1.9
> * a model named Message
> * let(:message) or def message in an example group
> * a Rails assertion in an example in that group
>  * note that rspec-rails' matchers delegate to Rails' assertions
> 
> You'll get an error saying "wrong number of arguments (1 for 0)"
> 
> This is because the rails assertion, which, when running with Ruby-1.9, delegates to Minitest::Assertions#assert_block, which delegates to a message() method that it defines. So the message() method defined by let() overrides the message() method in the Assertions module, and results in unexpected and undesirable outcomes.
> 
> So - what should we do? I don't think changing Minitest is really an option, as too many assertion libraries already wrap Minitest assertions. I don't think RSpec should be in the business of monitoring methods end-users define to make sure they're not overriding pre-existing methods (what if you override a method intentionally?). The only thing I'm left with is document this particular case and hope for the best, but that feels unsatisfactory as well.
> 
> Recommendations? Words of wisdom?

FYI - here's the issue that spawned this thread: http://github.com/rspec/rspec-rails/issues/152


More information about the rspec-users mailing list