Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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
like image 905
Tyler DeWitt Avatar asked Dec 09 '12 06:12

Tyler DeWitt


1 Answers

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")
like image 85
dimuch Avatar answered Sep 25 '22 00:09

dimuch