README.md in email_spec-1.6.0 vs README.md in email_spec-2.0.0

- old
+ new

@@ -1,32 +1,24 @@ -[![Build Status](https://secure.travis-ci.org/bmabey/email-spec.png)](http://travis-ci.org/bmabey/email-spec) +[![Build Status](https://secure.travis-ci.org/email-spec/email-spec.png)](http://travis-ci.org/email-spec/email-spec) ## Email Spec -A collection of matchers for RSpec/MiniTest and Cucumber steps to make testing emails go smoothly. +A collection of matchers for RSpec, MiniTest and Cucumber steps to make testing emails go smoothly. This library works with ActionMailer and Pony. When using it with ActionMailer it works with -DelayedJob, ActiveRecord Mailer, and action_mailer_cache_delivery. +ActiveRecord Mailer, and action_mailer_cache_delivery. If you are testing emails in conjunction with an automated browser solution, like Selenium, you will want to use [action_mailer_cache_delivery](http://rubygems.org/gems/action_mailer_cache_delivery) in your test environment. (This is because your test process and server processes are distinct and therefore need an -intermediate store for the emails.) DelayedJob and ActiveRecord Mailer will also work but +intermediate store for the emails.) ActiveRecord Mailer will also work but you generally don't want to include those projects unless you need them in production. -## Setup - -```bash -script/plugin install git://github.com/bmabey/email-spec.git -``` - ### Gem Setup ```ruby -gem install email_spec - # Gemfile group :test do gem 'email_spec' end ``` @@ -62,11 +54,11 @@ When I fill in "Email" with "quentin@example.com" And I press "Sign up" And "quentin@example.com" should receive an email # Specify who should receive the email ``` -### RSpec +### RSpec (3.1+) First you need to require email_spec in your spec_helper.rb: ```ruby require "email_spec" @@ -133,10 +125,20 @@ ### Turnip If you're using [Turnip](https://github.com/jnicklas/turnip), you might be interested in this [conversion of the Cucumber steps into Turnip steps](https://github.com/jmuheim/transition/blob/master/spec/support/steps/email_steps.rb). +## Background Jobs + +If you are using a background job, you might need to use a step to process the jobs. Another alternative is to use an inline statement for your scenario. + +For example, for DelayedJob: + +```ruby +Delayed::Worker.delay_jobs = false +``` + ## Usage ### Cucumber ```gherkin @@ -166,11 +168,11 @@ ```ruby describe "POST /signup (#signup)" do it "should deliver the signup email" do # expect - UserMailer.should_receive(:deliver_signup).with("email@example.com", "Jimmy Bean") + expect(UserMailer).to(receive(:deliver_signup).with("email@example.com", "Jimmy Bean")) # when post :signup, "Email" => "email@example.com", "Name" => "Jimmy Bean" end end ``` @@ -187,23 +189,23 @@ before(:all) do @email = UserMailer.create_signup("jojo@yahoo.com", "Jojo Binks") end it "should be set to be delivered to the email passed in" do - @email.should deliver_to("jojo@yahoo.com") + expect(@email).to deliver_to("jojo@yahoo.com") end it "should contain the user's message in the mail body" do - @email.should have_body_text(/Jojo Binks/) + expect(@email).to have_body_text(/Jojo Binks/) end it "should contain a link to the confirmation link" do - @email.should have_body_text(/#{confirm_account_url}/) + expect(@email).to have_body_text(/#{confirm_account_url}/) end it "should have the correct subject" do - @email.should have_subject(/Account confirmation/) + expect(@email).to have_subject(/Account confirmation/) end end ``` @@ -215,11 +217,11 @@ This checks that the Reply-To header's email address (the bob@example.com of "Bob Saget <bob@example.com>") is set to the given string. ```ruby email = UserMailer.create_signup("jojo@yahoo.com", "Jojo Binks") -email.should reply_to("support@myapp.com") +expect(email).to reply_to("support@myapp.com") ``` ##### deliver_to(*email_addresses) alias: `be_delivered_to` @@ -227,11 +229,11 @@ This checks that the To header's email addresses (the bob@example.com of "Bob Saget <bob@example.com>") are set to the addresses. ```ruby email = UserMailer.create_signup("jojo@yahoo.com", "Jojo Binks") -email.should deliver_to("jojo@yahoo.com") +expect(email).to deliver_to("jojo@yahoo.com") ``` ##### deliver_from(email) alias: `be_delivered_from` @@ -239,43 +241,43 @@ This checks that the From header's email address (the bob@example.com of "Bob Saget <bob@example.com>") is set to the given string. ```ruby email = UserMailer.create_signup("jojo@yahoo.com", "Jojo Binks") -email.should deliver_from("sally@yahoo.com") +expect(email).to deliver_from("sally@yahoo.com") ``` ##### bcc_to(*email_addresses) This checks that the BCC header's email addresses (the bob@example.com of "Bob Saget <bob@example.com>") are set to the addresses. ```ruby email = UserMailer.create_signup("jojo@yahoo.com", "Jojo Binks") -email.should bcc_to("sue@yahoo.com", "bill@yahoo.com") +expect(email).to bcc_to("sue@yahoo.com", "bill@yahoo.com") ``` ##### cc_to(*email_addresses) This checks that the CC header's email addresses (the bob@example.com of "Bob Saget <bob@example.com>") are set to the addresses. ```ruby email = UserMailer.create_signup("jojo@yahoo.com", "Jojo Binks") -email.should cc_to("sue@yahoo.com", "bill@yahoo.com") +expect(email).to cc_to("sue@yahoo.com", "bill@yahoo.com") ``` ##### have_subject(subject) This checks that the Subject header's value is set to the given subject. ```ruby email = UserMailer.create_signup("jojo@yahoo.com", "Jojo Binks") -email.should have_subject("Welcome!") +expect(email).to have_subject("Welcome!") ``` ##### include_email_with_subject(subject) Note: subject can be either a String or a Regexp @@ -283,32 +285,32 @@ This checks that one of the given emails' subjects includes the subject. ```ruby email = UserMailer.create_signup("jojo@yahoo.com", "Jojo Binks") email2 = UserMailer.forgot_password("jojo@yahoo.com", "Jojo Binks") -[email, email2].should include_email_with_subject("Welcome!") +expect([email, email2]).to include_email_with_subject("Welcome!") ``` ##### have_body_text(text) Note: text can be either a String or a Regexp This checks that the text of the body has the given body. ```ruby email = UserMailer.create_signup("jojo@yahoo.com", "Jojo Binks") -email.should have_body_text(/Hi Jojo Binks,/) +expect(email).to have_body_text(/Hi Jojo Binks,/) ``` ##### have_header(key, value) This checks that the expected key/value pair is in the headers of the email. ```ruby email = UserMailer.create_signup("jojo@yahoo.com", "Jojo Binks") -email.should have_header("X-Campaign", "1234abc") +expect(email).to have_header("X-Campaign", "1234abc") ``` #### Using the helpers when not testing in isolation Don't. :) Seriously, if you do just take a look at the helpers and use them as you wish. @@ -339,6 +341,6 @@ ## Original Authors Ben Mabey, Aaron Gibralter, Mischa Fierer -Please see History.txt for upcoming changsets and other contributors. +Please see History.txt for upcoming changesets and other contributors.