本文介绍了为什么 Rspec 会说“失败/错误:无法从回溯中找到匹配的行"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我正在关注 Rails 教程:http://railstutorial.org/chapters/filling-in-the-layout#top

I'm following the rails tutorial here: http://railstutorial.org/chapters/filling-in-the-layout#top

当我运行rspec spec/"时,我收到了一堆如下所示的错误:

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

但是当我在我的网络浏览器中访问 localhost:3000/和 localhost:3000/contact 时,页面在那里,正确的标题也在那里.这是我的 myrailsrootspecequestslayout_links_spec.rb 文件:

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 myrailsrootspecequestslayout_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

推荐答案

这是由于 RSpec 2.0.0.beta.19 中的错误造成的.如果您按照教程建议使用 2.0.0.beta.18,它将正常工作.只需将 Gemfile 中的任何版本更改为 beta 18,捆绑安装并再次运行测试.

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.

这是我的 Gemfile 中的相关部分.

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

另请注意,Spork 也会时不时地导致这样的问题.如果您遇到莫名其妙的测试失败,特别是如果您刚刚添加了新的控制器或动作,请尝试一下.按 Ctrl-C 并再次运行 spork 服务器.

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.

这篇关于为什么 Rspec 会说“失败/错误:无法从回溯中找到匹配的行"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-07 02:12