I have a list of stories assigned to me in Cucumber, one of them being "Then the user should receive a confirmation email". I think testing that the user receives it is beyond the power of the application, but how can I test that an email had just been sent?
Cucumber is an open-source software testing tool written in Ruby. Cucumber enables you to write test cases that anyone can easily understand regardless of their technical knowledge.
Cucumber is not designed for long, end-to-end scenarios. Cucumber is not an automation tool. Its sweet spot is for business rules and examples of business rules, and the majority of your executable specifications should be short, focused, and concise.
Cucumber is not an API automation tool, but it works well with other API automation tools. Using API's for your automation, can make your tests faster and less flaky than going through the UI.
You can use this step definition :
Then "the user should receive a confirmation email" do
# this will get the first email, so we can check the email headers and body.
email = ActionMailer::Base.deliveries.first
email.from.should == "[email protected]"
email.to.should == @user.email
email.body.should include("some key word or something....")
end
Tested with Rails 3.2
Source
email_spec + action_mailer_cache_delivery gems are your friends for doing this
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With