我用创建了一个测试
rails g integration_test index --webrat
这将创建文件:
require 'spec_helper'
describe "Indices" do
describe "GET /indices" do
it "works! (now write some real specs)" do
visit indices_path
response.status.should be(200)
end
end
end
这一切都很好,但唯一的问题是,即使indices_path
存在,这个测试也会失败:
Failure/Error: response.status.should be(200)
NoMethodError:
undefined method `status' for nil:NilClass
所以看起来response
就是nil
。
我仍然可以使用page
(例如page.should have_content
工作得很好),但不能使用response
。我真的很想知道响应状态是200。我可以用response
以外的东西吗?
如果page
可用,那么您可能会使用capybara
而不是webrat
。你可以试试这个:
page.status_code.should be 200