Git Product home page Git Product logo

email-spec's Introduction

Build Status

Email Spec

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 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 in your test environment. (This is because your test process and server processes are distinct and therefore need an 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.

Gem Setup

# Gemfile
group :test do
  gem 'email_spec'
end

Cucumber

To use the steps in features put the following in your env.rb:

# Make sure this require is after you require cucumber/rails/world.
require 'email_spec' # add this line if you use spork
require 'email_spec/cucumber'

This will load all the helpers that the steps rely on. It will also add a Before hook for Cucumber so that emails are cleared at the start of each scenario.

Then:

rails generate email_spec:steps

This will give you a bunch of steps to get started with in step_definitions/email_steps.rb

By default, the generated file will look for email to [email protected]. You can either change this by editing the current_email_address method in email_steps.rb, or by simply specifying the target email in your features:

Scenario: A new person signs up
    Given I am at "/"
    When I fill in "Email" with "[email protected]"
    And I press "Sign up"
    Then "[email protected]" should receive an email   # Specify who should receive the email

Spinach

To use the helpers and matchers in your Spinach steps, add this to your env.rb:

require 'email_spec/spinach'

Creating shared steps (as for Cucumber above) doesn't fit so well with the Spinach ethos of very compartmentalized steps, so there is no generator for Spinach. It's easy to use the helpers/matchers in your steps. For example:

step 'the last email sent should welcome the user' do
  expect(last_email_sent).to have_subject('Welcome')
end

RSpec (3.1+)

First you need to require email_spec in your spec_helper.rb:

require "email_spec"
require "email_spec/rspec"

This will load all the helpers that the scenarios can count on. It will also add a before(:each) hook so that emails are cleared at the start of each scenario.

If you are upgrading to Rails 5, make sure your rails_helper.rb requires spec_helper after loading the environment. For example:

require File.expand_path('../../config/environment', __FILE__)
require 'spec_helper'

MiniTest

First you need to require minitest-matchers and email_spec in your test_helper.rb:

require "minitest-matchers"
require "email_spec"

You will then need to include EmailSpec::Helpers and EmailSpec::Matchers in your test classes. If you want to have access to the helpers and matchers in all of your tests you can do the following in your test_helper.rb:

class MiniTest::Unit::TestCase
  include EmailSpec::Helpers
  include EmailSpec::Matchers
end

Otherwise, you will need to include them in the tests where you use them:

class SignupMailerTest < MiniTest::Unit::TestCase
  include EmailSpec::Helpers
  include EmailSpec::Matchers
  ...
end

Or, if you are using the MiniTest spec DSL, it would look like this:

describe SignupMailer do
  include EmailSpec::Helpers
  include EmailSpec::Matchers
  ...
end

Turnip

If you're using Turnip, you might be interested in this conversion of the Cucumber steps into Turnip steps.

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:

Delayed::Worker.delay_jobs = false

Usage

Cucumber

Scenario: A new person signs up
    Given I am at "/"
    When I fill in "Email" with "[email protected]"
    And I press "Sign up"
    And I should receive an email
    When I open the email
    Then I should see "confirm" in the email body
    When I follow "confirm" in the email
    Then I should see "Confirm your new account"

For more examples, check out examples/rails_root in the source for a small example app that implements these steps.

Cucumber Matchers (Ruby)

See RSpec Matchers (they are the same)

RSpec

Testing In Isolation

It is often useful to test your mailers in isolation. You can accomplish this by using mocks to verify that the mailer is being called in the correct place and then write focused examples for the actual mailer. This is a simple example from the sample app found in the gem:

Verify that the mailer is used correctly in the controller (this would apply to a model as well):

describe "POST /signup (#signup)" do
  it "should deliver the signup email" do
    # expect
    expect(UserMailer).to(receive(:deliver_signup).with("[email protected]", "Jimmy Bean"))
    # when
    post :signup, "Email" => "[email protected]", "Name" => "Jimmy Bean"
  end
end

Examples for the #signup method in UserMailer:

describe "Signup Email" do
  include EmailSpec::Helpers
  include EmailSpec::Matchers
  # include ActionController::UrlWriter - old rails
  include Rails.application.routes.url_helpers

  before(:all) do
    @email = UserMailer.create_signup("[email protected]", "Jojo Binks")
  end

  it "should be set to be delivered to the email passed in" do
    expect(@email).to deliver_to("[email protected]")
  end

  it "should contain the user's message in the mail body" do
    expect(@email).to have_body_text(/Jojo Binks/)
  end

  it "should contain a link to the confirmation link" do
    expect(@email).to have_body_text(/#{confirm_account_url}/)
  end

  it "should have the correct subject" do
    expect(@email).to have_subject(/Account confirmation/)
  end

end

RSpec Matchers

reply_to(email)

alias: have_reply_to

This checks that the Reply-To header's email address (the [email protected] of "Bob Saget [email protected]") is set to the given string.

email = UserMailer.create_signup("[email protected]", "Jojo Binks")
expect(email).to reply_to("[email protected]")
deliver_to(*email_addresses)

alias: be_delivered_to

This checks that the To header's email addresses (the [email protected] of "Bob Saget [email protected]") are set to the addresses.

email = UserMailer.create_signup("[email protected]", "Jojo Binks")
expect(email).to deliver_to("[email protected]")
deliver_from(email)

alias: be_delivered_from

This checks that the From header's email address (the [email protected] of "Bob Saget [email protected]") is set to the given string.

email = UserMailer.create_signup("[email protected]", "Jojo Binks")
expect(email).to deliver_from("[email protected]")
bcc_to(*email_addresses)

This checks that the BCC header's email addresses (the [email protected] of "Bob Saget [email protected]") are set to the addresses.

email = UserMailer.create_signup("[email protected]", "Jojo Binks")
expect(email).to bcc_to("[email protected]", "[email protected]")
cc_to(*email_addresses)

This checks that the CC header's email addresses (the [email protected] of "Bob Saget [email protected]") are set to the addresses.

email = UserMailer.create_signup("[email protected]", "Jojo Binks")
expect(email).to cc_to("[email protected]", "[email protected]")
have_subject(subject)

This checks that the Subject header's value is set to the given subject.

email = UserMailer.create_signup("[email protected]", "Jojo Binks")
expect(email).to have_subject("Welcome!")
include_email_with_subject(subject)

Note: subject can be either a String or a Regexp

This checks that one of the given emails' subjects includes the subject.

email = UserMailer.create_signup("[email protected]", "Jojo Binks")
email2 = UserMailer.forgot_password("[email protected]", "Jojo Binks")
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.

email = UserMailer.create_signup("[email protected]", "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.

email = UserMailer.create_signup("[email protected]", "Jojo Binks")
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.

MiniTest

You will use EmailSpec in your tests the same way you use it in your specs. The only difference is the use of MiniTest's must instead of Rspec's should:

email = UserMailer.create_signup("[email protected]", "Jojo Binks")
email.must deliver_to("[email protected]")

Or, you can use the matcher as an expectation:

email = UserMailer.create_signup "[email protected]", "Jojo Binks"
email.must_deliver_to "[email protected]"

And of course you can use the matcher as an assertion:

email = UserMailer.create_signup "[email protected]", "Jojo Binks"
assert_must deliver_to("[email protected]"), email

Issue triage Open Source Helpers

You can contribute by triaging issues which may include reproducing bug reports or asking for vital information, such as version numbers or reproduction instructions. If you would like to start triaging issues, one easy way to get started is to subscribe to email-spec on CodeTriage.

Original Authors

Ben Mabey, Aaron Gibralter, Mischa Fierer

Please see Changelog.md for upcoming changes and other contributors.

email-spec's People

Contributors

archfear avatar baumicon avatar bcardarella avatar blowmage avatar bmabey avatar cgunther avatar dbalatero avatar dcrec1 avatar donaldpiret avatar doon avatar drnic avatar eitoball avatar etagwerker avatar gardelea avatar hammerdr avatar hirurg103 avatar jakubkosinski avatar johncant avatar josephholsten avatar koic avatar lukaszx0 avatar lukemelia avatar mauro-oto avatar maxim avatar mischa avatar ronaldsalas avatar sirkosi avatar thomasfedb avatar timcharper avatar woahdae avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

email-spec's Issues

asynchronous email checking in cucumber+Selenium/Celerity features

Sorry to bombard you with issues! Just reworking my testing framework now and I've run into a few issues...

So... do you have any thoughts on making email-spec wait for requests to finish before checking for email? I'm trying to figure out the best way to have my Selenium features run without having to sleep 2 before checking for email in my Then steps.

email_spec 0.6.4 doesnt declare RSpec depedency in gemspec file

We are using email_spec 0.6.4 in a large commercial project because of a delay in Rails 3 upgrade due to unrelated issues. Today, we diagnosed an 'uninitialized constant EmailSpec::Matchers::Spec' problem with email_spec 0.6.4 that ultimately was traced to its gemspec: while it depends upon RSpec, it does not declare that dependency. Hence, Bundler can init Email_Spec ahead of RSpec.

We resolved it by doing both of:

  • reordering the Project Gemfile (which you should not need to do) to ensure email spec comes after RSpec
  • Appending ", :require => 'spec'" to the line "gem 'rspec', '1.3.1'"

[PATCH] Fix and expand email steps to correctly parse email subject Regexp and/or String

The implementation for the following step in email_steps.rb...

Then /^(?:I|they|"([^"]*?)") should receive (an|no|\d+) emails? with subject "([^"]*?)"$/

...fails to match a subject that contains any character that has a special meaning in a regular expression.

I've broken down the step into two steps, one for matching a regular expressions, and another one for matching strings.

Patch here:

http://gist.github.com/478371

Multipart Messages..

The majority of my messages are multi-part, containing both a plain-text and an html part. When you have a multi-part email current_email.body is "", so it will always fail. Also there really isn't any default steps for dealing with mutli-part email, so I've added a couple steps to deal with it.

Then I should see "confirm" in the email html part body
Then I should see "confirm" in the email text part body

So you can test against both parts.

and I modified

Then I should see "confirm" in the email body
To use default_part_body.to_s (since steps like When I click the first link in the email, use it figured it was best to be consistent? )

see: http://github.com/doon/email-spec/commit/9297abaf30fa55c3a2cc71e5384964966ed8f640

For the changes I made to the template.

Matching email subjects that contain regexp sensitive characters

The find_email helper function fails to match emails whose subjects contain characters that have special meaning inside a regular expression.

For example the following will never match:

find_email('[email protected]', :with_subject => '[app.com] please confirm your account')

I am guessing this is not the expected behaviour…?!

The way I have fixed the issue in my local branch is by removing the regexp conversion in find_email and then splitting the current 'should receive an email with subject' and 'open email with subject' steps in email_steps.rb to three distinct steps each:

  • should receive an/open email with subject String
  • should receive an/open email with subject RegExp
  • should receive an/open email with subject containing String

I would like to send a pull request but I am finding it tricky to test find_email in helper_specs.rb as there are no examples how to setup deliveries of fake messages.

Any pointers how to test?

Shall I just push my changes without the tests?

(BTW, using 0.6.* but is seems to be an issue in 1.0.0 as well)

How to write an RSpec for a Mail Interceptor?

How can you write a spec to test a Mail Interceptor as follows? The interceptor is not taking effect before calling:

... @email.should deliver_to

setup_mail.rb
Mail.register_interceptor(MailInterceptor) if Rails.env != "production"

class MailInterceptor
def self.delivering_email(message)
message.subject = "#{message.subject} [#{message.to}]"
message.to = "[email protected]"
end
end

current_email_address problem

Hi, can you refactor the code so that current_email_address is set in a email_steps, like the following:

Given my email address is "[email protected]"

Otherwise it is very problematic to deal with current_email_address

~> pessimistic version constraint doesn't work with rspec 2.3.x

I went to install email_spec on a recent Rails project but couldn't due to the pessimistic version constraint on RSpec (I'm currently using rspec 2.3.0) - was the last 0 in email_spec intentional?

By my reading if you drop the last 0 in it it should work. Happy to patch, but wasn't sure what the intention was here.

Thanks for this awesome lib!

undefined 'current_email_address', email-spec works only with cucumber (steps generator)

when trying to: visit_in_email 'Confirm registration' i get:
NameError: undefined local variable or method `current_email_address' for RSpec::Core::ExampleGroup::Nested_1:0x9f18570

i'm writing test in steak, and that current_email_address is declared only in cucumber steps generator.

To get working email_spec without cucumber, but with spec, we have to manually create for example email_helpers.rb file in spec/acceptance/support/ with:

module EmailHelpers
  def current_email_address
    last_email_address || '[email protected]'
  end
end
RSpec.configuration.include(EmailHelpers)

so to fix that in email_spec, we have to create separate generator for this helper? more convenient way i think is to define that method by default within email_spec code.

is anybody using that default email from current_email_address? if so, instead of creating external method, we could set it somewhat in configuration of email_spec, in spec_helper.

what do you think about it? for now, email_spec works ONLY with Cucumber, so why don't name it cucumber_email_spec? :) email_spec should just give methods to work with email and should work by default.

if you like cucumber, ok, make just generator for steps for it, but don't prevent people from using it without cucumber!

Exception in request_uri when parsing emails

Hi, I'm working on a Rails app with following setup:

  • Ruby 1.9.2-p0
  • rails (3.0.4)
  • cucumber (0.10.2)
  • cucumber-rails (0.3.2)
  • email_spec (0.6.2 e197a16) -> Rails 3 branch, HEAD from git repo on github

The emails that are send are in HTML format (haml views) and are encoded in UTF-8.

I can check for emails etc. but as soon as I try parsing the email e.g. to click on a link I get following error:

(::) failed steps (::)

You have a nil object when you didn't expect it!
You might have expected an instance of Array.
The error occurred while evaluating nil.
/Users/alberto/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/uri/http.rb:91:in request_uri' ./features/step_definitions/email_steps.rb:172:in/^(?:I|they) click the first link in the email$/'
features/public_users_activation.feature:15:in `When I click the first link in the email'

Is this a bug? Am I doing something wrong? Any kind of help appreciated.

release 1.0.0 requires 'rspec'

Apparently it requires 'rspec' somewhere, instead of 'spec'. My solution has been to specifically bundle 0.6.3. Is that what I should be doing or am I missing something?

"visit_in_email" and "click_first_link_in_email" throw ArgumentError

Using email_spec with cucumber like so:
[…]
Then I should see "Sign in"
And I should see "You will receive an email with instructions […]"
And I should receive an email

When I open the email
Then I should see "Change my password" in the email body

When I follow "Change my password" in the email

Then I should […]

will throw
wrong number of arguments (1 for 2) (ArgumentError)

Replacing
When I follow "Change my password" in the email
with
When I click the first link in the email

will throw
wrong number of arguments (0 for 1) (ArgumentError)

The corresponding steps come straight from the generator:
When(/^(?:I|they) follow "([^"]*?)" in the email$/) do |link|
visit_in_email(link)
end

When(/^(?:I|they) click the first link in the email$/) do
    click_first_link_in_email
end

As a work–around I've specified "current_email" explicitly and changed the steps like so:

When(/^(?:I|they) follow "([^"]*?)" in the email$/) do |link|
    visit(parse_email_for_link(current_email, link))
end

When(/^(?:I|they) click the first link in the email$/) do
    click_first_link_in_email(current_email)
end

— which seems to work so far. Any ideas?

Cheers.

When I follow -> No action responded to edit

Using rails (2.3.5), cucumber-rails (0.3.2),

Using the method
When I follow "[link]" in the email or I click the first link in the email

Getting an error:
No action responded to edit. Actions: accept, create, index, mailer_set_url_options, recapture, reject, reprocess, show, time_diff_in_minutes, title, and update (ActionController::UnknownAction)
/usr/lib/ruby/1.8/benchmark.rb:308:in realtime' ./features/step_definitions/email_steps.rb:155:in/^(?:I|they) follow "([^"]*?)" in the email$/'
features/device_send_and_accept_businesscard.feature:114:in `When I follow "http://assistant.example.com/profiles" in the email'

Googles it but no result

Open email not found

I have been unable to any use email_spec version since 0.3.0. Again today I decided to see if my problem had been resolved in the most recent (0.5.0) gem. As it turned out all but one of the difficulties have disappeared so I would like to resolve the remaining one.

In one feature only I get this error and I cannot see why:

When we run the forex retrieval script                                         # features/bin/forex/step_definitions/forex_ca_feed_script_steps.rb:87

And "[email protected]" should receive an email                         # features/step_definitions/email_steps.rb:51

And "[email protected]" opens the email                                 # features/step_definitions/email_steps.rb:82

Then they should see "Exchange Rates Central Bank Update" in the email subject # features/step_definitions/email_steps.rb:98
  Expected an open email but none was found. Did you forget to call open_email? (Spec::Expectations::ExpectationNotMetError)
  ./features/step_definitions/email_steps.rb:99:in `/^(?:I|they) should see "([^"]*?)" in the email subject$/'
  features/bin/forex/forex_ca_feed_script.feature:47:in `Then they should see "Exchange Rates Central Bank Update" in the email subject'

Typical test failing "Expected an open email but none was found" (rails 2.3.9, email_spec 0.6.5)

Hi guys,

I'm trying to start (al last!) a test suite using Cucumber, everything was almost fine until I added email_spec.
It should be simple but just doesn't work:
Then I should be on the thank-you page
And "[email protected]" should receive 1 email
When "[email protected]" opens the email
Then I should see "Please activate your new account" in the email subject
When I click the first link in the email

Fails being unable to open the email:

When "[email protected]" opens the email                                 # features/step_definitions/email_steps.rb:73
Then I should see "Please activate your new account" in the email subject      # features/step_definitions/email_steps.rb:89
  Expected an open email but none was found. Did you forget to call open_email? (Spec::Expectations::ExpectationNotMetError)
  ./features/step_definitions/email_steps.rb:90:in `/^(?:I|they) should see "([^"]*?)" in the email subject$/'
  features/accounts.feature:25:in `Then I should see "Please activate your new account" in the email subject'

I'm sending a multipart email to bob and a text email to admin (so it shouldn't be in this count). My cucumber.log looks perfectly okay.

Any idea would be super greatly appreciated!
Thanks :)

reset_mailer does not work with :cache delivery method

I'm using email-spec with Cucumber, using the :cache delivery method (specifically action_mailer_delivery_cache) and found that the 'reset_mailer' method didn't work as expected. This method only clears the 'deliveries' array, but doesn't clear the cache. Thus a step like "Given a clear email queue" doesn't actually clear the queue.

I've made a patch in my fork to fix this: wapcaplet@135c858

An easy workaround is to redefine "Given a clear email queue" to call ActionMailer::Base.clear_cache directly.

Using email-spec with Culerity?

Hello,

I am using Steak/rSpec+Capybara and Culerity for JS. When using Culerity, I am setting ActionMailer's delivery_method to :persistent (that's what comes by default on the culerity environment). However, I am not sure if this works with email-spec? This seems to be equivalent to the cache delivery method, but I'd rather not install anything else if Culerity already solves the issue for me.

Thanks!

Marcelo.

"I should be on page_name" should consider parameters!

Change this

Then /^(?:|I )should be on (.+)$/ do |page_name|
  current_path = URI.parse(current_url).path
  if current_path.respond_to? :should
    current_path.should == path_to(page_name)
  else
    assert_equal path_to(page_name), current_path
  end
end

to

Then /^(?:|I )should be on (.+)$/ do |page_name|
  current_path = URI.parse(current_url).path
  current_path += "?" + URI.parse(current_url).query.to_s if URI.parse(current_url).query
  if current_path.respond_to? :should
    current_path.should == path_to(page_name)
  else
    assert_equal path_to(page_name), current_path
  end
end

uninitialized constant EmailSpec::Matchers::Spec (rvm + bundler + spork + rspec)

I'm trying to setup email_spec to work with spork and rspec. I added require "email_spec" to spec_helper.rb and include helpers and matchers config.include(EmailSpec::Helpers) config.include(EmailSpec::Matchers). When I run specs with bundle exec spec spec/models everything works as expected. However when I run bundle exec spork it fails to start with uninitialized constant EmailSpec::Matchers::Spec.

jabuk:menstruacija lenart$ bundle exec spork
Using RSpec
Preloading Rails environment
Loading Spork.prefork block...
uninitialized constant EmailSpec::Matchers::Spec (NameError)
/Users/lenart/Sites/rails/menstruacija/.bundle/ruby/1.8/gems/activesupport-2.3.8/lib/active_support/dependencies.rb:440:in `load_missing_constant'
/Users/lenart/Sites/rails/menstruacija/.bundle/ruby/1.8/gems/activesupport-2.3.8/lib/active_support/dependencies.rb:80:in `const_missing'
/Users/lenart/Sites/rails/menstruacija/.bundle/ruby/1.8/gems/email_spec-0.6.4/lib/email_spec/matchers.rb:135
/Users/lenart/Sites/rails/menstruacija/.bundle/ruby/1.8/gems/activesupport-2.3.8/lib/active_support/dependencies.rb:158:in `require'
/Users/lenart/Sites/rails/menstruacija/.bundle/ruby/1.8/gems/activesupport-2.3.8/lib/active_support/dependencies.rb:158:in `require'
/Users/lenart/Sites/rails/menstruacija/.bundle/ruby/1.8/gems/email_spec-0.6.4/lib/email_spec.rb:13
/Users/lenart/.rvm/gems/ruby-1.8.7-p302@global/gems/bundler-1.0.0.rc.5/lib/bundler/runtime.rb:64:in `require'
/Users/lenart/.rvm/gems/ruby-1.8.7-p302@global/gems/bundler-1.0.0.rc.5/lib/bundler/runtime.rb:64:in `require'
/Users/lenart/.rvm/gems/ruby-1.8.7-p302@global/gems/bundler-1.0.0.rc.5/lib/bundler/runtime.rb:62:in `each'
/Users/lenart/.rvm/gems/ruby-1.8.7-p302@global/gems/bundler-1.0.0.rc.5/lib/bundler/runtime.rb:62:in `require'
/Users/lenart/.rvm/gems/ruby-1.8.7-p302@global/gems/bundler-1.0.0.rc.5/lib/bundler/runtime.rb:51:in `each'
/Users/lenart/.rvm/gems/ruby-1.8.7-p302@global/gems/bundler-1.0.0.rc.5/lib/bundler/runtime.rb:51:in `require'
/Users/lenart/.rvm/gems/ruby-1.8.7-p302@global/gems/bundler-1.0.0.rc.5/lib/bundler.rb:107:in `require'
/Users/lenart/Sites/rails/menstruacija/config/boot.rb:115:in `load_gems'
/Users/lenart/Sites/rails/menstruacija/.bundle/ruby/1.8/gems/rails-2.3.8/lib/initializer.rb:164:in `process'
/Users/lenart/Sites/rails/menstruacija/.bundle/ruby/1.8/gems/rails-2.3.8/lib/initializer.rb:113:in `send'
/Users/lenart/Sites/rails/menstruacija/.bundle/ruby/1.8/gems/rails-2.3.8/lib/initializer.rb:113:in `run_without_spork'
/Users/lenart/Sites/rails/menstruacija/.bundle/ruby/1.8/gems/spork-0.8.4/lib/spork/app_framework/rails.rb:18:in `run'
/Users/lenart/Sites/rails/menstruacija/config/environment.rb:12
/Users/lenart/Sites/rails/menstruacija/spec/spec_helper.rb:7:in `require'
/Users/lenart/Sites/rails/menstruacija/spec/spec_helper.rb:7
/Users/lenart/Sites/rails/menstruacija/.bundle/ruby/1.8/gems/spork-0.8.4/bin/../lib/spork.rb:23:in `prefork'
/Users/lenart/Sites/rails/menstruacija/spec/spec_helper.rb:6
/Users/lenart/Sites/rails/menstruacija/.bundle/ruby/1.8/gems/spork-0.8.4/lib/spork/test_framework.rb:138:in `load'
/Users/lenart/Sites/rails/menstruacija/.bundle/ruby/1.8/gems/spork-0.8.4/lib/spork/test_framework.rb:138:in `preload'
/Users/lenart/Sites/rails/menstruacija/.bundle/ruby/1.8/gems/spork-0.8.4/lib/spork/app_framework/rails.rb:121:in `preload'
/Users/lenart/Sites/rails/menstruacija/.bundle/ruby/1.8/gems/spork-0.8.4/lib/spork/test_framework.rb:134:in `preload'
/Users/lenart/Sites/rails/menstruacija/.bundle/ruby/1.8/gems/spork-0.8.4/bin/../lib/spork.rb:67:in `exec_prefork'
/Users/lenart/Sites/rails/menstruacija/.bundle/ruby/1.8/gems/spork-0.8.4/lib/spork/test_framework.rb:120:in `preload'
/Users/lenart/Sites/rails/menstruacija/.bundle/ruby/1.8/gems/spork-0.8.4/lib/spork/run_strategy/forking.rb:25:in `preload'
/Users/lenart/Sites/rails/menstruacija/.bundle/ruby/1.8/gems/spork-0.8.4/bin/../lib/spork/runner.rb:74:in `run'
/Users/lenart/Sites/rails/menstruacija/.bundle/ruby/1.8/gems/spork-0.8.4/bin/../lib/spork/runner.rb:9:in `run'
/Users/lenart/Sites/rails/menstruacija/.bundle/ruby/1.8/gems/spork-0.8.4/bin/spork:10
/Users/lenart/Sites/rails/menstruacija/.bundle/ruby/1.8/bin/spork:19:in `load'
/Users/lenart/Sites/rails/menstruacija/.bundle/ruby/1.8/bin/spork:19
jabuk:menstruacija lenart$ 

Any ideas?

My versions:

  • ruby 1.8.7
  • rails 2.3.8
  • rvm 1.0.21
  • bundler 1.0.0.rc.5
  • rspec (1.3.1)
  • rspec-rails (1.3.3)
  • email_spec (0.6.4)

Invalid gemspec in rails2 branch

I get this when checking out the latest from the 0.6-rails2-compat branch:

email_spec at ... did not have a valid gemspec.
This prevents bundler from installing bins or native extensions, but that may not affect its functionality.
The validation message from Rubygems was:
  ["lib/email_spec/#helpers.rb#", "examples/rails3_root", "examples/rails3_root/db", "examples/rails3_root/features",         "examples/rails3_root/features/step_definitions", "examples/rails3_root/features/step_definitions/email_steps.rb", "examples/rails3_root/log", "examples/sinatra/features/step_definitions/email_steps.rb", "examples/sinatra_root", "examples/sinatra_root/features", "examples/sinatra_root/features/step_definitions", "examples/sinatra_root/features/step_definitions/email_steps.rb"] are not file

Commit c692a82 seems to have added rails 3 files, and continued the "rsepc" typo

The 0.6.5 tag works, but not 0.6.6, which gives the error "Could not find gem 'rsepc', required by 'email_spec', in any of the sources." Commit 9c41890 has the original typo.

named_route not generated exactly the same in test and template.

Hi,

The named_route has a slightly different output when parsed in the mail template than expected from the RSpec point of view.
The diff is minimal, put there is a diff so the test fails.
Any idea why this happens or suggestions to what I´m doing wrong?

expected the body to match http://my_company.com/users/sign_up?confirmation_token=0001_secret_token&email=test-0001-email%40my_company.com/
Actual body was http://my_company.com/users/sign_up?confirmation_token=0001_secret_token&email=test-0001-email%40my_company.com

it "should contain a link to the signup through an invite page" do
  @email.should have_body_text(/#{new_user_registration_url(:email => @invitation.email, 
    :confirmation_token => @invitation.confirmation_token, :host => 'my_company.com')}/)
end

invite.html.slim:
= link_to t('.click_here_to_join_group'), new_user_registration_url(:email => @invitation.email,
:confirmation_token => @invitation.confirmation_token, :host => 'my_company.com')

$ rspec

Failures:

  1. Group invitations inviting users who does not have an account on My Company should contain a link to the signup through an invite page
    Failure/Error: @email.should have_body_text(/#{new_user_registration_url(:email => @invitation.email,
    expected the body to match /http://my_company.com/users/sign_up?confirmation_token=0001_secret_token&email=test-0001-email%40my_company.com/, but did not. Actual body was: "

    John Doe would like you to join the group Nihil delectus possimus et aut veritatis. at my_company.com
    <a href="http://my_company.com/users/sign_up?confirmation_token=0001_secret_token&email=test-0001-email%40my_company.com">Follow this link to join

    Best regards
    My Company

    "

    ./spec/mail/group_invite_spec.rb:25:in `block (3 levels) in <top (required)>'

*** LOCAL GEMS ***

email_spec (1.1.1)
rspec (2.5.0)
rspec-core (2.5.1)
rspec-expectations (2.5.0)
rspec-mocks (2.5.0)
rspec-rails (2.5.0)
rails (3.0.3)

Best,
Martin
[email protected]

Formatting off for README

The formatting of the READMe is a little off. It’s being processed as a rdoc, and had some markup that was a little bit off.

I’ve forked and added a fix at technicalpickles@3b1a96da1161ddd56979bfff13df98172295c9d5

Attempting to install and use on Rails 3 but can't get generate spec working

Hey there,

Prolly umping the gun a little but am trying to port an app over from 2 to 3 and wanted to do the testing part right as slightly rewriting everything so looking at email_spec

Tried installing email_spec along with cucumber-rails (capybara and rpsec) and got down to putting the require in the cucumber env.rb and then tried to generate the spec but can't seem to get it working with script/generate or script/rails generate email_spec

Can you give me an idea of what I need to do to get that to generate, or any hack around it while rails 3 support is being worked on (or should I try to install the rails3 branch?).

Dependent on RSpec2?

A recent commit calls:

require 'rspec'

Which seems to break when running RSpec 1.3.0

Running email-spec with spork

I've successfully setup email-spec to work with cucumber (i love the gem!). I have problems getting it to work with Spork DRb server. No matter where in support/env.rb I put the require I get the following error: uninitialized constant EmailSpec (NameError)

I've tried adding require 'email_spec/cucumber' to Spork.prefork, after cucumber/rails/world is loaded and get uninitialized constant EmailSpec (NameError). Same happens when I put it to Spork.each_run block.

Here's the full backtrace: http://pastie.org/862014

Any ideas and suggestions are welcome. I'm sure many people would love to see this in the wiki :P

"When I open the email" step does not give most recently received email

When I have multiple emails in the inbox, the open_email(address) method does not return the most recently received email (as is mentioned in the comment above the step definition that uses it), but the first received one.

This is demonstrated by this bit of Frankenstein code to debug the step:
# Opens the most recently received email
When /^(?:I|they|"([^\"]*?)") opens? the email$/ do |address|
address = convert_address(address)
mailbox = mailbox_for(address)
puts mailbox.map { |m| m.header["date"].to_s(:db) }.inspect

  open_email(address)
  puts email_spec_hash[:current_email].header["date"].to_s(:db)
end

Output:
["Tue, 10 Aug 2010 19:09:53 +0100", "Tue, 10 Aug 2010 19:09:54 +0100"]
Tue, 10 Aug 2010 19:09:53 +0100

The date of the returned email is furthest in the past, or first received. Not the "most recently received" one.

While this would be solved by modifying find_email to return mailbox_for(address).last instead of mailbox_for(address).first, this may break other people's code. In my case I did want the most recent email, in other cases people may want the first received one. Maybe a reasonable solution is to add an option to find_email that when passed returns the last one.

Improve cucumber README instructions

The README should explain that by default
Then I should receive an email
checks for emails sent to [email protected] and people should read email_steps.rb on how to customize this. I had a hard time figuring out why email_spec wasn't finding any emails.

Webrat rack branch error

When I deliver an email when using webrat's rack branch, I get the following error if I try to do anything afterwards:

No response yet. Request a page first. (Rack::Test::Error) /vendor/webrat/lib/webrat/rack.rb:22:in `response' /vendor/webrat/lib/webrat/core/session.rb:229:in`page_scope' /vendor/webrat/lib/webrat/core/session.rb:177:in `current_scope' (eval):2:in`select'

Problem by relative path access

I want you no access by relativity URL it, and to make it to the access with URL absolutely. Described in mails in my application following URL

http://username.example.com/

A necessary key(username) cannot be acquired in relativity URL though username is made a key and data is retrieved.

I've forked and added a fix at maedana@ac1ea0ecb80ca6604b3520fe7b695708adcf671a.

bcc matchers

I found myself needing to check an email is bcc'd to a particular email address. deliver_to only check's an email's to.

I wasn't sure if it should also check the bcc, so I made a new matcher, bcc_to, which behaves the same way as deliver_to, except it's only the bcc.

I made a branch for this, bcc. See technicalpickles/email-spec@65ac7c7

email_spec/cucumber.rb messes with capybara+culerity

Culerity introduces a new delivery method, :persistent... email_spec overrides config/environments/cucumber.rb config.action_mailer.delivery_method = :persistent. Also, the Before block assumes :test or :cache...

set_current_email doesn't work if the email has no to recipients

If we have an email that doesn't have a to address (maybe we are only using cc or bcc) then set_current_email will fail because it's trying to call .each on a nil.

It would also be nice if we could set the email as one of the read ones / the current one for all the recipients of the email, not just those in the to address.

Patch with tests available in h-lame@178e40c7b2932f858f4cd7a17c9d9c3d8c0dfbaa

links_in_email includes doctype uri and namespace

In HTML emails links_in_email will include the URIs specified in the Doctype URI, any HTML namespace tags.

e.g.

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en' lang='en'>

This breaks click_first_link_in_email for HTML emails because the first link is http://www.w3.org/TR/html4/loose.dtd in this example.

I patched my version to this hacky solulution:

def links_in_email(email)
  URI.extract(email.default_part_body.to_s, ['http', 'https']).reject do |link|
    ['www.w3.org', 'www.openmobilealliance.org'].include? URI.parse(link).host
  end
end

An ideal solution would probably use Nokogiri to get the links from all the <a href=...> elements

Missing dependencies

When trying to use your gem I got the following error: http://gist.github.com/268484. My workaround is to require the missing file before the helpers in spec_helper.rb

like this:

require 'email_spec/background_processes'
require 'email_spec/helpers'
require 'email_spec/matchers'

Invalid gemspec (Version 0.6.2) in rails3 branch

$ bundle update
...
...
Using email_spec (0.6.2) from git://github.com/bmabey/email-spec.git (at rails3)  
email_spec at /Users/xxx/.rvm/gems/ruby-1.9.2-rc2/bundler/gems/email-spec-e197a16 did not have a valid gemspec. 

This prevents bundler from installing bins or native extensions, 
but that may not affect its functionality. 

The validation message from Rubygems was:   
 ["examples/rails3_root/tmp", 
 "examples/rails3_root/tmp/cache",  
 "examples/rails3_root/tmp/pids", 
 "examples/rails3_root/tmp/sessions", 
 "examples/rails3_root/tmp/sockets"] 
 are not files

visit_in_email throws error when not using cucumber

when trying to: visit_in_email 'Confirm registration' i get:
NameError: undefined local variable or method `current_email_address' for RSpec::Core::ExampleGroup::Nested_1:0x9f18570

i'm writing test in steak, and that current_email_address is declared only in some cucumber stuff i think.

Attachment Testing

Something that would be handy to have is Cucumber steps for testing of email attachments.

When I open the email
Then it should have 5 attachments
And attachment 1 should be named "instructions.pdf"
And attachment 2 should be named "login_details.pdf"
And all attachments should be of type "application/pdf"
And all attachments should not be blank

DelayedJob conflicts

I don't use delayed job, but I guess ThinkingSphinx (which I do use) defines the Delayed constant.

Is there a good way to disable what happens here:
lib/email_spec/background_processes.rb:25
@@@
module Compatibility
if defined?(Delayed)
include EmailSpec::BackgroundProcesses::DelayedJob
end
end
@@@

Documentation for how to configure email_spec

If you had the time to add documentation for how to configure email_spec, that would be grand.

Pony is sending mail, but email_spec isn't seeing it, probably because I've not configured it correctly.

In particular, further detail about how to configure current_email_address would be useful.

Thank you.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.