Reputation: 2211
I've been trying to simulate devise's confirmation through integration tests, but whenever I try to simulate clicking the confirmation link(i.e., from an email message), no confirmation was done, even though the email was successfully sent.
tests:(registration done earlier, and is successful)
open_email user[:email]
#Simulate confirmation
click_first_link_in_email#Only one link in the email message i.e. confirmation link
sleep 0.2
expect(new_user.confirmed?).to eq true# FAILS
..Results in:
Failure/Error: expect(new_user.confirmed?).to eq true
expected: true
got: false
(compared using ==)
Even though the email was sent and the confirmation process is actually working outside the tests, why's the confirmation process not being performed in that snippet?
Upvotes: 1
Views: 842
Reputation: 24815
I think the reason is the time delay at click taking effect.
To fix, do not use sleep
at first.
Then, test it in UI way, aka, do not expect user to have something. Instead, expect UI to have something.
click_first_link_in_email
expect(page).to have_content(/confirmed/)
If you really need to test user
, try reload
, but still should after UI thing - to have the wait effect.
click_first_link_in_email
expect(page).to have_content(/confirmed/)
user.reload
expect(user).to be_confirmed
Upvotes: 2