Search code examples
ruby-on-railscucumberemail-spec

What's wrong with email spec?


When I write:

When I fill in "To" with "[email protected], [email protected]"
And I press "Send testimonials request"
Then I should see "Testimonial requests have been successfully sent"
And "[email protected]" should receive an email with subject "Add a testimonial..."
And "[email protected]" should receive an email with subject "Add a testimonial..."

everything works fine.

But if I write:

When I fill in "To" with "[email protected], [email protected]"
And I press "Send testimonials request"
Then "[email protected]" should receive an email with subject "Add a testimonial..."
And "[email protected]" should receive an email with subject "Add a testimonial..."
And I should see "Testimonial requests have been successfully sent"

Nothing works... Just one line was moved to the end and... boom..

May the reason be in some delay before checking email? or something like that.


Solution

  • This is asynchronous behavior of cucumber. In the first case you're waiting until action completed by waiting for a flash message. Internally cucumber driver "waits" until element would become visible by polling this element with interval and guard delay (capybara wait time).

    And in second case you're immediately checking for an email. Cucumber knows nothing about your controllers/actions and isn't synchronized with them.

    You can either left the first case or introduce some kind of polling in email checking step.