如何跟踪 RSpec 正在加载哪个文件?

发布于 2024-09-29 15:34:27 字数 647 浏览 0 评论 0原文

我正在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

浮世清欢 2024-10-06 15:34:27

您需要告诉 RSpec 渲染视图:

describe PagesController do
  render_views # Add this line to tell RSpec to render the views
  describe "GET 'main'" do
  .
  .
end

You need to tell RSpec to render the views:

describe PagesController do
  render_views # Add this line to tell RSpec to render the views
  describe "GET 'main'" do
  .
  .
end
再浓的妆也掩不了殇 2024-10-06 15:34:27

这是发布 log/test.log 的更好方法:

  Processing by PagesController#main as HTML
Rendered pages/main.html.erb within layouts/application (0.4ms)
Completed 200 OK in 5ms (Views: 5.1ms | ActiveRecord: 0.0ms)
  Processing by PagesController#main as HTML
Completed 200 OK in 1ms (Views: 0.9ms | ActiveRecord: 0.0ms)

在我看来,第一个结果导致页面被渲染 - 第二个调用的目的是什么?

Here is a better way to post log/test.log:

  Processing by PagesController#main as HTML
Rendered pages/main.html.erb within layouts/application (0.4ms)
Completed 200 OK in 5ms (Views: 5.1ms | ActiveRecord: 0.0ms)
  Processing by PagesController#main as HTML
Completed 200 OK in 1ms (Views: 0.9ms | ActiveRecord: 0.0ms)

It looks to me like the first one results in a page being rendered - what is the second call for?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文