gpt4 book ai didi

ruby-on-rails - 访问设计用于 Rspec 和 Capybara 测试的配置消息

转载 作者:行者123 更新时间:2023-12-04 05:43:25 24 4
gpt4 key购买 nike

我正在尝试测试未登录的用户在尝试访问 protected 内容时是否被定向到设计注册页面。我正在使用 RSpec 和 Capybara 进行测试。

为了确保他们到达登录页面,我确保他们最终进入的页面具有设计登录页面通知哈希的内容。 (默认情况下,这是: You need to sign in or sign up before continuing. )

而不是像这样编写测试:

page.should have_content "You need to sign in or sign up before continuing."

有没有办法访问配置的消息(以防我以后更改它)?就像是:
page.should have_content Devise::Messages.Login_required

最佳答案

设计消息存储在 config/locales/devise.*.yml ,因此您可以像访问任何其他翻译一样访问它们:

page.should have_content I18n.t("devise.failure.unauthenticated")

关于ruby-on-rails - 访问设计用于 Rspec 和 Capybara 测试的配置消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13785261/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com