ruby-on-rails - 为什么 Rspec 说 "Failure/Error: Unable to find matching line from backtrace"?

标签 ruby-on-rails ruby ruby-on-rails-3 rspec autotest

我在这里学习 Rails 教程:http://railstutorial.org/chapters/filling-in-the-layout#top

当我运行“rspec spec/”时,我得到一堆如下所示的错误:

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 时,页面在那里并且正确的标题在那里。这是我的 myrailsroot\spec\requests\layout_links_spec.rb 文件:

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

任何想法都会很棒,谢谢

最佳答案

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

这是我的 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 有时也会导致此类问题。如果你遇到莫名其妙的测试失败,特别是如果你刚刚添加了新的 Controller 或 Action ,那就试试 spork。按 Ctrl-C 并再次运行 spork 服务器。

关于ruby-on-rails - 为什么 Rspec 说 "Failure/Error: Unable to find matching line from backtrace"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3517724/

相关文章:

ruby-on-rails - 在 Rspec 中使用数据库查询好不好?

ruby-on-rails - Ruby 哈希通过比较值合并

ruby-on-rails - Rails 如果存在则更新,否则使用 find_or_create_by 创建

ruby-on-rails-3 - RVM、Capistrano 和 bundle 程序路径问题

javascript - rails : How to execute function using a button without reload pages

ruby-on-rails - 如何避免 Rails 应用程序中任何地方的信用卡信息为 "saved"?

ruby - Selenium 在 Ruby capybara 测试中指定 chromedriver.exe 的路径

ruby-on-rails - 使用 capistrano 部署 "zero downtime"后, unicorn worker 超时

ruby-on-rails - 在本地/测试中开发时如何保持电子邮件公司的 IP 信任

Ruby irbrc_history 系统范围。如何在本地制作?