rainchen-email_spec 0.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (90) hide show
  1. data/History.txt +75 -0
  2. data/MIT-LICENSE.txt +19 -0
  3. data/README.rdoc +125 -0
  4. data/Rakefile +50 -0
  5. data/examples/rails_root/Rakefile +7 -0
  6. data/examples/rails_root/app/controllers/application.rb +15 -0
  7. data/examples/rails_root/app/controllers/welcome_controller.rb +9 -0
  8. data/examples/rails_root/app/helpers/application_helper.rb +3 -0
  9. data/examples/rails_root/app/helpers/welcome_helper.rb +2 -0
  10. data/examples/rails_root/app/models/user.rb +2 -0
  11. data/examples/rails_root/app/models/user_mailer.rb +12 -0
  12. data/examples/rails_root/app/views/user_mailer/signup.erb +3 -0
  13. data/examples/rails_root/app/views/welcome/confirm.html.erb +1 -0
  14. data/examples/rails_root/app/views/welcome/index.html.erb +8 -0
  15. data/examples/rails_root/app/views/welcome/signup.html.erb +1 -0
  16. data/examples/rails_root/config/boot.rb +109 -0
  17. data/examples/rails_root/config/database.yml +22 -0
  18. data/examples/rails_root/config/environment.rb +22 -0
  19. data/examples/rails_root/config/environments/development.rb +17 -0
  20. data/examples/rails_root/config/environments/production.rb +24 -0
  21. data/examples/rails_root/config/environments/test.rb +33 -0
  22. data/examples/rails_root/config/initializers/inflections.rb +10 -0
  23. data/examples/rails_root/config/initializers/mime_types.rb +5 -0
  24. data/examples/rails_root/config/initializers/new_rails_defaults.rb +17 -0
  25. data/examples/rails_root/config/routes.rb +43 -0
  26. data/examples/rails_root/cucumber.yml +1 -0
  27. data/examples/rails_root/db/migrate/20090125013728_create_users.rb +11 -0
  28. data/examples/rails_root/db/schema.rb +19 -0
  29. data/examples/rails_root/doc/README_FOR_APP +5 -0
  30. data/examples/rails_root/features/errors.feature +42 -0
  31. data/examples/rails_root/features/example.feature +59 -0
  32. data/examples/rails_root/features/step_definitions/email_steps.rb +74 -0
  33. data/examples/rails_root/features/step_definitions/user_steps.rb +23 -0
  34. data/examples/rails_root/features/step_definitions/webrat_steps.rb +104 -0
  35. data/examples/rails_root/features/support/env.rb +21 -0
  36. data/examples/rails_root/public/404.html +30 -0
  37. data/examples/rails_root/public/422.html +30 -0
  38. data/examples/rails_root/public/500.html +33 -0
  39. data/examples/rails_root/public/dispatch.rb +10 -0
  40. data/examples/rails_root/public/favicon.ico +0 -0
  41. data/examples/rails_root/public/images/rails.png +0 -0
  42. data/examples/rails_root/public/javascripts/application.js +2 -0
  43. data/examples/rails_root/public/javascripts/controls.js +963 -0
  44. data/examples/rails_root/public/javascripts/dragdrop.js +973 -0
  45. data/examples/rails_root/public/javascripts/effects.js +1128 -0
  46. data/examples/rails_root/public/javascripts/prototype.js +4320 -0
  47. data/examples/rails_root/public/robots.txt +5 -0
  48. data/examples/rails_root/script/about +4 -0
  49. data/examples/rails_root/script/autospec +5 -0
  50. data/examples/rails_root/script/console +3 -0
  51. data/examples/rails_root/script/cucumber +7 -0
  52. data/examples/rails_root/script/dbconsole +3 -0
  53. data/examples/rails_root/script/destroy +3 -0
  54. data/examples/rails_root/script/generate +3 -0
  55. data/examples/rails_root/script/performance/benchmarker +3 -0
  56. data/examples/rails_root/script/performance/profiler +3 -0
  57. data/examples/rails_root/script/performance/request +3 -0
  58. data/examples/rails_root/script/plugin +3 -0
  59. data/examples/rails_root/script/process/inspector +3 -0
  60. data/examples/rails_root/script/process/reaper +3 -0
  61. data/examples/rails_root/script/process/spawner +3 -0
  62. data/examples/rails_root/script/runner +3 -0
  63. data/examples/rails_root/script/server +3 -0
  64. data/examples/rails_root/script/spec +5 -0
  65. data/examples/rails_root/script/spec_server +125 -0
  66. data/examples/rails_root/spec/controllers/welcome_controller_spec.rb +15 -0
  67. data/examples/rails_root/spec/model_factory.rb +6 -0
  68. data/examples/rails_root/spec/models/user_mailer_spec.rb +58 -0
  69. data/examples/rails_root/spec/models/user_spec.rb +5 -0
  70. data/examples/rails_root/spec/rcov.opts +2 -0
  71. data/examples/rails_root/spec/spec.opts +4 -0
  72. data/examples/rails_root/spec/spec_helper.rb +51 -0
  73. data/examples/rails_root/stories/all.rb +4 -0
  74. data/examples/rails_root/stories/helper.rb +3 -0
  75. data/examples/rails_root/vendor/plugins/email_spec/rails_generators/email_spec/email_spec_generator.rb +17 -0
  76. data/examples/rails_root/vendor/plugins/email_spec/rails_generators/email_spec/templates/email_steps.rb +74 -0
  77. data/install.rb +0 -0
  78. data/lib/email_spec.rb +14 -0
  79. data/lib/email_spec/address_converter.rb +27 -0
  80. data/lib/email_spec/cucumber.rb +19 -0
  81. data/lib/email_spec/deliveries.rb +55 -0
  82. data/lib/email_spec/email_viewer.rb +70 -0
  83. data/lib/email_spec/helpers.rb +129 -0
  84. data/lib/email_spec/matchers.rb +122 -0
  85. data/rails_generators/email_spec/email_spec_generator.rb +17 -0
  86. data/rails_generators/email_spec/templates/email_steps.rb +74 -0
  87. data/spec/email_spec/matchers_spec.rb +159 -0
  88. data/spec/spec.opts +4 -0
  89. data/spec/spec_helper.rb +4 -0
  90. metadata +176 -0
@@ -0,0 +1,17 @@
1
+ # This generator adds email steps to the step definitions directory
2
+ generator_base = defined?(Rails) ? Rails::Generator::Base : RubiGen::Base
3
+ class EmailSpecGenerator < generator_base
4
+ def manifest
5
+ record do |m|
6
+ m.directory 'features/step_definitions'
7
+ m.file 'email_steps.rb', 'features/step_definitions/email_steps.rb'
8
+ end
9
+ end
10
+
11
+ protected
12
+
13
+ def banner
14
+ "Usage: #{$0} email_spec"
15
+ end
16
+
17
+ end
@@ -0,0 +1,74 @@
1
+ #Commonly used email steps
2
+ #
3
+ # To add your own steps make a custom_email_steps.rb
4
+ # The provided methods are:
5
+ #
6
+ # reset_mailer
7
+ # open_last_email
8
+ # visit_in_email
9
+ # unread_emails_for
10
+ # mailbox_for
11
+ # current_email
12
+ # open_email
13
+ # read_emails_for
14
+ # find_email
15
+
16
+ module EmailHelpers
17
+ def current_email_address
18
+ "quentin@example.com" # Replace with your a way to find your current_email. e.g current_user.email
19
+ end
20
+ end
21
+ World(EmailHelpers)
22
+
23
+ # Use this step to reset the e-mail queue within a scenario.
24
+ # This is done automatically before each scenario.
25
+ Given /^(?:a clear email queue|no emails have been sent)$/ do
26
+ reset_mailer
27
+ end
28
+
29
+ # Use this step to open the most recently sent e-mail.
30
+ When /^I open the email$/ do
31
+ open_email(current_email_address)
32
+ end
33
+
34
+ When %r{^I follow "([^"]*?)" in the email$} do |link|
35
+ visit_in_email(link)
36
+ end
37
+
38
+ Then /^I should receive (an|\d+) emails?$/ do |amount|
39
+ amount = 1 if amount == "an"
40
+ unread_emails_for(current_email_address).size.should == amount.to_i
41
+ end
42
+
43
+ Then %r{^"([^"]*?)" should receive (\d+) emails?$} do |address, n|
44
+ unread_emails_for(address).size.should == n.to_i
45
+ end
46
+
47
+ Then %r{^"([^"]*?)" should have (\d+) emails?$} do |address, n|
48
+ mailbox_for(address).size.should == n.to_i
49
+ end
50
+
51
+ Then %r{^"([^"]*?)" should not receive an email$} do |address|
52
+ find_email(address).should be_nil
53
+ end
54
+
55
+ Then %r{^I should see "([^"]*?)" in the subject$} do |text|
56
+ current_email.should have_subject(Regexp.new(text))
57
+ end
58
+
59
+ Then %r{^I should see "([^"]*?)" in the email$} do |text|
60
+ current_email.body.should =~ Regexp.new(text)
61
+ end
62
+
63
+ When %r{^"([^"]*?)" opens? the email with subject "([^"]*?)"$} do |address, subject|
64
+ open_email(address, :with_subject => subject)
65
+ end
66
+
67
+ When %r{^"([^"]*?)" opens? the email with text "([^"]*?)"$} do |address, text|
68
+ open_email(address, :with_text => text)
69
+ end
70
+
71
+ When /^I click the first link in the email$/ do
72
+ click_first_link_in_email
73
+ end
74
+
@@ -0,0 +1,159 @@
1
+
2
+ require File.dirname(__FILE__) + '/../spec_helper'
3
+
4
+
5
+
6
+ describe EmailSpec::Matchers do
7
+
8
+
9
+ class MatcherMatch
10
+
11
+ def initialize(object_to_test_match)
12
+ @object_to_test_match = object_to_test_match
13
+ end
14
+
15
+ def description
16
+ "match when provided #{@object_to_test_match.inspect}"
17
+ end
18
+
19
+ def matches?(matcher)
20
+ @matcher = matcher
21
+ matcher.matches?(@object_to_test_match)
22
+ end
23
+
24
+ def failure_message
25
+ "expected #{@matcher.inspect} to match when provided #{@object_to_test_match.inspect}, but it did not"
26
+ end
27
+
28
+ def negative_failure_message
29
+ "expected #{@matcher.inspect} not to match when provided #{@object_to_test_match.inspect}, but it did"
30
+ end
31
+ end
32
+
33
+ def match(object_to_test_match)
34
+ if object_to_test_match.is_a?(Regexp)
35
+ super # delegate to rspec's built in 'match' matcher
36
+ else
37
+ MatcherMatch.new(object_to_test_match)
38
+ end
39
+ end
40
+
41
+ include EmailSpec::Matchers
42
+
43
+ def mock_email(stubs)
44
+ mock("email", stubs)
45
+ end
46
+
47
+ describe "#deliver_to" do
48
+
49
+ it "should match when the email is set to deliver to the specidied address" do
50
+ email = mock_email(:to => "jimmy_bean@yahoo.com")
51
+
52
+ deliver_to("jimmy_bean@yahoo.com").should match(email)
53
+ end
54
+
55
+ it "should match when a list of emails is exact same as all of the email's recipients" do
56
+ email = mock_email(:to => ["james@yahoo.com", "karen@yahoo.com"])
57
+
58
+ deliver_to("karen@yahoo.com", "james@yahoo.com").should match(email)
59
+ deliver_to("karen@yahoo.com").should_not match(email)
60
+ end
61
+
62
+ it "should match when an array of emails is exact same as all of the email's recipients" do
63
+ addresses = ["james@yahoo.com", "karen@yahoo.com"]
64
+ email = mock_email(:to => addresses)
65
+ deliver_to(addresses).should match(email)
66
+ end
67
+
68
+ it "should use the passed in objects :email method if not a string" do
69
+ email = mock_email(:to => "jimmy_bean@yahoo.com")
70
+ user = mock("user", :email => "jimmy_bean@yahoo.com")
71
+
72
+ deliver_to(user).should match(email)
73
+ end
74
+
75
+ end
76
+
77
+ describe "#have_subject" do
78
+
79
+ describe "when regexps are used" do
80
+
81
+ it "should match when the subject mathches regexp" do
82
+ email = mock_email(:subject => ' -- The Subject --')
83
+
84
+ have_subject(/The Subject/).should match(email)
85
+ have_subject(/The Subject/).should match(email)
86
+ have_subject(/foo/).should_not match(email)
87
+ end
88
+
89
+ it "should have a helpful description" do
90
+ matcher = have_subject(/foo/)
91
+ matcher.matches?(mock_email(:subject => "bar"))
92
+
93
+ matcher.description.should == "have subject matching /foo/"
94
+ end
95
+
96
+ it "should offer helpful failing messages" do
97
+ matcher = have_subject(/foo/)
98
+ matcher.matches?(mock_email(:subject => "bar"))
99
+
100
+ matcher.failure_message.should == 'expected the subject to match /foo/, but did not. Actual subject was: "bar"'
101
+ end
102
+
103
+ it "should offer helpful negative failing messages" do
104
+ matcher = have_subject(/b/)
105
+ matcher.matches?(mock_email(:subject => "bar"))
106
+
107
+ matcher.negative_failure_message.should == 'expected the subject not to match /b/ but "bar" does match it.'
108
+ end
109
+
110
+ end
111
+
112
+ describe "when strings are used" do
113
+
114
+ it "should match when the subject equals the passed in string exactly" do
115
+ email = mock_email(:subject => 'foo')
116
+
117
+ have_subject("foo").should match(email)
118
+ have_subject(" - foo -").should_not match(email)
119
+ end
120
+
121
+ it "should have a helpful description" do
122
+ matcher = have_subject("foo")
123
+ matcher.matches?(mock_email(:subject => "bar"))
124
+
125
+ matcher.description.should == 'have subject of "foo"'
126
+ end
127
+
128
+ it "should offer helpful failing messages" do
129
+ matcher = have_subject("foo")
130
+ matcher.matches?(mock_email(:subject => "bar"))
131
+
132
+ matcher.failure_message.should == 'expected the subject to be "foo" but was "bar"'
133
+ end
134
+
135
+
136
+ it "should offer helpful negative failing messages" do
137
+ matcher = have_subject("bar")
138
+ matcher.matches?(mock_email(:subject => "bar"))
139
+
140
+ matcher.negative_failure_message.should == 'expected the subject not to be "bar" but was'
141
+ end
142
+
143
+ end
144
+
145
+
146
+ end
147
+
148
+ describe "#include_email_with_subject" do
149
+ it "should have specs!"
150
+ end
151
+
152
+ describe "#have_body_text" do
153
+ it "should have specs!"
154
+ end
155
+
156
+ describe "#have_header" do
157
+ it "should have specs!"
158
+ end
159
+ end
data/spec/spec.opts ADDED
@@ -0,0 +1,4 @@
1
+ --colour
2
+ --format s
3
+ --loadby mtime
4
+ --reverse
@@ -0,0 +1,4 @@
1
+ require 'rubygems'
2
+ require 'actionmailer'
3
+ require 'spec'
4
+ require File.expand_path(File.dirname(__FILE__) + '/../lib/email_spec.rb')
metadata ADDED
@@ -0,0 +1,176 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rainchen-email_spec
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.4
5
+ platform: ruby
6
+ authors:
7
+ - Ben Mabey
8
+ - Aaron Gibralter
9
+ - Mischa Fierer
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+
14
+ date: 2009-06-01 00:00:00 -07:00
15
+ default_executable:
16
+ dependencies: []
17
+
18
+ description: Easily test email in rspec and cucumber
19
+ email: ben@benmabey.com
20
+ executables: []
21
+
22
+ extensions: []
23
+
24
+ extra_rdoc_files:
25
+ - MIT-LICENSE.txt
26
+ - README.rdoc
27
+ files:
28
+ - History.txt
29
+ - MIT-LICENSE.txt
30
+ - README.rdoc
31
+ - Rakefile
32
+ - examples/rails_root/Rakefile
33
+ - examples/rails_root/app/controllers/application.rb
34
+ - examples/rails_root/app/controllers/welcome_controller.rb
35
+ - examples/rails_root/app/helpers/application_helper.rb
36
+ - examples/rails_root/app/helpers/welcome_helper.rb
37
+ - examples/rails_root/app/models/user.rb
38
+ - examples/rails_root/app/models/user_mailer.rb
39
+ - examples/rails_root/app/views/user_mailer/signup.erb
40
+ - examples/rails_root/app/views/welcome/confirm.html.erb
41
+ - examples/rails_root/app/views/welcome/index.html.erb
42
+ - examples/rails_root/app/views/welcome/signup.html.erb
43
+ - examples/rails_root/config/boot.rb
44
+ - examples/rails_root/config/database.yml
45
+ - examples/rails_root/config/environment.rb
46
+ - examples/rails_root/config/environments/development.rb
47
+ - examples/rails_root/config/environments/production.rb
48
+ - examples/rails_root/config/environments/test.rb
49
+ - examples/rails_root/config/initializers/inflections.rb
50
+ - examples/rails_root/config/initializers/mime_types.rb
51
+ - examples/rails_root/config/initializers/new_rails_defaults.rb
52
+ - examples/rails_root/config/routes.rb
53
+ - examples/rails_root/cucumber.yml
54
+ - examples/rails_root/db/migrate/20090125013728_create_users.rb
55
+ - examples/rails_root/db/schema.rb
56
+ - examples/rails_root/doc/README_FOR_APP
57
+ - examples/rails_root/features/errors.feature
58
+ - examples/rails_root/features/example.feature
59
+ - examples/rails_root/features/step_definitions/email_steps.rb
60
+ - examples/rails_root/features/step_definitions/user_steps.rb
61
+ - examples/rails_root/features/step_definitions/webrat_steps.rb
62
+ - examples/rails_root/features/support/env.rb
63
+ - examples/rails_root/public/404.html
64
+ - examples/rails_root/public/422.html
65
+ - examples/rails_root/public/500.html
66
+ - examples/rails_root/public/dispatch.rb
67
+ - examples/rails_root/public/favicon.ico
68
+ - examples/rails_root/public/images/rails.png
69
+ - examples/rails_root/public/javascripts/application.js
70
+ - examples/rails_root/public/javascripts/controls.js
71
+ - examples/rails_root/public/javascripts/dragdrop.js
72
+ - examples/rails_root/public/javascripts/effects.js
73
+ - examples/rails_root/public/javascripts/prototype.js
74
+ - examples/rails_root/public/robots.txt
75
+ - examples/rails_root/script/about
76
+ - examples/rails_root/script/autospec
77
+ - examples/rails_root/script/console
78
+ - examples/rails_root/script/cucumber
79
+ - examples/rails_root/script/dbconsole
80
+ - examples/rails_root/script/destroy
81
+ - examples/rails_root/script/generate
82
+ - examples/rails_root/script/performance/benchmarker
83
+ - examples/rails_root/script/performance/profiler
84
+ - examples/rails_root/script/performance/request
85
+ - examples/rails_root/script/plugin
86
+ - examples/rails_root/script/process/inspector
87
+ - examples/rails_root/script/process/reaper
88
+ - examples/rails_root/script/process/spawner
89
+ - examples/rails_root/script/runner
90
+ - examples/rails_root/script/server
91
+ - examples/rails_root/script/spec
92
+ - examples/rails_root/script/spec_server
93
+ - examples/rails_root/spec/controllers/welcome_controller_spec.rb
94
+ - examples/rails_root/spec/model_factory.rb
95
+ - examples/rails_root/spec/models/user_mailer_spec.rb
96
+ - examples/rails_root/spec/models/user_spec.rb
97
+ - examples/rails_root/spec/rcov.opts
98
+ - examples/rails_root/spec/spec.opts
99
+ - examples/rails_root/spec/spec_helper.rb
100
+ - examples/rails_root/stories/all.rb
101
+ - examples/rails_root/stories/helper.rb
102
+ - examples/rails_root/vendor/plugins/email_spec/rails_generators/email_spec/email_spec_generator.rb
103
+ - examples/rails_root/vendor/plugins/email_spec/rails_generators/email_spec/templates/email_steps.rb
104
+ - install.rb
105
+ - lib/email_spec.rb
106
+ - lib/email_spec/address_converter.rb
107
+ - lib/email_spec/cucumber.rb
108
+ - lib/email_spec/deliveries.rb
109
+ - lib/email_spec/email_viewer.rb
110
+ - lib/email_spec/helpers.rb
111
+ - lib/email_spec/matchers.rb
112
+ - rails_generators/email_spec/email_spec_generator.rb
113
+ - rails_generators/email_spec/templates/email_steps.rb
114
+ - spec/email_spec/matchers_spec.rb
115
+ - spec/spec.opts
116
+ - spec/spec_helper.rb
117
+ has_rdoc: false
118
+ homepage: http://github.com/bmabey/email-spec/
119
+ post_install_message:
120
+ rdoc_options:
121
+ - --charset=UTF-8
122
+ require_paths:
123
+ - lib
124
+ required_ruby_version: !ruby/object:Gem::Requirement
125
+ requirements:
126
+ - - ">="
127
+ - !ruby/object:Gem::Version
128
+ version: "0"
129
+ version:
130
+ required_rubygems_version: !ruby/object:Gem::Requirement
131
+ requirements:
132
+ - - ">="
133
+ - !ruby/object:Gem::Version
134
+ version: "0"
135
+ version:
136
+ requirements: []
137
+
138
+ rubyforge_project:
139
+ rubygems_version: 1.2.0
140
+ signing_key:
141
+ specification_version: 3
142
+ summary: Easily test email in rspec and cucumber
143
+ test_files:
144
+ - spec/email_spec/matchers_spec.rb
145
+ - spec/spec_helper.rb
146
+ - examples/rails_root/app/controllers/application.rb
147
+ - examples/rails_root/app/controllers/welcome_controller.rb
148
+ - examples/rails_root/app/helpers/application_helper.rb
149
+ - examples/rails_root/app/helpers/welcome_helper.rb
150
+ - examples/rails_root/app/models/user.rb
151
+ - examples/rails_root/app/models/user_mailer.rb
152
+ - examples/rails_root/config/boot.rb
153
+ - examples/rails_root/config/environment.rb
154
+ - examples/rails_root/config/environments/development.rb
155
+ - examples/rails_root/config/environments/production.rb
156
+ - examples/rails_root/config/environments/test.rb
157
+ - examples/rails_root/config/initializers/inflections.rb
158
+ - examples/rails_root/config/initializers/mime_types.rb
159
+ - examples/rails_root/config/initializers/new_rails_defaults.rb
160
+ - examples/rails_root/config/routes.rb
161
+ - examples/rails_root/db/migrate/20090125013728_create_users.rb
162
+ - examples/rails_root/db/schema.rb
163
+ - examples/rails_root/features/step_definitions/email_steps.rb
164
+ - examples/rails_root/features/step_definitions/user_steps.rb
165
+ - examples/rails_root/features/step_definitions/webrat_steps.rb
166
+ - examples/rails_root/features/support/env.rb
167
+ - examples/rails_root/public/dispatch.rb
168
+ - examples/rails_root/spec/controllers/welcome_controller_spec.rb
169
+ - examples/rails_root/spec/model_factory.rb
170
+ - examples/rails_root/spec/models/user_mailer_spec.rb
171
+ - examples/rails_root/spec/models/user_spec.rb
172
+ - examples/rails_root/spec/spec_helper.rb
173
+ - examples/rails_root/stories/all.rb
174
+ - examples/rails_root/stories/helper.rb
175
+ - examples/rails_root/vendor/plugins/email_spec/rails_generators/email_spec/email_spec_generator.rb
176
+ - examples/rails_root/vendor/plugins/email_spec/rails_generators/email_spec/templates/email_steps.rb