<div dir="ltr">Hi,<div><br></div><div>We have a Rails app which has the concept of invitations. I.e. I can invite you to join me in using this app.</div><div><br></div><div>We have ended up with some pretty ugly cucumber scenarios that I am trying (and failing) to refactor.</div>
<div><br></div><div>We are using email_spec (<a href="https://github.com/bmabey/email-spec">https://github.com/bmabey/email-spec</a>) to do the email interaction stuff and it seems to work well but the scenarios end up pretty tortuous.</div>
<div><br></div><div style>Things like:</div><div style><br></div><div style>Given I am logged in as a user</div><div style>When I invite someone else</div><div style>Then they should receive an email</div><div style>When they open the email</div>
<div style>Then they should see the subject "Invitation"</div><div style>And the contents "You have been invited"</div><div style>When I sign out</div><div style>And the user clicks the first link in the email</div>
<div style>Then they should be on the "accept invitation" page</div><div style><br></div><div style><br></div><div style>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.</div>
<div style><br></div><div style>My thought was to finish the first test at "Then they should receive an email" and started a new one that started:</div><div style><br></div><div style>Given I have been invited</div>
<div style>Then I should have an email</div><div style>...</div><div style><br></div><div style>However, the emails are sent in the controller so there is no email. </div><div style><br></div><div style>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.</div>
<div style><br></div><div style>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.</div>
<div style><br></div><div style>Has anyone done this? It is pretty standard behaviour. Does anyone have any recommendations?</div><div style><br></div><div style>Thanks</div><div style>Ian</div><div style><br></div><div><div>
<br></div>-- <br>







<br>Ian Kynnersley<br><a href="http://iankynnersley.co.uk" target="_blank">http://iankynnersley.co.uk</a> | +44 (0) 7973 420 829 | <a href="http://twitter.com/kpopper" target="_blank">http://twitter.com/kpopper</a>
</div></div>