[LRUG] Testing email invitations with Cucumber

Ian Kynnersley iankynnersley at gmail.com
Tue Jan 29 10:35:37 PST 2013


Hi,

We have a Rails app which has the concept of invitations. I.e. I can invite
you to join me in using this app.

We have ended up with some pretty ugly cucumber scenarios that I am trying
(and failing) to refactor.

We are using email_spec (https://github.com/bmabey/email-spec) to do the
email interaction stuff and it seems to work well but the scenarios end up
pretty tortuous.

Things like:

Given I am logged in as a user
When I invite someone else
Then they should receive an email
When they open the email
Then they should see the subject "Invitation"
And the contents "You have been invited"
When I sign out
And the user clicks the first link in the email
Then they should be on the "accept invitation" page


I'm paraphrasing but this is the sort of thing I'm talking about. The step
"When I sign out" feels totally wrong here but is required otherwise
clicking the email link will react as me, not the recipient. I'm trying to
break the test down into discrete units but I'm struggling.

My thought was to finish the first test at "Then they should receive an
email" and started a new one that started:

Given I have been invited
Then I should have an email
...

However, the emails are sent in the controller so there is no email.

Does this indicate the email should be sent from somewhere else (in the
model or maybe a creator class) so that my "Given I have been invited" step
will automatically generate the email.

Or should I explicitly send an email in the "Given I have been invited"
step. This doesn't test that I am actually sending the right email in the
controller but that could be dealt with elsewhere.

Has anyone done this? It is pretty standard behaviour. Does anyone have any
recommendations?

Thanks
Ian


-- 

Ian Kynnersley
http://iankynnersley.co.uk | +44 (0) 7973 420 829 |
http://twitter.com/kpopper
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lrug.org/pipermail/chat-lrug.org/attachments/20130129/db94d431/attachment-0003.html>


More information about the Chat mailing list