bmabey-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.
Files changed (26) hide show
  1. data/History.txt +12 -2
  2. data/Rakefile +16 -1
  3. data/examples/rails_root/app/controllers/{application.rb → application_controller.rb} +0 -0
  4. data/examples/rails_root/app/models/user_mailer.rb +1 -2
  5. data/examples/rails_root/config/boot.rb +1 -0
  6. data/examples/rails_root/config/environment.rb +2 -2
  7. data/examples/rails_root/config/environments/test.rb +6 -10
  8. data/examples/rails_root/features/errors.feature +31 -41
  9. data/examples/rails_root/features/example.feature +44 -41
  10. data/examples/rails_root/features/step_definitions/user_steps.rb +11 -8
  11. data/examples/rails_root/features/step_definitions/webrat_steps.rb +72 -39
  12. data/examples/rails_root/features/support/env.rb +15 -4
  13. data/examples/rails_root/features/support/paths.rb +21 -0
  14. data/examples/rails_root/script/cucumber +6 -4
  15. data/examples/rails_root/spec/models/user_mailer_spec.rb +3 -3
  16. data/examples/rails_root/spec/spec_helper.rb +1 -1
  17. data/lib/email_spec/deliveries.rb +0 -2
  18. data/lib/email_spec/helpers.rb +48 -31
  19. data/rails_generators/email_spec/templates/email_steps.rb +66 -30
  20. metadata +72 -83
  21. data/examples/rails_root/cucumber.yml +0 -1
  22. data/examples/rails_root/features/step_definitions/email_steps.rb +0 -86
  23. data/examples/rails_root/stories/all.rb +0 -4
  24. data/examples/rails_root/stories/helper.rb +0 -3
  25. data/examples/rails_root/vendor/plugins/email_spec/rails_generators/email_spec/email_spec_generator.rb +0 -17
  26. data/examples/rails_root/vendor/plugins/email_spec/rails_generators/email_spec/templates/email_steps.rb +0 -86
data/History.txt CHANGED
@@ -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)
@@ -51,8 +60,14 @@ task :default => [:features, :spec, 'example_app:spec']
51
60
 
52
61
  desc "Cleans the project of any tmp file that should not be included in the gemspec."
53
62
  task :clean do
63
+ FileUtils.rm_f('examples/rails_root/features/step_definitions/email_steps.rb')
64
+ FileUtils.rm_rf('examples/rails_root/log')
65
+ FileUtils.rm_rf('examples/rails_root/vendor')
54
66
  %w[*.sqlite3 *.log].each do |pattern|
55
67
  `find . -name "#{pattern}" -delete`
56
68
  end
57
69
  end
58
70
 
71
+ desc "Cleans the dir and builds the gem"
72
+ task :prep => [:clean, :gemspec, :build]
73
+
@@ -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
@@ -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
@@ -1,104 +1,137 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), "..", "support", "paths"))
2
+
1
3
  # Commonly used webrat steps
2
4
  # http://github.com/brynary/webrat
3
5
 
4
- Given /^I am at "(.+)"$/ do |path|
5
- visit path
6
+ Given /^I am on (.+)$/ do |page_name|
7
+ visit path_to(page_name)
6
8
  end
7
9
 
8
- Given /^I'm on the (.+) page$/ do |page|
9
- locations = {"signup" => "/"}
10
- visit locations[page]
10
+ When /^I go to (.+)$/ do |page_name|
11
+ visit path_to(page_name)
11
12
  end
12
13
 
13
- When /^I press "(.*)"$/ do |button|
14
+ When /^I press "([^\"]*)"$/ do |button|
14
15
  click_button(button)
15
16
  end
16
17
 
17
- When /^I follow "(.*)"$/ do |link|
18
+ When /^I follow "([^\"]*)"$/ do |link|
18
19
  click_link(link)
19
20
  end
20
21
 
21
- When /^I fill in "(.*)" with "(.*)"$/ do |field, value|
22
- fill_in(field, :with => value)
22
+ When /^I follow "([^\"]*)" within "([^\"]*)"$/ do |link, parent|
23
+ click_link_within(parent, link)
24
+ end
25
+
26
+ When /^I fill in "([^\"]*)" with "([^\"]*)"$/ do |field, value|
27
+ fill_in(field, :with => value)
23
28
  end
24
29
 
25
- When /^I select "(.*)" from "(.*)"$/ do |value, field|
26
- select(value, :from => field)
30
+ When /^I select "([^\"]*)" from "([^\"]*)"$/ do |value, field|
31
+ select(value, :from => field)
27
32
  end
28
33
 
29
34
  # Use this step in conjunction with Rail's datetime_select helper. For example:
30
- # When I select "December 25, 2008 10:00" as the date and time
31
- When /^I select "(.*)" as the date and time$/ do |time|
35
+ # When I select "December 25, 2008 10:00" as the date and time
36
+ When /^I select "([^\"]*)" as the date and time$/ do |time|
32
37
  select_datetime(time)
33
38
  end
34
39
 
35
- # Use this step when using multiple datetime_select helpers on a page or
40
+ # Use this step when using multiple datetime_select helpers on a page or
36
41
  # you want to specify which datetime to select. Given the following view:
37
- # <%= f.label :preferred %><br />
38
- # <%= f.datetime_select :preferred %>
39
- # <%= f.label :alternative %><br />
40
- # <%= f.datetime_select :alternative %>
42
+ # <%%= f.label :preferred %><br />
43
+ # <%%= f.datetime_select :preferred %>
44
+ # <%%= f.label :alternative %><br />
45
+ # <%%= f.datetime_select :alternative %>
41
46
  # The following steps would fill out the form:
42
- # When I select "November 23, 2004 11:20" as the "Preferred" data and time
43
- # And I select "November 25, 2004 10:30" as the "Alternative" data and time
44
- When /^I select "(.*)" as the "(.*)" date and time$/ do |datetime, datetime_label|
47
+ # When I select "November 23, 2004 11:20" as the "Preferred" date and time
48
+ # And I select "November 25, 2004 10:30" as the "Alternative" date and time
49
+ When /^I select "([^\"]*)" as the "([^\"]*)" date and time$/ do |datetime, datetime_label|
45
50
  select_datetime(datetime, :from => datetime_label)
46
51
  end
47
52
 
48
- # Use this step in conjuction with Rail's time_select helper. For example:
53
+ # Use this step in conjunction with Rail's time_select helper. For example:
49
54
  # When I select "2:20PM" as the time
50
55
  # Note: Rail's default time helper provides 24-hour time-- not 12 hour time. Webrat
51
- # will convert the 2:20PM to 14:20 and then select it.
52
- When /^I select "(.*)" as the time$/ do |time|
56
+ # will convert the 2:20PM to 14:20 and then select it.
57
+ When /^I select "([^\"]*)" as the time$/ do |time|
53
58
  select_time(time)
54
59
  end
55
60
 
56
61
  # Use this step when using multiple time_select helpers on a page or you want to
57
62
  # specify the name of the time on the form. For example:
58
63
  # When I select "7:30AM" as the "Gym" time
59
- When /^I select "(.*)" as the "(.*)" time$/ do |time, time_label|
64
+ When /^I select "([^\"]*)" as the "([^\"]*)" time$/ do |time, time_label|
60
65
  select_time(time, :from => time_label)
61
66
  end
62
67
 
63
- # Use this step in conjuction with Rail's date_select helper. For example:
68
+ # Use this step in conjunction with Rail's date_select helper. For example:
64
69
  # When I select "February 20, 1981" as the date
65
- When /^I select "(.*)" as the date$/ do |date|
70
+ When /^I select "([^\"]*)" as the date$/ do |date|
66
71
  select_date(date)
67
72
  end
68
73
 
69
74
  # Use this step when using multiple date_select helpers on one page or
70
75
  # you want to specify the name of the date on the form. For example:
71
76
  # When I select "April 26, 1982" as the "Date of Birth" date
72
- When /^I select "(.*)" as the "(.*)" date$/ do |date, date_label|
77
+ When /^I select "([^\"]*)" as the "([^\"]*)" date$/ do |date, date_label|
73
78
  select_date(date, :from => date_label)
74
79
  end
75
80
 
76
- When /^I check "(.*)"$/ do |field|
77
- check(field)
81
+ When /^I check "([^\"]*)"$/ do |field|
82
+ check(field)
78
83
  end
79
84
 
80
- When /^I uncheck "(.*)"$/ do |field|
81
- uncheck(field)
85
+ When /^I uncheck "([^\"]*)"$/ do |field|
86
+ uncheck(field)
82
87
  end
83
88
 
84
- When /^I choose "(.*)"$/ do |field|
89
+ When /^I choose "([^\"]*)"$/ do |field|
85
90
  choose(field)
86
91
  end
87
92
 
88
- When /^I attach the file at "(.*)" to "(.*)" $/ do |path, field|
93
+ When /^I attach the file at "([^\"]*)" to "([^\"]*)"$/ do |path, field|
89
94
  attach_file(field, path)
90
95
  end
91
96
 
92
- Then /^I should see "(.*)"$/ do |text|
93
- response.body.should =~ /#{text}/m
97
+ Then /^I should see "([^\"]*)"$/ do |text|
98
+ response.should contain(text)
99
+ end
100
+
101
+ Then /^I should see \/([^\/]*)\/$/ do |regexp|
102
+ regexp = Regexp.new(regexp)
103
+ response.should contain(regexp)
104
+ end
105
+
106
+ Then /^I should not see "([^\"]*)"$/ do |text|
107
+ response.should_not contain(text)
94
108
  end
95
109
 
96
- Then /^I should not see "(.*)"$/ do |text|
97
- response.body.should_not =~ /#{text}/m
110
+ Then /^I should not see \/([^\/]*)\/$/ do |regexp|
111
+ regexp = Regexp.new(regexp)
112
+ response.should_not contain(regexp)
98
113
  end
99
114
 
100
- Then /^the "(.*)" checkbox should be checked$/ do |label|
115
+ Then /^the "([^\"]*)" field should contain "([^\"]*)"$/ do |field, value|
116
+ field_labeled(field).value.should =~ /#{value}/
117
+ end
118
+
119
+ Then /^the "([^\"]*)" field should not contain "([^\"]*)"$/ do |field, value|
120
+ field_labeled(field).value.should_not =~ /#{value}/
121
+ end
122
+
123
+ Then /^the "([^\"]*)" checkbox should be checked$/ do |label|
101
124
  field_labeled(label).should be_checked
102
125
  end
103
126
 
127
+ Then /^the "([^\"]*)" checkbox should not be checked$/ do |label|
128
+ field_labeled(label).should_not be_checked
129
+ end
130
+
131
+ Then /^I should be on (.+)$/ do |page_name|
132
+ URI.parse(current_url).path.should == path_to(page_name)
133
+ end
104
134
 
135
+ Then /^show me the page$/ do
136
+ save_and_open_page
137
+ end