email_spec 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -3,14 +3,24 @@
3
3
  === New features
4
4
  === Bufixes
5
5
 
6
+ == 0.3.1 2009-08-19
7
+ This release is a general refactoring of the steps and helpers.
8
+ The example rails app was also updated to use the lateset rails and webrat. It also takes advantages
9
+ and the newer step definistions including the new third-person forms.
10
+
11
+ Some of the generated steps are being removed in favor of some of the newer ones. The older ones
12
+ will remain until 0.3.5 but will issue deprecation warnings.
13
+
14
+ Big shoutout to Kieran Pilkington who did the majority of work for this release.
15
+
6
16
  == 0.3.0 2009-08-13
7
17
 
8
18
  === New features
9
19
  * New helper #last_email_address which returns the last address used by email-spec for that scenario. (Ben Mabey)
10
20
  * Steps now support third person language. (Kieran P)
11
- * "[email] should receive ... " now supports "an" instead of just an integer. (Kieran P)
21
+ * "[email] should receive ... " now supports "an" instead of just an integer. (Kieran Pilkington)
12
22
  With these changes, the following is now possible:
13
-
23
+
14
24
  Then "jack@example.com" should receive an email
15
25
  When they open the email
16
26
  Then they should see "Account has been created" in the subject
data/Rakefile CHANGED
@@ -14,7 +14,8 @@ begin
14
14
  s.bindir = "bin"
15
15
  s.description = s.summary
16
16
  s.require_path = "lib"
17
- s.files = %w(History.txt install.rb MIT-LICENSE.txt README.rdoc Rakefile) + Dir["lib/**/*"] + Dir["rails_generators/**/*"] + Dir["spec/**/*"] + Dir["examples/**/*"]
17
+ s.files = %w(History.txt install.rb MIT-LICENSE.txt README.rdoc Rakefile) + Dir["lib/**/*"] + Dir["rails_generators/**/*"]
18
+ s.test_files = Dir["spec/**/*"] + Dir["examples/**/*"]
18
19
  # rdoc
19
20
  s.has_rdoc = true
20
21
  s.extra_rdoc_files = %w(README.rdoc MIT-LICENSE.txt)
@@ -24,6 +25,14 @@ rescue LoadError
24
25
  puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
25
26
  end
26
27
 
28
+
29
+ begin
30
+ gem 'fixjour'
31
+ rescue Gem::LoadError
32
+ puts "Installing fixjour for the example rails app..."
33
+ puts `gem install fixjour --no-rdoc --no-ri`
34
+ end
35
+
27
36
  begin
28
37
  require 'cucumber/rake/task'
29
38
  Cucumber::Rake::Task.new(:features)
@@ -1,6 +1,5 @@
1
1
  class UserMailer < ActionMailer::Base
2
- default_url_options[:host] = ''
3
-
2
+ default_url_options = {:host => 'example.com'}
4
3
  def signup(email, name)
5
4
  @recipients = email
6
5
  @from = "admin@example.com"
@@ -44,6 +44,7 @@ module Rails
44
44
  def load_initializer
45
45
  require "#{RAILS_ROOT}/vendor/rails/railties/lib/initializer"
46
46
  Rails::Initializer.run(:install_gem_spec_stubs)
47
+ Rails::GemDependency.add_frozen_gem_path
47
48
  end
48
49
  end
49
50
 
@@ -5,7 +5,7 @@
5
5
  # ENV['RAILS_ENV'] ||= 'production'
6
6
 
7
7
  # Specifies gem version of Rails to use when vendor/rails is not present
8
- RAILS_GEM_VERSION = '2.2.2' unless defined? RAILS_GEM_VERSION
8
+ RAILS_GEM_VERSION = '2.3.3' unless defined? RAILS_GEM_VERSION
9
9
 
10
10
  # Bootstrap the Rails environment, frameworks, and default configuration
11
11
  require File.join(File.dirname(__FILE__), 'boot')
@@ -13,7 +13,7 @@ require File.join(File.dirname(__FILE__), 'boot')
13
13
  Rails::Initializer.run do |config|
14
14
 
15
15
  config.time_zone = 'UTC'
16
-
16
+
17
17
  config.action_controller.session = {
18
18
  :session_key => '_es_session',
19
19
  :secret => 'b9327c7967925fb36f8901e43f47e0a3e8fc7856ae1b4533ddeda776381548f9ac051721446fdbc4ccc88c7353124708e73d8b0950a30487571d8f8eb5b24732'
@@ -20,14 +20,10 @@ config.action_controller.allow_forgery_protection = false
20
20
  # The :test delivery method accumulates sent emails in the
21
21
  # ActionMailer::Base.deliveries array.
22
22
  config.action_mailer.delivery_method = :test
23
+ config.action_mailer.default_url_options = { :host => "example.com" }
23
24
 
24
-
25
- # I HATE config.gem.. it doesn't work as advertised...
26
- config.gem 'webrat', :source => "http://gems.github.com"
27
- #config.gem 'rspec', :lib => 'spec'
28
- #config.gem 'rspec-rails', :lib => 'spec/rails'
29
- config.gem 'cucumber', :source => "http://gems.github.com" # aslakhellesoy-cucumber
30
- config.gem 'nakajima-fixjour', :lib => 'fixjour', :source => "http://gems.github.com" # nakajima-fixjour
31
-
32
-
33
-
25
+ config.gem 'cucumber', :lib => false
26
+ config.gem 'webrat', :lib => false
27
+ config.gem 'rspec', :lib => false
28
+ config.gem 'rspec-rails', :lib => 'spec/rails'
29
+ config.gem 'fixjour', :lib => 'fixjour'
@@ -1,42 +1,32 @@
1
1
  Feature: Email-spec errors example
2
-
3
- In order to help alleviate email testing in apps
4
- As a email-spec contributor I a newcomer
5
- Should be able to easily determine where I have gone wrong
6
- These scenarios should fail with helpful messages
7
-
8
- Scenario: I fail to receive an email
9
- Given I am at "/"
10
- And no emails have been sent
11
- When I fill in "Email" with "example@example.com"
12
- And I press "Sign up"
13
- And I should receive an email
14
- When "example@example.com" opens the email with subject "no email"
15
-
16
- Scenario: I fail to receive an email with the expected link
17
- Given I am at "/"
18
- And no emails have been sent
19
- When I fill in "Email" with "example@example.com"
20
- And I press "Sign up"
21
- And I should receive an email
22
- When I open the email
23
- When I follow "link that doesn't exist" in the email
24
-
25
- Scenario: I attempt to operate on an email that is not opened
26
- Given I am at "/"
27
- And no emails have been sent
28
- When I fill in "Email" with "example@example.com"
29
- And I press "Sign up"
30
- And I should receive an email
31
- When I follow "confirm" in the email
32
-
33
- Scenario: I attempt to check out an unopened email
34
- Given I am at "/"
35
- And no emails have been sent
36
- When I fill in "Email" with "example@example.com"
37
- And I press "Sign up"
38
- Then I should see "confirm" in the email
39
- And I should see "Account confirmation" in the subject
40
-
41
-
42
-
2
+ In order to help alleviate email testing in apps
3
+ As a email-spec contributor I a newcomer
4
+ Should be able to easily determine where I have gone wrong
5
+ These scenarios should fail with helpful messages
6
+
7
+ Background:
8
+ Given I am on the homepage
9
+ And no emails have been sent
10
+ When I fill in "Email" with "example@example.com"
11
+ And I press "Sign up"
12
+
13
+ Scenario: I fail to open an email with incorrect subject
14
+ Then I should receive an email
15
+ When "example@example.com" opens the email with subject "no email"
16
+
17
+ Scenario: I fail to open an email with incorrect text
18
+ Then I should receive an email
19
+ When "example@example.com" opens the email with text "no email"
20
+
21
+ Scenario: I fail to receive an email with the expected link
22
+ Then I should receive an email
23
+ When I open the email
24
+ When I follow "link that doesn't exist" in the email
25
+
26
+ Scenario: I attempt to operate on an email that is not opened
27
+ Then I should receive an email
28
+ When I follow "confirm" in the email
29
+
30
+ Scenario: I attempt to check out an unopened email
31
+ Then I should see "confirm" in the email body
32
+ And I should see "Account confirmation" in the email subject
@@ -1,59 +1,62 @@
1
1
  Feature: EmailSpec Example -- Prevent Bots from creating accounts
2
2
 
3
- In order to help alleviate email testing in apps
4
- As an email-spec contributor I want new users of the library
5
- to easily adopt email-spec in their app by following this example
3
+ In order to help alleviate email testing in apps
4
+ As an email-spec contributor I want new users of the library
5
+ to easily adopt email-spec in their app by following this example
6
6
 
7
- In order to prevent bots from setting up new accounts
8
- As a site manager I want new users
9
- to verify their email address with a confirmation link
7
+ In order to prevent bots from setting up new accounts
8
+ As a site manager I want new users
9
+ to verify their email address with a confirmation link
10
10
 
11
- Scenario: A new person signs up imperatively
12
- Given I am a real person wanting to sign up for an account
13
- And I am at "/"
11
+ Background:
12
+ Given no emails have been sent
13
+ And I am a real person wanting to sign up for an account
14
+ And I am on the homepage
15
+ And I submit my registration information
14
16
 
15
- When I fill in "Email" with "example@example.com"
16
- And I fill in "Name" with "example Jones"
17
- And I press "Sign up"
18
-
19
- Then "example@example.com" should receive 1 email
20
- And "example@example.com" should have 1 email
21
- And "foo@bar.com" should not receive an email
17
+ Scenario: First person signup (as myself) with two ways of opening email
18
+ Then I should receive an email
19
+ And I should have 1 email
22
20
 
23
- When "example@example.com" opens the email with subject "Account confirmation"
21
+ # Opening email #1
22
+ When I open the email
23
+ Then I should see "Account confirmation" in the email subject
24
+ And I should see "Joe Someone" in the email body
25
+ And I should see "confirm" in the email body
24
26
 
25
- Then I should see "confirm" in the email
26
- And I should see "example Jones" in the email
27
- And I should see "Account confirmation" in the subject
27
+ # Opening email #2
28
+ When I open the email with subject "Account confirmation"
29
+ Then I should see "Account confirmation" in the email subject
30
+ And I should see "Joe Someone" in the email body
31
+ And I should see "confirm" in the email body
28
32
 
29
33
  When I follow "Click here to confirm your account!" in the email
30
34
  Then I should see "Confirm your new account"
31
35
 
36
+ And "foo@bar.com" should have no emails
32
37
 
33
- Scenario: slightly more declarative, but still mostly imperative
34
- Given I am a real person wanting to sign up for an account
35
- And I'm on the signup page
36
-
37
- When I fill in "Email" with "example@example.com"
38
- And I fill in "Name" with "example Jones"
39
- And I press "Sign up"
40
-
41
- Then I should receive an email
42
-
43
- When I open the email
44
- Then I should see "Account confirmation" in the subject
38
+ Scenario: Third person signup (emails sent to others) with two ways of opening email
39
+ Then "foo@bar.com" should have no emails
40
+ And "example@example.com" should receive an email
41
+ And "example@example.com" should have 1 email
45
42
 
46
- When I follow "http:///confirm" in the email
47
- Then I should see "Confirm your new account"
43
+ # Opening email #1
44
+ When they open the email
45
+ Then they should see "Account confirmation" in the email subject
46
+ And they should see "Joe Someone" in the email body
47
+ And they should see "confirm" in the email body
48
48
 
49
+ # Opening email #2
50
+ When "example@example.com" opens the email with subject "Account confirmation"
51
+ Then they should see "Account confirmation" in the email subject
52
+ And they should see "Joe Someone" in the email body
53
+ And they should see "confirm" in the email body
49
54
 
50
- Scenario: declarative
51
- Given I am a real person wanting to sign up for an account
52
- And I'm on the signup page
55
+ When they follow "Click here to confirm your account!" in the email
56
+ Then they should see "Confirm your new account"
53
57
 
54
- When I submit my registration information
58
+ Scenario: Declarative First Person signup
55
59
  Then I should receive an email with a link to a confirmation page
56
60
 
57
-
58
-
59
-
61
+ Scenario: Declarative First Person signup
62
+ Then they should receive an email with a link to a confirmation page
@@ -1,9 +1,10 @@
1
- #Commonly used email steps
1
+ # Commonly used email steps
2
2
  #
3
3
  # To add your own steps make a custom_email_steps.rb
4
4
  # The provided methods are:
5
5
  #
6
- # reset_mailer
6
+ # last_email_address
7
+ # reset_mailer
7
8
  # open_last_email
8
9
  # visit_in_email
9
10
  # unread_emails_for
@@ -12,6 +13,16 @@
12
13
  # open_email
13
14
  # read_emails_for
14
15
  # find_email
16
+ #
17
+ # General form for email scenarios are:
18
+ # - clear the email queue (done automatically by email_spec)
19
+ # - execute steps that sends an email
20
+ # - check the user received an/no/[0-9] emails
21
+ # - open the email
22
+ # - inspect the email contents
23
+ # - interact with the email (e.g. click links)
24
+ #
25
+ # The Cucumber steps below are setup in this order.
15
26
 
16
27
  module EmailHelpers
17
28
  def current_email_address
@@ -21,63 +32,88 @@ module EmailHelpers
21
32
  last_email_address || "example@example.com"
22
33
  end
23
34
  end
35
+
24
36
  World(EmailHelpers)
25
37
 
26
- # Use this step to reset the e-mail queue within a scenario.
38
+ #
39
+ # Reset the e-mail queue within a scenario.
27
40
  # This is done automatically before each scenario.
41
+ #
42
+
28
43
  Given /^(?:a clear email queue|no emails have been sent)$/ do
29
44
  reset_mailer
30
45
  end
31
46
 
32
- # Use this step to open the most recently sent e-mail.
33
- When /^(?:I|they) open the email$/ do
34
- open_email(current_email_address)
35
- end
47
+ #
48
+ # Check how many emails have been sent/received
49
+ #
36
50
 
37
- When %r{^(?:I|they) follow "([^"]*?)" in the email$} do |link|
38
- visit_in_email(link)
51
+ Then /^(?:I|they|"([^"]*?)") should receive (an|no|\d+) emails?$/ do |address, amount|
52
+ unread_emails_for(address).size.should == parse_email_count(amount)
39
53
  end
40
54
 
41
- Then /^(?:I|they) should receive (an|\d+) emails?$/ do |amount|
42
- amount = 1 if amount == "an"
43
- unread_emails_for(current_email_address).size.should == amount.to_i
55
+ Then /^(?:I|they|"([^"]*?)") should have (an|no|\d+) emails?$/ do |address, amount|
56
+ mailbox_for(address).size.should == parse_email_count(amount)
44
57
  end
45
58
 
46
- Then /^(?:I|they) should not receive any emails?$/ do
47
- unread_emails_for(current_email_address).size.should == 0
59
+ # DEPRECATED
60
+ # The following methods are left in for backwards compatibility and
61
+ # should be removed by version 0.3.5.
62
+ Then /^(?:I|they|"([^"]*?)") should not receive an email$/ do |address|
63
+ email_spec_deprecate "The step 'I/they/[email] should not receive an email' is no longer supported.
64
+ Please use 'I/they/[email] should receive no emails' instead."
65
+ unread_emails_for(address).size.should == 0
48
66
  end
49
67
 
50
- Then %r{^"([^"]*?)" should receive (an|\d+) emails?$} do |address, amount|
51
- amount = 1 if amount == "an"
52
- unread_emails_for(address).size.should == amount.to_i
68
+ #
69
+ # Accessing emails
70
+ #
71
+
72
+ # Opens the most recently received email
73
+ When /^(?:I|they|"([^"]*?)") opens? the email$/ do |address|
74
+ open_email(address)
53
75
  end
54
76
 
55
- Then %r{^"([^"]*?)" should have (\d+) emails?$} do |address, n|
56
- mailbox_for(address).size.should == n.to_i
77
+ When /^(?:I|they|"([^"]*?)") opens? the email with subject "([^"]*?)"$/ do |address, subject|
78
+ open_email(address, :with_subject => subject)
57
79
  end
58
80
 
59
- Then %r{^"([^"]*?)" should not receive an email$} do |address|
60
- find_email(address).should be_nil
81
+ When /^(?:I|they|"([^"]*?)") opens? the email with text "([^"]*?)"$/ do |address, text|
82
+ open_email(address, :with_text => text)
61
83
  end
62
84
 
63
- Then %r{^(?:I|they) should see "([^"]*?)" in the subject$} do |text|
85
+ #
86
+ # Inspect the Email Contents
87
+ #
88
+
89
+ Then /^(?:I|they) should see "([^"]*?)" in the email subject$/ do |text|
64
90
  current_email.should have_subject(Regexp.new(text))
65
91
  end
66
92
 
67
- Then %r{^(?:I|they) should see "([^"]*?)" in the email$} do |text|
93
+ Then /^(?:I|they) should see "([^"]*?)" in the email body$/ do |text|
68
94
  current_email.body.should =~ Regexp.new(text)
69
95
  end
70
96
 
71
- When %r{^"([^"]*?)" opens? the email$} do |address|
72
- open_email(address)
97
+ # DEPRECATED
98
+ # The following methods are left in for backwards compatibility and
99
+ # should be removed by version 0.3.5.
100
+ Then /^(?:I|they) should see "([^"]*?)" in the subject$/ do |text|
101
+ email_spec_deprecate "The step 'I/they should see [text] in the subject' is no longer supported.
102
+ Please use 'I/they should see [text] in the email subject' instead."
103
+ current_email.should have_subject(Regexp.new(text))
73
104
  end
74
-
75
- When %r{^"([^"]*?)" opens? the email with subject "([^"]*?)"$} do |address, subject|
76
- open_email(address, :with_subject => subject)
105
+ Then /^(?:I|they) should see "([^"]*?)" in the email$/ do |text|
106
+ email_spec_deprecate "The step 'I/they should see [text] in the email' is no longer supported.
107
+ Please use 'I/they should see [text] in the email body' instead."
108
+ current_email.body.should =~ Regexp.new(text)
77
109
  end
78
110
 
79
- When %r{^"([^"]*?)" opens? the email with text "([^"]*?)"$} do |address, text|
80
- open_email(address, :with_text => text)
111
+ #
112
+ # Interact with Email Contents
113
+ #
114
+
115
+ When /^(?:I|they) follow "([^"]*?)" in the email$/ do |link|
116
+ visit_in_email(link)
81
117
  end
82
118
 
83
119
  When /^(?:I|they) click the first link in the email$/ do
@@ -3,21 +3,24 @@ Given "I am a real person wanting to sign up for an account" do
3
3
  end
4
4
 
5
5
  When /^I submit my registration information$/ do
6
- fill_in "Name", :with => valid_user_attributes[:name]
7
- fill_in "Email", :with => valid_user_attributes[:email]
6
+ fill_in "Name", :with => 'Joe Someone'
7
+ fill_in "Email", :with => 'example@example.com'
8
8
  click_button
9
9
  end
10
10
 
11
- Then /^I should receive an email with a link to a confirmation page$/ do
12
- unread_emails_for(valid_user_attributes[:email]).size.should == 1
13
-
11
+ Then /^(?:I|they) should receive an email with a link to a confirmation page$/ do
12
+ unread_emails_for(current_email_address).size.should == 1
13
+
14
14
  # this call will store the email and you can access it with current_email
15
- open_last_email_for(valid_user_attributes[:email])
15
+ open_last_email_for(last_email_address)
16
16
  current_email.should have_subject(/Account confirmation/)
17
- current_email.should have_body_text(valid_user_attributes[:name])
17
+ current_email.should have_body_text('Joe Someone')
18
18
 
19
19
  click_email_link_matching /confirm/
20
20
  response.should include_text("Confirm your new account")
21
-
22
21
  end
23
22
 
23
+ # Basically aliases "I should see [text]", but for third person
24
+ Then /^they should see "([^\"]*)"$/ do |text|
25
+ Then "I should see \"#{text}\""
26
+ end