email_spec 1.2.1 → 1.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +17 -1
- data/README.md +340 -0
- data/Rakefile +3 -50
- data/lib/email_spec.rb +3 -2
- data/lib/email_spec/email_viewer.rb +10 -6
- data/lib/email_spec/errors.rb +7 -0
- data/lib/email_spec/helpers.rb +5 -3
- data/lib/email_spec/matchers.rb +166 -66
- data/rails_generators/email_spec/templates/email_steps.rb +1 -1
- metadata +290 -236
- data/README.rdoc +0 -148
- data/examples/rails3_root/Gemfile +0 -17
- data/examples/rails3_root/Gemfile.lock +0 -135
- data/examples/rails3_root/README +0 -5
- data/examples/rails3_root/Rakefile +0 -11
- data/examples/rails3_root/app/controllers/application_controller.rb +0 -3
- data/examples/rails3_root/app/controllers/welcome_controller.rb +0 -16
- data/examples/rails3_root/app/helpers/application_helper.rb +0 -2
- data/examples/rails3_root/app/mailers/user_mailer.rb +0 -39
- data/examples/rails3_root/app/models/user.rb +0 -2
- data/examples/rails3_root/app/views/user_mailer/attachments.html.erb +0 -6
- data/examples/rails3_root/app/views/user_mailer/newsletter.html.erb +0 -8
- data/examples/rails3_root/app/views/user_mailer/signup.html.erb +0 -4
- data/examples/rails3_root/app/views/user_mailer/signup.text.erb +0 -4
- data/examples/rails3_root/app/views/welcome/attachments.html.erb +0 -0
- data/examples/rails3_root/app/views/welcome/confirm.html.erb +0 -1
- data/examples/rails3_root/app/views/welcome/index.html.erb +0 -8
- data/examples/rails3_root/app/views/welcome/newsletter.html.erb +0 -0
- data/examples/rails3_root/app/views/welcome/signup.html.erb +0 -1
- data/examples/rails3_root/attachments/document.pdf +0 -0
- data/examples/rails3_root/attachments/image.png +0 -0
- data/examples/rails3_root/config.ru +0 -4
- data/examples/rails3_root/config/application.rb +0 -43
- data/examples/rails3_root/config/boot.rb +0 -14
- data/examples/rails3_root/config/cucumber.yml +0 -8
- data/examples/rails3_root/config/database.yml +0 -25
- data/examples/rails3_root/config/environment.rb +0 -6
- data/examples/rails3_root/config/environments/development.rb +0 -20
- data/examples/rails3_root/config/environments/production.rb +0 -42
- data/examples/rails3_root/config/environments/test.rb +0 -30
- data/examples/rails3_root/config/initializers/backtrace_silencers.rb +0 -7
- data/examples/rails3_root/config/initializers/cookie_verification_secret.rb +0 -7
- data/examples/rails3_root/config/initializers/delayed_job.rb +0 -1
- data/examples/rails3_root/config/initializers/inflections.rb +0 -10
- data/examples/rails3_root/config/initializers/mime_types.rb +0 -5
- data/examples/rails3_root/config/initializers/notifier_job.rb +0 -1
- data/examples/rails3_root/config/initializers/rspec_generator.rb +0 -6
- data/examples/rails3_root/config/initializers/session_store.rb +0 -10
- data/examples/rails3_root/config/locales/en.yml +0 -5
- data/examples/rails3_root/config/routes.rb +0 -7
- data/examples/rails3_root/db/migrate/20090125013728_create_users.rb +0 -11
- data/examples/rails3_root/db/migrate/20090908054656_create_delayed_jobs.rb +0 -20
- data/examples/rails3_root/db/schema.rb +0 -33
- data/examples/rails3_root/db/seeds.rb +0 -7
- data/examples/rails3_root/doc/README_FOR_APP +0 -2
- data/examples/rails3_root/features/attachments.feature +0 -27
- data/examples/rails3_root/features/delayed_job.feature +0 -13
- data/examples/rails3_root/features/errors.feature +0 -40
- data/examples/rails3_root/features/example.feature +0 -93
- data/examples/rails3_root/features/step_definitions/user_steps.rb +0 -26
- data/examples/rails3_root/features/step_definitions/web_steps.rb +0 -219
- data/examples/rails3_root/features/support/env.rb +0 -58
- data/examples/rails3_root/features/support/env_ext.rb +0 -2
- data/examples/rails3_root/features/support/paths.rb +0 -33
- data/examples/rails3_root/lib/notifier_job.rb +0 -5
- data/examples/rails3_root/lib/tasks/cucumber.rake +0 -53
- data/examples/rails3_root/lib/tasks/rspec.rake +0 -69
- data/examples/rails3_root/public/404.html +0 -26
- data/examples/rails3_root/public/422.html +0 -26
- data/examples/rails3_root/public/500.html +0 -26
- data/examples/rails3_root/public/favicon.ico +0 -0
- data/examples/rails3_root/public/images/rails.png +0 -0
- data/examples/rails3_root/public/javascripts/application.js +0 -2
- data/examples/rails3_root/public/javascripts/controls.js +0 -965
- data/examples/rails3_root/public/javascripts/dragdrop.js +0 -974
- data/examples/rails3_root/public/javascripts/effects.js +0 -1123
- data/examples/rails3_root/public/javascripts/prototype.js +0 -4874
- data/examples/rails3_root/public/javascripts/rails.js +0 -109
- data/examples/rails3_root/public/robots.txt +0 -5
- data/examples/rails3_root/script/cucumber +0 -10
- data/examples/rails3_root/script/rails +0 -9
- data/examples/rails3_root/spec/controllers/welcome_controller_spec.rb +0 -20
- data/examples/rails3_root/spec/models/user_mailer_spec.rb +0 -47
- data/examples/rails3_root/spec/spec_helper.rb +0 -19
- data/examples/sinatra_root/config.ru +0 -4
- data/examples/sinatra_root/features/errors.feature +0 -40
- data/examples/sinatra_root/features/example.feature +0 -93
- data/examples/sinatra_root/features/step_definitions/user_steps.rb +0 -26
- data/examples/sinatra_root/features/step_definitions/web_steps.rb +0 -219
- data/examples/sinatra_root/features/support/env.rb +0 -21
- data/examples/sinatra_root/features/support/paths.rb +0 -29
- data/examples/sinatra_root/lib/example_sinatra_app.rb +0 -45
- data/install.rb +0 -0
- data/spec/email_spec/helpers_spec.rb +0 -220
- data/spec/email_spec/mail_ext_spec.rb +0 -34
- data/spec/email_spec/matchers_spec.rb +0 -486
- data/spec/spec_helper.rb +0 -16
data/History.txt
CHANGED
@@ -1,4 +1,20 @@
|
|
1
|
-
== 1.
|
1
|
+
== 1.4.0 2012-10-30
|
2
|
+
|
3
|
+
* removed jeweler in favor of just using bundler for all gem management.
|
4
|
+
|
5
|
+
=== New features
|
6
|
+
* MiniTest support! See README for documentation. (Mike Moore)
|
7
|
+
|
8
|
+
== 1.3.0 2011-04-07
|
9
|
+
|
10
|
+
Many thanks to Derek Hammer and George Ardeleanu who both spontaneously cleaned up various parts of the project
|
11
|
+
and helped get the release out the door. Yay opensoruce!
|
12
|
+
|
13
|
+
=== New features
|
14
|
+
* Launchy is now used to open up the email viewer. (Matt Burke)
|
15
|
+
* Email Viewer now works in Rails 3 (Woody Peterson)
|
16
|
+
* Email Viewer now works with UTF-8. (Woody Peterson)
|
17
|
+
* Documentation for email matchers. (Derek Hammer)
|
2
18
|
|
3
19
|
== 1.2.1 2011-06-20
|
4
20
|
|
data/README.md
ADDED
@@ -0,0 +1,340 @@
|
|
1
|
+
|
2
|
+
[![Build Status](https://secure.travis-ci.org/bmabey/email-spec.png)](http://travis-ci.org/bmabey/email-spec)
|
3
|
+
|
4
|
+
## Email Spec
|
5
|
+
|
6
|
+
A collection of RSpec matchers and Cucumber steps to make testing emails go smoothly.
|
7
|
+
|
8
|
+
This library works with ActionMailer and Pony. When using it with ActionMailer it works with
|
9
|
+
DelayedJob, ActiveRecord Mailer, and action_mailer_cache_delivery.
|
10
|
+
|
11
|
+
If you are testing emails in conjunction with an automated browser solution, like Selenium,
|
12
|
+
you will want to use [action_mailer_cache_delivery](http://rubygems.org/gems/action_mailer_cache_delivery) in your test environment. (This is
|
13
|
+
because your test process and server processes are distinct and therefore need an
|
14
|
+
intermediate store for the emails.) DelayedJob and ActiveRecord Mailer will also work but
|
15
|
+
you generally don't want to include those projects unless you need them in production.
|
16
|
+
|
17
|
+
## Setup
|
18
|
+
|
19
|
+
```bash
|
20
|
+
script/plugin install git://github.com/bmabey/email-spec.git
|
21
|
+
```
|
22
|
+
|
23
|
+
### Gem Setup
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
gem install email_spec
|
27
|
+
|
28
|
+
# Gemfile
|
29
|
+
group :test do
|
30
|
+
gem 'email_spec'
|
31
|
+
end
|
32
|
+
```
|
33
|
+
|
34
|
+
### Cucumber
|
35
|
+
|
36
|
+
To use the steps in features put the following in your env.rb:
|
37
|
+
|
38
|
+
```ruby
|
39
|
+
# Make sure this require is after you require cucumber/rails/world.
|
40
|
+
require 'email_spec' # add this line if you use spork
|
41
|
+
require 'email_spec/cucumber'
|
42
|
+
```
|
43
|
+
|
44
|
+
This will load all the helpers that the steps rely on.
|
45
|
+
It will also add a Before hook for Cucumber so that emails are cleared at the start of each scenario.
|
46
|
+
|
47
|
+
Then:
|
48
|
+
|
49
|
+
```bash
|
50
|
+
rails generate email_spec:steps
|
51
|
+
```
|
52
|
+
|
53
|
+
This will give you a bunch of steps to get started with in step_definitions/email_steps.rb
|
54
|
+
|
55
|
+
By default, the generated file will look for email to example@example.com. You can either change this
|
56
|
+
by editing the current_email_address method in email_steps.rb, or by simply specifying the target
|
57
|
+
email in your features:
|
58
|
+
|
59
|
+
```gherkin
|
60
|
+
Scenario: A new person signs up
|
61
|
+
Given I am at "/"
|
62
|
+
When I fill in "Email" with "quentin@example.com"
|
63
|
+
And I press "Sign up"
|
64
|
+
And "quentin@example.com" should receive an email # Specify who should receive the email
|
65
|
+
```
|
66
|
+
|
67
|
+
### RSpec
|
68
|
+
|
69
|
+
First you need to require email_spec in your spec_helper.rb:
|
70
|
+
|
71
|
+
```ruby
|
72
|
+
require "email_spec"
|
73
|
+
```
|
74
|
+
|
75
|
+
You will then need to include EmailSpec::Helpers and EmailSpec::Matchers in your example groups.
|
76
|
+
If you want to have access to the helpers and matchers in all of your examples you can do the following in your spec_helper.rb:
|
77
|
+
|
78
|
+
```ruby
|
79
|
+
RSpec.configure do |config|
|
80
|
+
config.include(EmailSpec::Helpers)
|
81
|
+
config.include(EmailSpec::Matchers)
|
82
|
+
end
|
83
|
+
```
|
84
|
+
|
85
|
+
Otherwise, you will need to include them in the example groups you wish to use them:
|
86
|
+
|
87
|
+
```ruby
|
88
|
+
describe "Signup Email" do
|
89
|
+
include EmailSpec::Helpers
|
90
|
+
include EmailSpec::Matchers
|
91
|
+
...
|
92
|
+
end
|
93
|
+
```
|
94
|
+
|
95
|
+
### MiniTest
|
96
|
+
|
97
|
+
First you need to require minitest-matchers and email_spec in your test_helper.rb:
|
98
|
+
|
99
|
+
```ruby
|
100
|
+
require "minitest-matchers"
|
101
|
+
require "email_spec"
|
102
|
+
```
|
103
|
+
|
104
|
+
You will then need to include EmailSpec::Helpers and EmailSpec::Matchers in your test classes.
|
105
|
+
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:
|
106
|
+
|
107
|
+
```ruby
|
108
|
+
class MiniTest::Unit::TestCase
|
109
|
+
include EmailSpec::Helpers
|
110
|
+
include EmailSpec::Matchers
|
111
|
+
end
|
112
|
+
```
|
113
|
+
|
114
|
+
Otherwise, you will need to include them in the tests where you use them:
|
115
|
+
|
116
|
+
```ruby
|
117
|
+
class SignupMailerTest < MiniTest::Unit::TestCase
|
118
|
+
include EmailSpec::Helpers
|
119
|
+
include EmailSpec::Matchers
|
120
|
+
...
|
121
|
+
end
|
122
|
+
```
|
123
|
+
|
124
|
+
Or, if you are using the MiniTest spec DSL, it would look like this:
|
125
|
+
|
126
|
+
```ruby
|
127
|
+
describe SignupMailer do
|
128
|
+
include EmailSpec::Helpers
|
129
|
+
include EmailSpec::Matchers
|
130
|
+
...
|
131
|
+
end
|
132
|
+
```
|
133
|
+
|
134
|
+
## Usage
|
135
|
+
|
136
|
+
### Cucumber
|
137
|
+
|
138
|
+
```gherkin
|
139
|
+
Scenario: A new person signs up
|
140
|
+
Given I am at "/"
|
141
|
+
When I fill in "Email" with "quentin@example.com"
|
142
|
+
And I press "Sign up"
|
143
|
+
And I should receive an email
|
144
|
+
When I open the email
|
145
|
+
Then I should see "confirm" in the email body
|
146
|
+
When I follow "confirm" in the email
|
147
|
+
Then I should see "Confirm your new account"
|
148
|
+
```
|
149
|
+
|
150
|
+
For more examples, check out examples/rails_root in the source for a small example app that implements these steps.
|
151
|
+
|
152
|
+
### Cucumber Matchers (Ruby)
|
153
|
+
|
154
|
+
See RSpec Matchers (they are the same)
|
155
|
+
|
156
|
+
### RSpec
|
157
|
+
|
158
|
+
#### Testing In Isolation
|
159
|
+
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:
|
160
|
+
|
161
|
+
Verify that the mailer is used correctly in the controller (this would apply to a model as well):
|
162
|
+
|
163
|
+
```ruby
|
164
|
+
describe "POST /signup (#signup)" do
|
165
|
+
it "should deliver the signup email" do
|
166
|
+
# expect
|
167
|
+
UserMailer.should_receive(:deliver_signup).with("email@example.com", "Jimmy Bean")
|
168
|
+
# when
|
169
|
+
post :signup, "Email" => "email@example.com", "Name" => "Jimmy Bean"
|
170
|
+
end
|
171
|
+
end
|
172
|
+
```
|
173
|
+
|
174
|
+
Examples for the #signup method in UserMailer:
|
175
|
+
|
176
|
+
```ruby
|
177
|
+
describe "Signup Email" do
|
178
|
+
include EmailSpec::Helpers
|
179
|
+
include EmailSpec::Matchers
|
180
|
+
# include ActionController::UrlWriter - old rails
|
181
|
+
include Rails.application.routes.url_helpers
|
182
|
+
|
183
|
+
before(:all) do
|
184
|
+
@email = UserMailer.create_signup("jojo@yahoo.com", "Jojo Binks")
|
185
|
+
end
|
186
|
+
|
187
|
+
it "should be set to be delivered to the email passed in" do
|
188
|
+
@email.should deliver_to("jojo@yahoo.com")
|
189
|
+
end
|
190
|
+
|
191
|
+
it "should contain the user's message in the mail body" do
|
192
|
+
@email.should have_body_text(/Jojo Binks/)
|
193
|
+
end
|
194
|
+
|
195
|
+
it "should contain a link to the confirmation link" do
|
196
|
+
@email.should have_body_text(/#{confirm_account_url}/)
|
197
|
+
end
|
198
|
+
|
199
|
+
it "should have the correct subject" do
|
200
|
+
@email.should have_subject(/Account confirmation/)
|
201
|
+
end
|
202
|
+
|
203
|
+
end
|
204
|
+
```
|
205
|
+
|
206
|
+
#### RSpec Matchers
|
207
|
+
|
208
|
+
##### reply_to(email)
|
209
|
+
alias: `have_reply_to`
|
210
|
+
|
211
|
+
This checks that the Reply-To header's email address (the bob@example.com of
|
212
|
+
"Bob Saget <bob@example.com>") is set to the given string.
|
213
|
+
|
214
|
+
```ruby
|
215
|
+
email = UserMailer.create_signup("jojo@yahoo.com", "Jojo Binks")
|
216
|
+
email.should reply_to("support@myapp.com")
|
217
|
+
```
|
218
|
+
|
219
|
+
|
220
|
+
##### deliver_to(*email_addresses)
|
221
|
+
alias: `be_delivered_to`
|
222
|
+
|
223
|
+
This checks that the To header's email addresses (the bob@example.com of
|
224
|
+
"Bob Saget <bob@example.com>") are set to the addresses.
|
225
|
+
|
226
|
+
```ruby
|
227
|
+
email = UserMailer.create_signup("jojo@yahoo.com", "Jojo Binks")
|
228
|
+
email.should deliver_to("jojo@yahoo.com")
|
229
|
+
```
|
230
|
+
|
231
|
+
|
232
|
+
##### deliver_from(email)
|
233
|
+
alias: `be_delivered_from`
|
234
|
+
|
235
|
+
This checks that the From header's email address (the bob@example.com of
|
236
|
+
"Bob Saget <bob@example.com>") is set to the given string.
|
237
|
+
|
238
|
+
```ruby
|
239
|
+
email = UserMailer.create_signup("jojo@yahoo.com", "Jojo Binks")
|
240
|
+
email.should deliver_from("sally@yahoo.com")
|
241
|
+
```
|
242
|
+
|
243
|
+
|
244
|
+
##### bcc_to(*email_addresses)
|
245
|
+
|
246
|
+
This checks that the BCC header's email addresses (the bob@example.com of
|
247
|
+
"Bob Saget <bob@example.com>") are set to the addresses.
|
248
|
+
|
249
|
+
```ruby
|
250
|
+
email = UserMailer.create_signup("jojo@yahoo.com", "Jojo Binks")
|
251
|
+
email.should bcc_to("sue@yahoo.com", "bill@yahoo.com")
|
252
|
+
```
|
253
|
+
|
254
|
+
|
255
|
+
##### cc_to(*email_addresses)
|
256
|
+
|
257
|
+
This checks that the CC header's email addresses (the bob@example.com of
|
258
|
+
"Bob Saget <bob@example.com>") are set to the addresses.
|
259
|
+
|
260
|
+
```ruby
|
261
|
+
email = UserMailer.create_signup("jojo@yahoo.com", "Jojo Binks")
|
262
|
+
email.should cc_to("sue@yahoo.com", "bill@yahoo.com")
|
263
|
+
```
|
264
|
+
|
265
|
+
|
266
|
+
##### have_subject(subject)
|
267
|
+
|
268
|
+
This checks that the Subject header's value is set to the given subject.
|
269
|
+
|
270
|
+
```ruby
|
271
|
+
email = UserMailer.create_signup("jojo@yahoo.com", "Jojo Binks")
|
272
|
+
email.should have_subject("Welcome!")
|
273
|
+
```
|
274
|
+
|
275
|
+
|
276
|
+
##### include_email_with_subject(subject)
|
277
|
+
Note: subject can be either a String or a Regexp
|
278
|
+
|
279
|
+
This checks that one of the given emails' subjects includes the subject.
|
280
|
+
|
281
|
+
```ruby
|
282
|
+
email = UserMailer.create_signup("jojo@yahoo.com", "Jojo Binks")
|
283
|
+
email2 = UserMailer.forgot_password("jojo@yahoo.com", "Jojo Binks")
|
284
|
+
[email, email2].should include_email_with_subject("Welcome!")
|
285
|
+
```
|
286
|
+
|
287
|
+
|
288
|
+
##### have_body_text(text)
|
289
|
+
Note: text can be either a String or a Regexp
|
290
|
+
|
291
|
+
This checks that the text of the body has the given body.
|
292
|
+
|
293
|
+
```ruby
|
294
|
+
email = UserMailer.create_signup("jojo@yahoo.com", "Jojo Binks")
|
295
|
+
email.should have_body_text(/Hi Jojo Binks,/)
|
296
|
+
```
|
297
|
+
|
298
|
+
|
299
|
+
##### have_header(key, value)
|
300
|
+
|
301
|
+
This checks that the expected key/value pair is in the headers of the email.
|
302
|
+
|
303
|
+
```ruby
|
304
|
+
email = UserMailer.create_signup("jojo@yahoo.com", "Jojo Binks")
|
305
|
+
email.should have_header("X-Campaign", "1234abc")
|
306
|
+
```
|
307
|
+
|
308
|
+
#### Using the helpers when not testing in isolation
|
309
|
+
|
310
|
+
Don't. :) Seriously, if you do just take a look at the helpers and use them as you wish.
|
311
|
+
|
312
|
+
### MiniTest
|
313
|
+
|
314
|
+
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`:
|
315
|
+
|
316
|
+
```ruby
|
317
|
+
email = UserMailer.create_signup("jojo@yahoo.com", "Jojo Binks")
|
318
|
+
email.must deliver_to("jojo@yahoo.com")
|
319
|
+
```
|
320
|
+
|
321
|
+
Or, you can use the matcher as an expectation:
|
322
|
+
|
323
|
+
```ruby
|
324
|
+
email = UserMailer.create_signup "jojo@yahoo.com", "Jojo Binks"
|
325
|
+
email.must_deliver_to "jojo@yahoo.com"
|
326
|
+
```
|
327
|
+
|
328
|
+
And of course you can use the matcher as an assertion:
|
329
|
+
|
330
|
+
```ruby
|
331
|
+
email = UserMailer.create_signup "jojo@yahoo.com", "Jojo Binks"
|
332
|
+
assert_must_deliver_to "jojo@yahoo.com", email
|
333
|
+
```
|
334
|
+
|
335
|
+
|
336
|
+
## Original Authors
|
337
|
+
|
338
|
+
Ben Mabey, Aaron Gibralter, Mischa Fierer
|
339
|
+
|
340
|
+
Please see History.txt for upcoming changsets and other contributors.
|
data/Rakefile
CHANGED
@@ -1,33 +1,6 @@
|
|
1
1
|
require 'rubygems'
|
2
|
-
require 'bundler
|
3
|
-
|
4
|
-
require 'rspec/core/rake_task'
|
5
|
-
|
6
|
-
|
7
|
-
begin
|
8
|
-
require 'jeweler'
|
9
|
-
Jeweler::Tasks.new do |s|
|
10
|
-
s.name = "email_spec"
|
11
|
-
s.platform = Gem::Platform::RUBY
|
12
|
-
s.authors = ['Ben Mabey', 'Aaron Gibralter', 'Mischa Fierer']
|
13
|
-
s.email = "ben@benmabey.com"
|
14
|
-
s.homepage = "http://github.com/bmabey/email-spec/"
|
15
|
-
s.summary = "Easily test email in rspec and cucumber"
|
16
|
-
s.bindir = "bin"
|
17
|
-
s.description = s.summary
|
18
|
-
s.require_path = "lib"
|
19
|
-
s.files = %w(History.txt install.rb MIT-LICENSE.txt README.rdoc Rakefile) + Dir["lib/**/*"] + Dir["rails_generators/**/*"]
|
20
|
-
s.test_files = Dir["spec/**/*"] + Dir["examples/**/*"]
|
21
|
-
# rdoc
|
22
|
-
s.has_rdoc = true
|
23
|
-
s.extra_rdoc_files = %w(README.rdoc MIT-LICENSE.txt)
|
24
|
-
s.rubyforge_project = 'email-spec'
|
25
|
-
s.add_runtime_dependency "mail", "~> 2.2"
|
26
|
-
s.add_runtime_dependency "rspec", "~> 2.0"
|
27
|
-
end
|
28
|
-
rescue LoadError
|
29
|
-
puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
|
30
|
-
end
|
2
|
+
require 'bundler'
|
3
|
+
Bundler::GemHelper.install_tasks
|
31
4
|
|
32
5
|
begin
|
33
6
|
require 'cucumber/rake/task'
|
@@ -39,26 +12,6 @@ rescue LoadError
|
|
39
12
|
end
|
40
13
|
|
41
14
|
require 'rspec/core/rake_task'
|
42
|
-
|
15
|
+
RSpec::Core::RakeTask.new
|
43
16
|
|
44
17
|
task :default => [:features, :spec]
|
45
|
-
|
46
|
-
desc "Cleans the project of any tmp file that should not be included in the gemspec."
|
47
|
-
task :clean do
|
48
|
-
#remove stuff from example rails apps
|
49
|
-
FileUtils.rm_rf("examples/rails_root")
|
50
|
-
FileUtils.rm_rf("examples/sinatra")
|
51
|
-
%w[ rails3 sinatra ].each do |ver|
|
52
|
-
FileUtils.rm_f("examples/#{ver}_root/features/step_definitions/email_steps.rb")
|
53
|
-
FileUtils.rm_f("examples/#{ver}_root/rerun.txt")
|
54
|
-
FileUtils.rm_rf("examples/#{ver}_root/log")
|
55
|
-
FileUtils.rm_rf("examples/#{ver}_root/vendor")
|
56
|
-
end
|
57
|
-
|
58
|
-
%w[*.sqlite3 *.log #*#].each do |pattern|
|
59
|
-
`find . -name "#{pattern}" -delete`
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
desc "Cleans the dir and builds the gem"
|
64
|
-
task :prep => [:clean, :gemspec, :build]
|
data/lib/email_spec.rb
CHANGED
@@ -5,7 +5,7 @@ end
|
|
5
5
|
|
6
6
|
$LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__))) unless $LOAD_PATH.include?(File.expand_path(File.dirname(__FILE__)))
|
7
7
|
|
8
|
-
require '
|
8
|
+
require 'mail'
|
9
9
|
require 'email_spec/background_processes'
|
10
10
|
require 'email_spec/deliveries'
|
11
11
|
require 'email_spec/address_converter'
|
@@ -13,4 +13,5 @@ require 'email_spec/email_viewer'
|
|
13
13
|
require 'email_spec/helpers'
|
14
14
|
require 'email_spec/matchers'
|
15
15
|
require 'email_spec/mail_ext'
|
16
|
-
require 'email_spec/test_observer'
|
16
|
+
require 'email_spec/test_observer'
|
17
|
+
require 'email_spec/errors'
|
@@ -17,7 +17,7 @@ module EmailSpec
|
|
17
17
|
|
18
18
|
def self.save_and_open_all_html_emails
|
19
19
|
all_emails.each_with_index do |m, index|
|
20
|
-
if m.multipart? && html_part = m.parts.detect{ |p| p.content_type
|
20
|
+
if m.multipart? && html_part = m.parts.detect{ |p| p.content_type.include?('text/html') }
|
21
21
|
filename = tmp_email_filename("-#{index}.html")
|
22
22
|
File.open(filename, "w") do |f|
|
23
23
|
f.write m.parts[1].body
|
@@ -32,8 +32,13 @@ module EmailSpec
|
|
32
32
|
|
33
33
|
File.open(filename, "w") do |f|
|
34
34
|
all_emails.each do |m|
|
35
|
-
if m.multipart? && text_part = m.parts.detect{ |p| p.content_type
|
36
|
-
m.ordered_each
|
35
|
+
if m.multipart? && text_part = m.parts.detect{ |p| p.content_type.include?('text/plain') }
|
36
|
+
if m.respond_to?(:ordered_each) # Rails 2 / TMail
|
37
|
+
m.ordered_each{|k,v| f.write "#{k}: #{v}\n" }
|
38
|
+
else # Rails 3 / Mail
|
39
|
+
f.write(text_part.header.to_s + "\n")
|
40
|
+
end
|
41
|
+
|
37
42
|
f.write text_part.body
|
38
43
|
else
|
39
44
|
f.write m.to_s
|
@@ -71,13 +76,12 @@ module EmailSpec
|
|
71
76
|
open_in_text_editor(filename)
|
72
77
|
end
|
73
78
|
|
74
|
-
# TODO: use the launchy gem for this stuff...
|
75
79
|
def self.open_in_text_editor(filename)
|
76
|
-
|
80
|
+
Launchy.open(URI.parse("file://#{File.expand_path(filename)}"), :application => :editor)
|
77
81
|
end
|
78
82
|
|
79
83
|
def self.open_in_browser(filename)
|
80
|
-
|
84
|
+
Launchy.open(URI.parse("file://#{File.expand_path(filename)}"))
|
81
85
|
end
|
82
86
|
|
83
87
|
def self.tmp_email_filename(extension = '.txt')
|