Tyler DeWitt
Tyler DeWitt

Reputation: 23576

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

Upvotes: 5

Views: 482

Answers (1)

dimuch
dimuch

Reputation: 12818

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")

Upvotes: 8

Related Questions