Stack Level Too Deep with RSpec 2 and Webrat

I’m currently following along with the Ruby on Rails Tutorial, hoping to pick up some tips and improve my understanding of Rails 3. I recommend the tutorial, especially to people just learning Rails. For those with more experience, you’ll find certain aspects to be a bit elementary. However, I’m personally appreciating the focus on testing throughout the development process.

The Rails community is still catching up to the recently released Rails 3. RSpec, which the tutorial recommends for testing, is no exception. RSpec 2 is the latest version, and the first to bring compatibility with Rails 3. However, I’m finding that there are still a few kinks that need to be worked out.

Most of the issues I’ve encountered have been easy to solve. However, I encountered a particularly frustrating problem dealing with the interrelation between rspec-rails and webrat, which is described in this issue. It is a known problem that has been variously fixed and re-broken by commits to the two libraries in question.

When executing an integration test using the following code:

describe "LayoutLinks" do
  describe "GET /" do
    it "should have a Home page at '/'" do
      get '/'
      response.should have_selector('title', :content => "Home")

A failure is reported:

  1) LayoutLinks GET / should have a Home page at '/'
     Failure/Error: response.should have_selector('title', :content => "Home")
     stack level too deep
     # ./spec/requests/layout_links_spec.rb:8

I haven’t traced down the exact issue, but it appears to be caused by webrat 0.7.2, and its interaction with both rspec-rails 2.0.1 and 2.1.0. I attempted upgrading to webrat 0.7.2.beta.2, but that did not resolve the issue. However, downgrading to webrat 0.7.1 did.

Simply specify the following in your Gemfile:

group :test do
  gem "webrat", "0.7.1"

Execute bundle install to use webrat 0.7.1 and the error will be resolved.


Lonna Hanson
November 8, 2010 at 2:24 PM

Very interesting. I wish I knew more about programming.

November 14, 2010 at 5:04 PM

Man, I’m glad Google found me this post. Was having this same frustrating issue and the linked bug (which I also found) gave no hope of making this work properly. Installing webrat 0.7.1 solved it. You da man. Thanks!

November 18, 2010 at 3:46 PM

Was using the book to learn a bit more about RSpec testing, and had the same problem. Thanks for the heads up!

November 23, 2010 at 11:46 PM

W0W thank you so much. i spent the day trying to comb my code trying to find the issue. luckily it was’nt a stupid mistake!


November 29, 2010 at 11:09 PM

Thank you so much, this of course resolved my issue. I’ve spent 6 hours trying to figure this out.

Dave Doolin
December 12, 2010 at 10:22 PM

Interesting. I finished this tutorial about a month ago, and all my tests passed without having webrat in my Gemfile.

So I added it to see what would happen. Minor disaster ensued with incompatible rspec.

Now, I’ve got webrat 0.7.2 working correctly with rspec* 2.3.0. The only failure I have is in RelationshipsController “create” method with the ajax handler, but I think that’s my fault.

Post a comment