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
Devise messages are stored in config/locales/devise.*.yml
, so you can access them like any other translations:
page.should have_content I18n.t("devise.failure.unauthenticated")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With