简体   繁体   中英

Access Devise Configured Messages for Rspec and Capybara Tests

I'm trying to test that a non-logged in user is directed to the devise sign up page when they attempt to access secured content. I'm using RSpec with Capybara for the tests.

To make sure they reach the login page, I'm making sure the page that they end up on has the content of the devise login page notify hash. (By default, this is: You need to sign in or sign up before continuing. )

Rather than write the test like:

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

Is there a way to access the configured message (in case I change it later)? Something like:

page.should have_content Devise::Messages.Login_required

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM