【问题标题】:Cucumber with Capybara/Rack-Test not working with DELETE route带有 Capybara/Rack-Test 的黄瓜不适用于 DELETE 路线
【发布时间】:2023-03-14 13:50:01
【问题描述】:

我正在尝试运行涉及 Devise 的黄瓜测试,但以下代码失败:

When /^I logout$/ do
   page.driver.submit :delete, destroy_user_session_path, {}
end

我收到的错误信息是:

No route matches [GET] "/" (ActionController::RoutingError)
./features/steps/authentication_steps.rb:16:in `/^I logout$/'
./features/steps/authentication_steps.rb:11:in `/^I am not logged in$/
features/authentication_admin.feature:8:in `And I am not logged in'

但是,当我执行 rake routes RAILS_ENV=test 时,该路线确实出现在我的路线中

destroy_user_session DELETE /users/sign_out(.:format)    devise/sessions#destroy

有什么想法可以帮助我调试吗?谢谢!

【问题讨论】:

    标签: ruby-on-rails cucumber capybara rack-test


    【解决方案1】:

    国际海事组织 - 设计是一个经过充分测试的宝石。 可能没有必要测试注销方法。

    我宁愿使用 RSpec 测试是否存在具有正确 href 的注销按钮。

    或者在控制器规范中使用 Warden 测试模式 - 如果你想测试一些特定的行为。

    【讨论】:

    • 我不是在测试设计。这是我需要将场景设置为注销状态的一个黄瓜步骤。然后我将有后续步骤来测试其他自定义构建的功能。
    • 天哪,就是这样!我没有指向任何东西的根,因为这只是另一个应用程序的管理面板,因此没有主页。我通过设置一个控制器来修复它,该控制器为任何根请求呈现 HTTP 200。感谢您帮助我看到这一点!
    猜你喜欢
    • 2017-09-02
    • 1970-01-01
    • 2019-09-11
    • 1970-01-01
    • 2016-08-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多