RSpec 2 Gotcha with polymorphic_path

December 8, 2010 Pivotal Labs

A quick gotcha we ran into when using polymorphic path and rspec2 today.

In a controller test we had an assertion:

response.should redirect_to(polymorphic_path(@some_object))

Which resulted in the following error

Failure/Error: Unable to find matching line from backtrace stack level too deep
# ~/.rvm/gems/ruby-1.9.2-p0@gemset/gems/rspec-expectations-2.1.0/lib/rspec/matchers/method_missing.rb:4

It turns out polymorphic path is not available in the controller test (but the usual object_path method is). As to why this throws a stack level too deep and not a method undefined looks like potentially another bug in rspec but the solution seemed to be to do the following in our spec_helper.b for Rails 3:

include Rails.application.routes.url_helpers

For Rails 2.x you’ll want to use:

include ActionController::UrlWriter

I’ve opened an issue for this on github as well

About the Author


Pairing tete-a-tete
Pairing tete-a-tete

At Pivotal Labs, we spend most of the day pair programming. The typical setup is an Apple iMac with a keyb...

ActiveHash 0.9.0 released for Rails 3
ActiveHash 0.9.0 released for Rails 3

I recently released active_hash-0.9.0 which should work with Rails 3 / ActiveModel. If you use previous ...

SpringOne Platform 2019 Presentations

Watch Now