Search code examples
rspecemail-spec

Is there a way to follow a link based in its text in email_spec?


In RSpec I can easily follow the link corresponding to certain text using

click_link "change your password"

RSpec will then find the appropriate link and follow the associated HREF.

How do you do this in an email?

I'm trying to execute the same behaviour in an email using email_spec. However I can't seem to find an equivalent helper that will click a link corresponding to particular link text in the email_spec helpers.

This seems like a pretty obvious use-case so before I write something to do it for me I wanted to check whether one already exists.

The scenario is that I want to follow whatever link in the email corresponds to "Change my password".


Solution

  • I expect you have the email_spec properly installed and the helper modules included in your spec or your spec_helper.rb file. If you did this, the proper methods would be available in your test. You then need to open_email and then call visit_in_email. Example:

    open_email('[email protected]')
    visit_in_email('Confirm my account')
    expect(page).to have_content('Your email address has been successfully confirmed.')
    

    The address used in the open_email call is the "to" field.

    Hope this helps.