【发布时间】:2011-02-03 14:56:47
【问题描述】:
找到了一些建议:http://openmonkey.com/articles/2009/03/cucumber-steps-for-testing-page-urls-and-redirects
我已将上述方法添加到我的 web 步骤定义中,编写了我的功能,运行它并收到关于 nil 对象的错误。经过一番调查,我注意到,我没有响应和请求对象,它们是 nil
来自 web_steps.rb:
Then /^I should be on the (.+?) page$/ do |page_name|
request.request_uri.should == send("#{page_name.downcase.gsub(' ','_')}_path")
response.should be_success
end
Then /^I should be redirected to the (.+?) page$/ do |page_name|
request.headers['HTTP_REFERER'].should_not be_nil
request.headers['HTTP_REFERER'].should_not == request.request_uri
Then "I should be on the #{page_name} page"
end
请求和响应对象都是nil,为什么?
【问题讨论】:
-
看看调用这些的功能会有很大帮助。那时你通常会有一个
request对象,但前提是你确实提出了请求。 -
仅供参考 - 在 Capybara 1.1.2 上我必须使用
page.driver.request.env["HTTP_REFERER"]
标签: ruby-on-rails testing cucumber