So I'm writing some boilerplate rails 4 code to use for future projects. I hate devise, so I'm building some of its functionality on my own.
This test took me about 2 minutes to write, and is literally walking me through everything I need to do like a small child. I consider myself a reasonably together guy, and this is easy boilerplate... but all the stuff I'm missing, or forgetting because it's slightly different in rails 4 than 3 is kind of crazy.
This test isn't perfect, and we could argue that it's testing too much, or whatever... but I'm convinced that this code will be working as intended once it passes.
I do think that maybe I could scrap it once it's done. Test drive a feature, then scrap the spec, just keeping some tests to walk through the critical paths of the application?
Then again, I did have to refactor an app at my last job where we split some views up into two namespaces. This broke pretty much every link in the app. Having tests there to make sure that every page was working was soooo nice in figuring out if we had missed anything, saved us a ton of time.
I think as long as we're testing we're doing better than most people.
Code:
require "spec_helper"
feature "Guest creates an account", js: true do
scenario "and verifies their email" do
visit root_path
find('a[data-role="signup"]').click
fill_in "user_email", with: "charlie@gmail.com"
fill_in "user_password", with: "P4ssw0rd"
fill_in "user_password_confirmation", with: "P4ssw0rd"
check "user_remember_password"
click_on "Register!"
expect(page).to have_css('.success', text: "Check your email to finish sign up")
expect(page).not_to have_content "Sign Out"
expect(last_email.to).to eq ["charlie@gmail.com"]
visit account_confirmations_path
expect(page).to have_css('.error', text: "Invalid confirmation token")
user = User.find_by_email("charlie@gmail.com")
visit account_confirmations_path(confirmation_token: user.confirmation_token)
expect(current_path).to eq(root_path)
expect(page).to have_css('.success', text: "Account confirmed")
expect(page).to have_content "Sign Out"
end
end