Why is Rspec saying "Failure/Error: Unable to find matching line from backtrace"?
Solution 1
This is due to a bug in RSpec 2.0.0.beta.19. If you use 2.0.0.beta.18 as the tutorial suggests, it will work fine. Just change whatever version you have in your Gemfile to beta 18, bundle install and run the tests again.
Here's the relevant parts from my Gemfile.
group :development do
gem 'rspec-rails', '2.0.0.beta.18'
end
group :test do
gem 'rspec-rails', '2.0.0.beta.18'
gem 'spork', '0.8.4'
end
Also note that Spork can also cause problems like this from time to time. If you get inexplicable test failures, especially if you just added new controllers or actions, go give spork a kick. Hit Ctrl-C and run the spork server again.
Solution 2
my gemfile looked like this and it works
group :test do
gem 'rspec-rails'
gem 'webrat', '0.7.1'
end
where rspec-rails (2.1.0)
however following doesn't:
group :test do
gem 'rspec-rails'
gem 'webrat', '0.7.2'
end
So I think it is webrat plays up.
Solution 3
I upgraded to beta.20 which is now out. Had to add webrat into my gemfile and do another bundle install. In the gemfile, it looks like this:
group :test do
gem "webrat"
gem 'rspec', '2.0.0.beta.20'
end
Cheers
Solution 4
I am only seeing this issue for two of my title tests.
My gemfile is as follows...
source 'http://rubygems.org'
gem 'rails', '3.0.0'
gem 'sqlite3-ruby', '1.2.5', :require => 'sqlite3'
gem 'gravatar_image_tag', '0.1.0'
gem 'will_paginate', '3.0.pre2'
group :development do
gem 'rspec-rails', '2.0.0.rc'
gem 'webrat', '0.7.1'
gem 'annotate-models', '1.0.4'
gem 'faker', '0.3.1'
end
group :test do
gem 'rspec', '2.0.0.rc'
gem 'webrat', '0.7.1'
gem 'spork', '0.8.4'
gem 'factory_girl_rails', '1.0'
end
I've tried the betas for rspec-rails as well, to no avail.
The two of the titles that are still giving me errors are the following:
From users_controller_spec.rc
it "should have the right title" do
get :index
response.should have_selector("title", :content => "All users")
end
#...
it "should have the right title" do
post :create, :user => @attr
response.should have_selector("title", :content => "Sign up")
end
The snippet from the errors reads:
Failures:
1) UsersController GET 'index' for signed-in users should have the right title
Failure/Error: response.should have_selector("title", :content => "All users")
expected following output to contain a <title>All users</title> tag:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>Ruby on Rails Tutorial Sample App | All Users</title>
and
2) UsersController Post 'create' for non-signed in users failure should have the right title
Failure/Error: response.should have_selector("title", :content => "Sign up")
expected following output to contain a <title>Sign up</title> tag:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>Ruby on Rails Tutorial Sample App | Sign Up</title>
respectively.
As seen by the output, "Sign Up" and "Index" are clearly shown to the right of the title. This is particularly perplexing in that, the following test does work:
it "should have the right title" do
get :new
response.should have_selector("title", :content => "Sign up")
end
Which is for the same page and contains the same title as the other "Sign Up" test. Also the get method works in this test but not in the "Index" test.
Help?
Solution 5
This doesn't seem to be an issue as of rspec 2.2.0
Comments
-
Chris about 4 years
I'm following the rails tutorial here: http://railstutorial.org/chapters/filling-in-the-layout#top
When I run "rspec spec/", I get a bunch of errors that look like this:
1) LayoutLinks should have a Home page at '/' Failure/Error: Unable to find matching line from backtrace stack level too deep # C:/Ruby19/lib/ruby/1.9.1/forwardable.rb:185 2) LayoutLinks should have a Contact page at '/contact' Failure/Error: Unable to find matching line from backtrace stack level too deep # C:/Ruby19/lib/ruby/1.9.1/forwardable.rb:185
But when I go in my web browser to localhost:3000/ and localhost:3000/contact, the pages are there and the correct titles are there. Here is my myrailsroot\spec\requests\layout_links_spec.rb file:
require 'spec_helper' describe "LayoutLinks" do it "should have a Home page at '/'" do get '/' response.should have_selector('title', :content => "Home") end it "should have a Contact page at '/contact'" do get '/contact' response.should have_selector('title', :content => "Contact") end it "should have an About page at '/about'" do get '/about' response.should have_selector('title', :content => "About") end it "should have a Help page at '/help'" do get '/help' response.should have_selector('title', :content => "Help") end it "should have a signup page at '/signup'" do get '/signup' response.should have_selector('title', :content => "Sign up") end end
Any ideas would be great, thanks
-
Mike Furtak over 13 yearsI was running into the same issue. This is exactly right. That's what I get for second-guessing the precise version specified in the tutorial!
-
AboutRuby over 13 yearsI obviously made the same mistake. But if you google, it doesn't seem many others are posting about the same thing. I guess most people just blindly copy from the tutorial and don't do something smart (stupid) like we did.
-
Chris over 13 yearsThere's a reason i couldn't use beta 18... I can't remember why, but it was not working, so i got beta 19 which fixed that bug but introduced this particular one. Frustrating.
-
Chris over 13 yearsAh found it - this is the bug that prevented me from using beta 18: github.com/rspec/rspec-rails/issues/closed#issue/145
-
Landitus over 13 yearsI'm having the exact same problem but I'm using beta.18. What can I do?
-
Kayla Rose over 13 years@Landitus I was having the same problem, for me, it turned out to be a webrat version issue, not rspec. See here stackoverflow.com/questions/3981852/…
-
bakasan over 13 yearsSame, test failures when not specifying a webrat version (which picks up 0.7.2). Specifying 0.7.1 specifically in my gem file moved the ball forward. My gemfile does not specify versions for rspec or spork, but they are currently 2.1.0 and 0.8.4 respectively.
-
Harry Steinhilber over 13 yearsThis got it for me as well. I was using rspec 2.1.0 and not using spork at all. Downgrading webrat to 0.7.1 from 0.7.2 fixed the error, though.
-
Ava over 11 yearsI am using rspec 2.11.1 still getting the same error. Any solution?
-
GS - Apologise to Monica over 9 yearsI think this does answer the question as it notes that webrat 0.7.1 fixes the problem.