如何在 Cucumber 步骤中获取从 Rack 返回的响应?

发布于 2024-07-27 00:59:49 字数 290 浏览 2 评论 0原文

我的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

冰之心 2024-08-03 00:59:49

从您的步骤定义来看,您似乎应该测试您是否在登录页面上,而不是是否收到 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

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:

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
戒ㄋ 2024-08-03 00:59:49

尝试仅使用不带“@”的响应。 它会给你 WebRat 看到的响应对象。

Try using just response without the '@'. It will give you the response object WebRat sees.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文