Skip to content

Instantly share code, notes, and snippets.

@tuomasj
Created November 21, 2013 15:49
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save tuomasj/7584071 to your computer and use it in GitHub Desktop.
Save tuomasj/7584071 to your computer and use it in GitHub Desktop.
Testing Activation Emails with Capybara, RSpec and Custom Matcher. I wrote blog post which is here: http://tuom.as/2013/11/20/testing-activation-emails-with-capybara-rspec-and-custom-matcher.html
require 'spec_helper'
describe "Activation Email" do
it "confirms the email when user clicks the confirmation link on activation email" do
register_new_user("john.smith@example.com", "adobe password", "adobe password")
activation_token = User.last.activation_code
expect( open_last_email.body).to have_link_with_endswith(activation_token)
visit activation_path(activation_token)
expect(page).to have_content( "Your email has been confirmed.")
end
end
@LimeBlast
Copy link

Hi, thank you very much for this, it has helped me solve a problem.

I have had to make some minor changes to your code to make it work with the latest versions of the gems used. - specifically:

  • failure_message_for_should is now failure_message
  • failure_message_for_should_not is now failure_message_when_negated
  • open_last_email.body is now open_last_email.default_part_body

And I've also changed the method and class names of the matcher to have_link_that_ends_with and HaveLinkEndsWith - but that's a personal preference thing.

You can see all the changes I've made here: https://gist.github.com/LimeBlast/edcfe156c5d719eaea1e

Again, thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment