Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

testing email gets sent in cucumber

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?

like image 760
jdkealy Avatar asked Feb 06 '13 17:02

jdkealy


People also ask

What does Cucumber do in testing?

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.

Is Cucumber end to end testing?

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.

Can we do API testing using Cucumber?

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.


2 Answers

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

like image 67
ouranos Avatar answered Nov 15 '22 08:11

ouranos


email_spec + action_mailer_cache_delivery gems are your friends for doing this

like image 36
fakeleft Avatar answered Nov 15 '22 07:11

fakeleft