【问题标题】:How do I get the response returned from Rack in a Cucumber step?如何在 Cucumber 步骤中获取从 Rack 返回的响应?
【发布时间】:2009-07-08 17:27:17
【问题描述】:
我的 Rails 应用程序有一个 Cucumber 步骤:
Then /^I should be redirected to the sign in page$/ do
assert_equal 302, @response.status
end
但是@response 对象是我的Controller 返回的对象,它是Rack 中间件将状态设置为我期望的状态。如何获得从最外层中间件返回的响应,而不是从控制器返回的响应?
【问题讨论】:
标签:
ruby-on-rails
ruby
testing
cucumber
rack
【解决方案1】:
从您的步骤定义看来,您应该测试您是否在登录页面上,而不是您是否收到 302。但是要按照您的方式进行,请执行以下步骤:
Then /^I should be redirected to the sign in page$/ do |url|
assert @integration_session.status == 302, "Expected status to be 302, got #{@integration_session.status}"
end
【解决方案2】:
尝试只使用response 而不使用“@”。它会给你 WebRat 看到的响应对象。