如何跟踪 RSpec 正在加载哪个文件?
我正在使用 Rails 3.0.1、RSpec-Rails 2.0.1 和 Webrat 0.7.1。我有以下测试:
describe PagesController do
describe "GET 'main'" do
it "should have the right title" do
get 'main'
response.should have_selector("title", :content => "My title")
end
end
end
pages#main 的 HTML 检查出来:它包含我的标题。当我运行 rspec 时,它在这个测试中失败,并表示它希望在以下行中找到标记:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
由于这不是存储在pages#main 的文件,我认为 rspec 出于某种原因,加载错误的页面。我该如何解决这个问题?或者,如果通用解决方案失败,我怎样才能让 rspec 告诉我它正在尝试加载哪个页面,以便我可以尝试找出为什么它会转到另一个页面?谢谢。
I'm using Rails 3.0.1, RSpec-Rails 2.0.1 and Webrat 0.7.1. I have the following test:
describe PagesController do
describe "GET 'main'" do
it "should have the right title" do
get 'main'
response.should have_selector("title", :content => "My title")
end
end
end
The HTML of pages#main checks out: it contains My Title. When I run rspec, it gives me a failure on this test, and says it expects to find the tag in the following line:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
Since this is not the file stored at pages#main, I take it that rspec is, for some reason, loading the wrong page. How do I solve this? Or, failing a general solution, how can I get rspec to tell me which page it is trying to load, so that I can try to figure out why it is going to this other page? Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要告诉 RSpec 渲染视图:
You need to tell RSpec to render the views:
这是发布 log/test.log 的更好方法:
在我看来,第一个结果导致页面被渲染 - 第二个调用的目的是什么?
Here is a better way to post log/test.log:
It looks to me like the first one results in a page being rendered - what is the second call for?