5

我正在尝试测试未登录用户在尝试访问安全内容时是否被定向到设计注册页面。我正在使用 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
4

1 回答 1

8

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

page.should have_content I18n.t("devise.failure.unauthenticated")
于 2012-12-09T06:50:55.500 回答