如何在 Cucumber 步骤中获取从 Rack 返回的响应?
我的 Rails 应用程序有一个 Cucumber 步骤:
Then /^I should be redirected to the sign in page$/ do
assert_equal 302, @response.status
end
但是 @response
对象是我的 Controller
返回的对象,并且是 Rack 中间件将状态设置为我期望的状态就这样吧。 如何获取从最外层中间件返回的响应而不是从控制器返回的响应?
I have a Cucumber step for my Rails application:
Then /^I should be redirected to the sign in page$/ do
assert_equal 302, @response.status
end
But that @response
object is the one returned by my Controller
, and it's the Rack middleware that sets the status to what I expect it to be. How can I get at the response as returned from the outer-most middleware instead of the one returned from the controller?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
从您的步骤定义来看,您似乎应该测试您是否在登录页面上,而不是是否收到 302。但要按照您的方式进行,请执行以下步骤:
From your step definition it sounds like you should be testing whether you're on the sign in page, not whether you got a 302. But to go your way, here's the step:
尝试仅使用不带“@”的
响应
。 它会给你 WebRat 看到的响应对象。Try using just
response
without the '@'. It will give you the response object WebRat sees.