basiszwo-email_spec 0.1.3

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 (89) hide show
  1. data/History.txt +70 -0
  2. data/MIT-LICENSE.txt +19 -0
  3. data/README.rdoc +133 -0
  4. data/Rakefile +50 -0
  5. data/examples/rails_root/app/controllers/application.rb +15 -0
  6. data/examples/rails_root/app/controllers/welcome_controller.rb +9 -0
  7. data/examples/rails_root/app/helpers/application_helper.rb +3 -0
  8. data/examples/rails_root/app/helpers/welcome_helper.rb +2 -0
  9. data/examples/rails_root/app/models/user.rb +2 -0
  10. data/examples/rails_root/app/models/user_mailer.rb +12 -0
  11. data/examples/rails_root/app/views/user_mailer/signup.erb +3 -0
  12. data/examples/rails_root/app/views/welcome/confirm.html.erb +1 -0
  13. data/examples/rails_root/app/views/welcome/index.html.erb +8 -0
  14. data/examples/rails_root/app/views/welcome/signup.html.erb +1 -0
  15. data/examples/rails_root/config/boot.rb +109 -0
  16. data/examples/rails_root/config/database.yml +22 -0
  17. data/examples/rails_root/config/environment.rb +22 -0
  18. data/examples/rails_root/config/environments/development.rb +17 -0
  19. data/examples/rails_root/config/environments/production.rb +24 -0
  20. data/examples/rails_root/config/environments/test.rb +33 -0
  21. data/examples/rails_root/config/initializers/inflections.rb +10 -0
  22. data/examples/rails_root/config/initializers/mime_types.rb +5 -0
  23. data/examples/rails_root/config/initializers/new_rails_defaults.rb +17 -0
  24. data/examples/rails_root/config/routes.rb +43 -0
  25. data/examples/rails_root/cucumber.yml +1 -0
  26. data/examples/rails_root/db/migrate/20090125013728_create_users.rb +11 -0
  27. data/examples/rails_root/db/schema.rb +19 -0
  28. data/examples/rails_root/doc/README_FOR_APP +5 -0
  29. data/examples/rails_root/features/errors.feature +42 -0
  30. data/examples/rails_root/features/example.feature +59 -0
  31. data/examples/rails_root/features/step_definitions/email_steps.rb +74 -0
  32. data/examples/rails_root/features/step_definitions/user_steps.rb +23 -0
  33. data/examples/rails_root/features/step_definitions/webrat_steps.rb +104 -0
  34. data/examples/rails_root/features/support/env.rb +21 -0
  35. data/examples/rails_root/public/404.html +30 -0
  36. data/examples/rails_root/public/422.html +30 -0
  37. data/examples/rails_root/public/500.html +33 -0
  38. data/examples/rails_root/public/dispatch.rb +10 -0
  39. data/examples/rails_root/public/favicon.ico +0 -0
  40. data/examples/rails_root/public/images/rails.png +0 -0
  41. data/examples/rails_root/public/javascripts/application.js +2 -0
  42. data/examples/rails_root/public/javascripts/controls.js +963 -0
  43. data/examples/rails_root/public/javascripts/dragdrop.js +973 -0
  44. data/examples/rails_root/public/javascripts/effects.js +1128 -0
  45. data/examples/rails_root/public/javascripts/prototype.js +4320 -0
  46. data/examples/rails_root/public/robots.txt +5 -0
  47. data/examples/rails_root/script/about +4 -0
  48. data/examples/rails_root/script/autospec +5 -0
  49. data/examples/rails_root/script/console +3 -0
  50. data/examples/rails_root/script/cucumber +7 -0
  51. data/examples/rails_root/script/dbconsole +3 -0
  52. data/examples/rails_root/script/destroy +3 -0
  53. data/examples/rails_root/script/generate +3 -0
  54. data/examples/rails_root/script/performance/benchmarker +3 -0
  55. data/examples/rails_root/script/performance/profiler +3 -0
  56. data/examples/rails_root/script/performance/request +3 -0
  57. data/examples/rails_root/script/plugin +3 -0
  58. data/examples/rails_root/script/process/inspector +3 -0
  59. data/examples/rails_root/script/process/reaper +3 -0
  60. data/examples/rails_root/script/process/spawner +3 -0
  61. data/examples/rails_root/script/runner +3 -0
  62. data/examples/rails_root/script/server +3 -0
  63. data/examples/rails_root/script/spec +5 -0
  64. data/examples/rails_root/script/spec_server +125 -0
  65. data/examples/rails_root/spec/controllers/welcome_controller_spec.rb +15 -0
  66. data/examples/rails_root/spec/model_factory.rb +6 -0
  67. data/examples/rails_root/spec/models/user_mailer_spec.rb +58 -0
  68. data/examples/rails_root/spec/models/user_spec.rb +5 -0
  69. data/examples/rails_root/spec/rcov.opts +2 -0
  70. data/examples/rails_root/spec/spec.opts +4 -0
  71. data/examples/rails_root/spec/spec_helper.rb +51 -0
  72. data/examples/rails_root/stories/all.rb +4 -0
  73. data/examples/rails_root/stories/helper.rb +3 -0
  74. data/examples/rails_root/vendor/plugins/email_spec/rails_generators/email_spec/email_spec_generator.rb +17 -0
  75. data/examples/rails_root/vendor/plugins/email_spec/rails_generators/email_spec/templates/email_steps.rb +74 -0
  76. data/install.rb +0 -0
  77. data/lib/email_spec.rb +14 -0
  78. data/lib/email_spec/address_converter.rb +27 -0
  79. data/lib/email_spec/cucumber.rb +19 -0
  80. data/lib/email_spec/deliveries.rb +55 -0
  81. data/lib/email_spec/email_viewer.rb +70 -0
  82. data/lib/email_spec/helpers.rb +128 -0
  83. data/lib/email_spec/matchers.rb +143 -0
  84. data/rails_generators/email_spec/email_spec_generator.rb +17 -0
  85. data/rails_generators/email_spec/templates/email_steps.rb +74 -0
  86. data/spec/email_spec/matchers_spec.rb +159 -0
  87. data/spec/spec.opts +4 -0
  88. data/spec/spec_helper.rb +4 -0
  89. metadata +179 -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
@@ -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,179 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: basiszwo-email_spec
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.3
5
+ platform: ruby
6
+ authors:
7
+ - Stefan Botzenhart
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-06-01 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: Easily test email in Unit::Test and cucumber
17
+ email: sb@basiszwo.com
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - README.rdoc
24
+ - MIT-LICENSE.txt
25
+ files:
26
+ - History.txt
27
+ - install.rb
28
+ - MIT-LICENSE.txt
29
+ - README.rdoc
30
+ - Rakefile
31
+ - lib/email_spec
32
+ - lib/email_spec/address_converter.rb
33
+ - lib/email_spec/cucumber.rb
34
+ - lib/email_spec/deliveries.rb
35
+ - lib/email_spec/email_viewer.rb
36
+ - lib/email_spec/helpers.rb
37
+ - lib/email_spec/matchers.rb
38
+ - lib/email_spec.rb
39
+ - rails_generators/email_spec
40
+ - rails_generators/email_spec/email_spec_generator.rb
41
+ - rails_generators/email_spec/templates
42
+ - rails_generators/email_spec/templates/email_steps.rb
43
+ - spec/email_spec
44
+ - spec/email_spec/matchers_spec.rb
45
+ - spec/spec.opts
46
+ - spec/spec_helper.rb
47
+ - examples/rails_root
48
+ - examples/rails_root/app
49
+ - examples/rails_root/app/controllers
50
+ - examples/rails_root/app/controllers/application.rb
51
+ - examples/rails_root/app/controllers/welcome_controller.rb
52
+ - examples/rails_root/app/helpers
53
+ - examples/rails_root/app/helpers/application_helper.rb
54
+ - examples/rails_root/app/helpers/welcome_helper.rb
55
+ - examples/rails_root/app/models
56
+ - examples/rails_root/app/models/user.rb
57
+ - examples/rails_root/app/models/user_mailer.rb
58
+ - examples/rails_root/app/views
59
+ - examples/rails_root/app/views/user_mailer
60
+ - examples/rails_root/app/views/user_mailer/signup.erb
61
+ - examples/rails_root/app/views/welcome
62
+ - examples/rails_root/app/views/welcome/confirm.html.erb
63
+ - examples/rails_root/app/views/welcome/index.html.erb
64
+ - examples/rails_root/app/views/welcome/signup.html.erb
65
+ - examples/rails_root/config
66
+ - examples/rails_root/config/boot.rb
67
+ - examples/rails_root/config/database.yml
68
+ - examples/rails_root/config/environment.rb
69
+ - examples/rails_root/config/environments
70
+ - examples/rails_root/config/environments/development.rb
71
+ - examples/rails_root/config/environments/production.rb
72
+ - examples/rails_root/config/environments/test.rb
73
+ - examples/rails_root/config/initializers
74
+ - examples/rails_root/config/initializers/inflections.rb
75
+ - examples/rails_root/config/initializers/mime_types.rb
76
+ - examples/rails_root/config/initializers/new_rails_defaults.rb
77
+ - examples/rails_root/config/routes.rb
78
+ - examples/rails_root/cucumber.yml
79
+ - examples/rails_root/db
80
+ - examples/rails_root/db/migrate
81
+ - examples/rails_root/db/migrate/20090125013728_create_users.rb
82
+ - examples/rails_root/db/schema.rb
83
+ - examples/rails_root/doc
84
+ - examples/rails_root/doc/README_FOR_APP
85
+ - examples/rails_root/features
86
+ - examples/rails_root/features/errors.feature
87
+ - examples/rails_root/features/example.feature
88
+ - examples/rails_root/features/step_definitions
89
+ - examples/rails_root/features/step_definitions/email_steps.rb
90
+ - examples/rails_root/features/step_definitions/user_steps.rb
91
+ - examples/rails_root/features/step_definitions/webrat_steps.rb
92
+ - examples/rails_root/features/support
93
+ - examples/rails_root/features/support/env.rb
94
+ - examples/rails_root/public
95
+ - examples/rails_root/public/404.html
96
+ - examples/rails_root/public/422.html
97
+ - examples/rails_root/public/500.html
98
+ - examples/rails_root/public/dispatch.rb
99
+ - examples/rails_root/public/favicon.ico
100
+ - examples/rails_root/public/images
101
+ - examples/rails_root/public/images/rails.png
102
+ - examples/rails_root/public/javascripts
103
+ - examples/rails_root/public/javascripts/application.js
104
+ - examples/rails_root/public/javascripts/controls.js
105
+ - examples/rails_root/public/javascripts/dragdrop.js
106
+ - examples/rails_root/public/javascripts/effects.js
107
+ - examples/rails_root/public/javascripts/prototype.js
108
+ - examples/rails_root/public/robots.txt
109
+ - examples/rails_root/script
110
+ - examples/rails_root/script/about
111
+ - examples/rails_root/script/autospec
112
+ - examples/rails_root/script/console
113
+ - examples/rails_root/script/cucumber
114
+ - examples/rails_root/script/dbconsole
115
+ - examples/rails_root/script/destroy
116
+ - examples/rails_root/script/generate
117
+ - examples/rails_root/script/performance
118
+ - examples/rails_root/script/performance/benchmarker
119
+ - examples/rails_root/script/performance/profiler
120
+ - examples/rails_root/script/performance/request
121
+ - examples/rails_root/script/plugin
122
+ - examples/rails_root/script/process
123
+ - examples/rails_root/script/process/inspector
124
+ - examples/rails_root/script/process/reaper
125
+ - examples/rails_root/script/process/spawner
126
+ - examples/rails_root/script/runner
127
+ - examples/rails_root/script/server
128
+ - examples/rails_root/script/spec
129
+ - examples/rails_root/script/spec_server
130
+ - examples/rails_root/spec
131
+ - examples/rails_root/spec/controllers
132
+ - examples/rails_root/spec/controllers/welcome_controller_spec.rb
133
+ - examples/rails_root/spec/model_factory.rb
134
+ - examples/rails_root/spec/models
135
+ - examples/rails_root/spec/models/user_mailer_spec.rb
136
+ - examples/rails_root/spec/models/user_spec.rb
137
+ - examples/rails_root/spec/rcov.opts
138
+ - examples/rails_root/spec/spec.opts
139
+ - examples/rails_root/spec/spec_helper.rb
140
+ - examples/rails_root/stories
141
+ - examples/rails_root/stories/all.rb
142
+ - examples/rails_root/stories/helper.rb
143
+ - examples/rails_root/vendor
144
+ - examples/rails_root/vendor/plugins
145
+ - examples/rails_root/vendor/plugins/email_spec
146
+ - examples/rails_root/vendor/plugins/email_spec/rails_generators
147
+ - examples/rails_root/vendor/plugins/email_spec/rails_generators/email_spec
148
+ - examples/rails_root/vendor/plugins/email_spec/rails_generators/email_spec/email_spec_generator.rb
149
+ - examples/rails_root/vendor/plugins/email_spec/rails_generators/email_spec/templates
150
+ - examples/rails_root/vendor/plugins/email_spec/rails_generators/email_spec/templates/email_steps.rb
151
+ has_rdoc: true
152
+ homepage: http://github.com/basiszwo/email-spec/
153
+ post_install_message:
154
+ rdoc_options:
155
+ - --inline-source
156
+ - --charset=UTF-8
157
+ require_paths:
158
+ - lib
159
+ required_ruby_version: !ruby/object:Gem::Requirement
160
+ requirements:
161
+ - - ">="
162
+ - !ruby/object:Gem::Version
163
+ version: "0"
164
+ version:
165
+ required_rubygems_version: !ruby/object:Gem::Requirement
166
+ requirements:
167
+ - - ">="
168
+ - !ruby/object:Gem::Version
169
+ version: "0"
170
+ version:
171
+ requirements: []
172
+
173
+ rubyforge_project:
174
+ rubygems_version: 1.2.0
175
+ signing_key:
176
+ specification_version: 3
177
+ summary: Easily test email in Unit::Test and cucumber
178
+ test_files: []
179
+