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 告诉我它正在尝试加载哪个页面,以便我可以尝试找出它为什么会转到另一个页面?谢谢。

4

2 回答 2

1

你需要告诉 RSpec 渲染视图:

describe PagesController do
  render_views # Add this line to tell RSpec to render the views
  describe "GET 'main'" do
  .
  .
end
于 2010-11-08T18:57:33.437 回答
0

这是发布 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)

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

于 2010-11-01T03:43:05.240 回答