为什么 Rspec 说“失败/错误:无法从回溯中找到匹配行”?
我在这里关注 Rails 教程: http://railstutorial.org/chapters/ fill-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
任何想法都会很棒,谢谢
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(11)
这是由于 RSpec 2.0.0.beta.19 中的错误造成的。如果您按照教程建议使用 2.0.0.beta.18,它将正常工作。只需将 Gemfile 中的任何版本更改为 beta 18,捆绑安装并再次运行测试即可。
这是我的 Gemfile 中的相关部分。
另请注意,Spork 有时也会导致此类问题。如果您遇到莫名其妙的测试失败,特别是如果您刚刚添加了新的控制器或操作,请尝试一下 spork。按 Ctrl-C 并再次运行 spork 服务器。
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.
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.
我的 gemfile 看起来像这样,它可以
在 rspec-rails (2.1.0) 的地方
工作,但是以下不行:
所以我认为这是 webrat 发挥作用。
my gemfile looked like this and it works
where rspec-rails (2.1.0)
however following doesn't:
So I think it is webrat plays up.
我升级到 beta.20,现已发布。必须将 webrat 添加到我的 gemfile 中并进行另一个捆绑安装。在 gemfile 中,它看起来像这样:
干杯
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:
Cheers
我只在两次标题测试中看到这个问题。
我的 gemfile 如下...
我也尝试过 rspec-rails 的测试版,但无济于事。
仍然给我错误的两个标题如下:
来自 users_controller_spec.rc
错误片段分别为:
和
。
从输出中可以看出,“Sign Up”和“Index”清楚地显示在标题右侧。这是特别令人困惑的,因为以下测试确实有效:
它适用于同一页面,并且包含与其他“注册”测试相同的标题。 get 方法在此测试中有效,但在“Index”测试中无效。
帮助?
I am only seeing this issue for two of my title tests.
My gemfile is as follows...
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
The snippet from the errors reads:
and
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:
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?
从 rspec 2.2.0 开始,这似乎不是问题
This doesn't seem to be an issue as of rspec 2.2.0
我可以确认以下 Gemfile 工作正常......
I can confirm that the following Gemfile works correctly...
我成功了
!__A__Y__!比您需要的信息更多,但就其价值而言,这个 Gemfile ...
... 在我运行 ... ... 后
...
... 产生了这个 ... 捆绑包 ...
...这使得所有示例应用程序测试(直到第 5 章结束)再次运行。
I GOT IT WORKING
W__A__Y__! more information than what you need, but for what it's worth, this Gemfile ...
... after I run ...
... and ...
... results in this ... bundle ...
... which got all of the sample application tests (through the end of Chapter 5) to run again.
在我指定 webrat 0.7.1 之前,我仍然遇到这个问题。
I was still seeing this issue until I specified webrat 0.7.1.
以下内容为我解决了问题。
The following fixed the problem for me.
哈哈,重新启动 spork 和自动测试就可以了。它确实需要时不时地踢一下。顺便说一句,我正在运行 rspec-rails 2.6.1...
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...
“踢”Spork 并为我解决了问题。
"Kicked" Spork and fixed the problem for me.