Why is Rspec saying “Failure/Error: Unable to find

2019-01-11 02:39发布

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

11条回答
【Aperson】
2楼-- · 2019-01-11 03:18

This doesn't seem to be an issue as of rspec 2.2.0

查看更多
三岁会撩人
3楼-- · 2019-01-11 03:23

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.

查看更多
时光不老,我们不散
4楼-- · 2019-01-11 03:23

haha, restarting spork and autotest did the trick. it does need a nice kick every now and then. i'm running rspec-rails 2.6.1 btw...

查看更多
来,给爷笑一个
5楼-- · 2019-01-11 03:27

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.

查看更多
ゆ 、 Hurt°
6楼-- · 2019-01-11 03:30

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

查看更多
淡お忘
7楼-- · 2019-01-11 03:30

"Kicked" Spork and fixed the problem for me.

查看更多
登录 后发表回答