spreewald 2.7.0 → 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +59 -3
- data/README.md +26 -66
- data/features/binary.feature +2 -2
- data/lib/spreewald/development_steps.rb +1 -8
- data/lib/spreewald/email_steps.rb +63 -73
- data/lib/spreewald/web_steps.rb +40 -69
- data/lib/spreewald_support/mail_finder.rb +69 -40
- data/lib/spreewald_support/version.rb +1 -1
- data/lib/spreewald_support/web_steps_helpers.rb +17 -0
- data/tests/rails-3_capybara-1/Gemfile.lock +1 -1
- data/tests/rails-3_capybara-2/Gemfile.lock +1 -1
- data/tests/rails-4_capybara-3/Gemfile.lock +1 -1
- data/tests/rails-6_capybara-3/Gemfile.lock +1 -1
- data/tests/rails-6_capybara-3/app/mailers/spreewald_mailer.rb +9 -1
- data/tests/shared/app/controllers/downloads_controller.rb +1 -1
- data/tests/shared/app/controllers/emails_controller.rb +10 -0
- data/tests/shared/app/models/mailer.rb +12 -0
- data/tests/shared/app/views/forms/checkbox_form.html.haml +3 -0
- data/tests/shared/app/views/forms/disabled_elements.html.haml +19 -0
- data/tests/shared/app/views/forms/form1.html.haml +4 -1
- data/tests/shared/app/views/forms/invalid_form.html.haml +3 -0
- data/tests/shared/app/views/mailer/email_crlf.text.erb +5 -0
- data/tests/shared/app/views/mailer/email_with_umlauts.text.erb +1 -0
- data/tests/shared/app/views/mailer/html_email_with_links.haml +2 -0
- data/tests/shared/app/views/mailer/text_email_with_links.text.erb +1 -0
- data/tests/shared/config/routes.rb +2 -0
- data/tests/shared/features/shared/email_steps.feature +91 -38
- data/tests/shared/features/shared/web_steps.feature +23 -12
- metadata +6 -4
- data/lib/spreewald/file_attachment_steps.rb +0 -22
- data/lib/spreewald/timecop_steps.rb +0 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 64749212dae1262a16bb92a588740444cf7ede78c5980fbdf15f66271a4b081d
|
4
|
+
data.tar.gz: 7384baaed65e17289ff4d4c52874e1c257b315b0e9026fac51bbea9a414f4141
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e06ba20e5252696bd8ce7aecb6f3a6f9f21eb16c3e2f7ba2cb6223bdfdfdf1cb05c34ada79e06bcd94631ea7288e802fab3f9cce98f8d59d34f7b0b9117300c3
|
7
|
+
data.tar.gz: d09e69ad26c4e76a09bfaa44989bcd870b1eb160de410be081bf0d40889e3a7ffc901e02c7e208538e8c92719752a3cb7fa396a9f7dada600c257dcbcf72fef3
|
data/CHANGELOG.md
CHANGED
@@ -3,6 +3,63 @@ All notable changes to this project will be documented in this file.
|
|
3
3
|
|
4
4
|
This project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
|
5
5
|
|
6
|
+
## 3.0.0
|
7
|
+
|
8
|
+
### Breaking changes
|
9
|
+
|
10
|
+
- The following steps have been removed:
|
11
|
+
- `/^the file "([^"]*)" was attached(?: as (?:([^"]*)\/)?([^"]*))? to the ([^"]*) above(?: at "([^"]*)")?$/` (see [#106](https://github.com/makandra/spreewald/issues/106), this functionality was moved to [CucumberFactory](https://github.com/makandra/cucumber_factory))
|
12
|
+
- `/^the "([^"]*)" field should have no error$/` (see [#134](https://github.com/makandra/spreewald/issues/134))
|
13
|
+
- `/^I should get a text response$/` (see [#135](https://github.com/makandra/spreewald/issues/135))
|
14
|
+
- `/^I wait for the page to load$/` (see [#136](https://github.com/makandra/spreewald/issues/136))
|
15
|
+
- `debugger` (was an alias for `console`)
|
16
|
+
- These email steps have been removed in favor of `(an?|no)( HTML| plain-text|) e?mail should have been sent with:` (see [#132](https://github.com/makandra/spreewald/issues/132#issuecomment-631457290)):
|
17
|
+
- `/^(an|no) e?mail should have been sent((?: |and|with|from "[^"]+"|bcc "[^"]+"|cc "[^"]+"|to "[^"]+"|the subject "[^"]+"|the body "[^"]+"|the attachments "[^"]+")+)$/`
|
18
|
+
- `/^that e?mail should( not)? have the following lines in the body$/`
|
19
|
+
- `/^that e?mail should have the following (?:|content in the )body:$/`
|
20
|
+
- The `and disabled` modifier of the step `the "..." checkbox should( not)? be checked` has been removed. Use the step without the modifier together with the step `the "..." checkbox should be disabled` to achieve the old behavior.
|
21
|
+
- The step `/^(the tag )?"([^\"]+)" should( not)? be visible$/` lost its `not` modifier (Use `Then (the tag )?"..." should be hidden` or `Then I should not see "..."`)
|
22
|
+
- The file `lib/spreewald/timecop_steps.rb` was removed (was an alias for `lib/spreewald/time_steps.rb`).
|
23
|
+
- The step `(an?|no)( HTML| plain-text|) e?mail should have been sent with:` does now require that the whole body is matched.
|
24
|
+
- All web steps interacting with forms will now find both enabled and disabled fields. We encourage you to assert the "disabled" state in a separate step when needed, Spreewald offers these steps as well.
|
25
|
+
|
26
|
+
The following steps have been adjusted:
|
27
|
+
- `I should( not)? see a field "..."`
|
28
|
+
- `the "..." field should( not)? contain "..."`
|
29
|
+
- `I should see a form with the following values:`
|
30
|
+
- `the "..." field should have the error "..."`
|
31
|
+
- `the "..." field should( not)? have an error`
|
32
|
+
- `the "..." checkbox should( not)? be checked`
|
33
|
+
- `"..." should be selected for "..."`
|
34
|
+
- `nothing should be selected for "..."`
|
35
|
+
- `"..." should( not)? be an option for "..."`
|
36
|
+
- `the "..." field should( not)? be visible`
|
37
|
+
- `the "..." select should( not)? be sorted`
|
38
|
+
|
39
|
+
### Compatible changes
|
40
|
+
- Reintroduced support for emails with CRLF line ending
|
41
|
+
|
42
|
+
## 2.99.0
|
43
|
+
- The following steps were deprecated and will be removed in the upcoming major version:
|
44
|
+
- `/^the "([^"]*)" field should have no error$/` (see [#134](https://github.com/makandra/spreewald/issues/134))
|
45
|
+
- `/^I should get a text response$/` (see [#135](https://github.com/makandra/spreewald/issues/135))
|
46
|
+
- `/^I wait for the page to load$/` (see [#136](https://github.com/makandra/spreewald/issues/136))
|
47
|
+
- The step `and disabled` modifier of the step `/^the "([^"]*)" checkbox should( not)? be checked( and disabled)?$/` has been deprecated.
|
48
|
+
|
49
|
+
## 2.9.0
|
50
|
+
- The step `an email should have been sent with:` does now support wildcards (`*` at the end of a line to ignore the rest of the line, `*` as single character in a line to ignore multiple lines). The step also has better error messages if an email could not be found.
|
51
|
+
- The step `show me the emails` got an option to display only the email headers. Additionally, a new step `show me the email( header)?s with:` has been created to only show a subset of all sent emails, with a syntax similar to `an email should have been sent with:`.
|
52
|
+
- The email steps `an email should have been sent (from ...) (to ...) (cc ...) ...`, `that email should( not)? have the following lines in the body` and `that email should have the following content in the body:` have been deprecated in favor of `an email should have been sent with:`.
|
53
|
+
|
54
|
+
## 2.8.0
|
55
|
+
- Add radio buttons to the `the "..." (field|button|checkbox|radio button) should( not)? be disabled` step.
|
56
|
+
|
57
|
+
## 2.7.2
|
58
|
+
- Fix the step `I follow the ... link in the email` if the email contains non-HTTP(S) links
|
59
|
+
|
60
|
+
## 2.7.1
|
61
|
+
- Support RFC-compliant encoding of filenames in `Content-Disposition` header (e.g. send_data), as provided by Rails 6.
|
62
|
+
|
6
63
|
## 2.7.0
|
7
64
|
- Add a step modifier to control different Capybara sessions: `... in the browser session "..."`. (see issue [#66](https://github.com/makandra/spreewald/issues/66))
|
8
65
|
|
@@ -55,7 +112,7 @@ This project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html
|
|
55
112
|
* It can now be composed with the 'within' step
|
56
113
|
* It can now truly match negative numbers
|
57
114
|
* It dropped the hidden dependency on the HTMLEntities gem
|
58
|
-
* Fix URLs to the GitHub repository of Spreewald as part of the `_path_to` and `_selector_for` error handling. (see issue [#82](https://github.com/makandra/spreewald/issues/82))
|
115
|
+
* Fix URLs to the GitHub repository of Spreewald as part of the `_path_to` and `_selector_for` error handling. (see issue [#82](https://github.com/makandra/spreewald/issues/82))
|
59
116
|
|
60
117
|
## 2.2.0
|
61
118
|
- Add a new step `I should( not)? see a link labeled "STRING"`.
|
@@ -88,7 +145,7 @@ The "it should work" step now takes an optional reason.
|
|
88
145
|
The word "within" can now be used in arguments for other steps without causing errors ([Issue #53](https://github.com/makandra/spreewald/issues/80))
|
89
146
|
|
90
147
|
## 1.12.3
|
91
|
-
Prevent wall of warnings when `Then console` is used multiple times in on test run ([issue](https://github.com/makandra/spreewald/issues/80))
|
148
|
+
Prevent wall of warnings when `Then console` is used multiple times in on test run ([issue](https://github.com/makandra/spreewald/issues/80))
|
92
149
|
|
93
150
|
## 1.12.2
|
94
151
|
Always check the current driver by its class (see [issue](https://github.com/makandra/spreewald/issues/74))
|
@@ -102,4 +159,3 @@ Always check the current driver by its class (see [issue](https://github.com/mak
|
|
102
159
|
## 1.11.6 2018-08-28
|
103
160
|
- Added CHANGELOG
|
104
161
|
- Replaced `field_labeled` with `find_field` (https://github.com/teamcapybara/capybara/blob/master/History.md#removed)
|
105
|
-
|
data/README.md
CHANGED
@@ -197,8 +197,7 @@ the step definitions.
|
|
197
197
|
* **Then console**
|
198
198
|
|
199
199
|
Pauses test execution and opens an IRB shell with current context. Does not halt the application-
|
200
|
-
under-test.
|
201
|
-
for its job)
|
200
|
+
under-test.
|
202
201
|
|
203
202
|
|
204
203
|
* **AfterStep @slow-motion**
|
@@ -216,7 +215,7 @@ the step definitions.
|
|
216
215
|
* **When I clear my e?mails**
|
217
216
|
|
218
217
|
|
219
|
-
* **Then (an
|
218
|
+
* **Then (an?|no)( HTML| plain-text|) e?mail should have been sent with:**
|
220
219
|
|
221
220
|
Example:
|
222
221
|
|
@@ -225,65 +224,45 @@ the step definitions.
|
|
225
224
|
From: max.mustermann@example.com
|
226
225
|
Reply-To: mmuster@gmail.com
|
227
226
|
To: john.doe@example.com
|
227
|
+
CC: jane.doe@example.com
|
228
|
+
BCC: johnny.doe@example.com
|
228
229
|
Subject: The subject may contain "quotes"
|
229
|
-
Attachments:
|
230
|
+
Attachments: image.jpg, attachment.pdf
|
230
231
|
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
a prefix.
|
237
|
-
|
238
|
-
|
239
|
-
* **Then (an|no) e?mail should have been sent(( |and|with|from "..."|bcc "..."|cc "..."|to "..."|the subject "..."|the body "..."|the attachments "...")+)**
|
240
|
-
|
241
|
-
Example:
|
232
|
+
This is the message body. You can use * as a wildcard to omit the rest
|
233
|
+
of a line *
|
234
|
+
Or you can omit multiple lines if the asterisk is the only
|
235
|
+
character in a single line, like this:
|
236
|
+
*
|
242
237
|
|
243
|
-
|
238
|
+
"""
|
244
239
|
|
245
|
-
You may skip
|
240
|
+
You may skip lines in the header, of course.
|
246
241
|
|
247
242
|
|
248
243
|
* **When I follow the (first|second|third)? link in the e?mail**
|
249
244
|
|
245
|
+
Please note that this step will only follow HTTP and HTTPS links.
|
246
|
+
Other links (such as mailto: or ftp:// links) are ignored.
|
247
|
+
|
250
248
|
|
251
249
|
* **Then no e?mail should have been sent**
|
252
250
|
|
253
251
|
|
254
|
-
* **Then I should see "..." in the e?mail**
|
252
|
+
* **Then I should see "..." in the( HTML| plain-text|) e?mail**
|
255
253
|
|
256
254
|
Checks that the last sent email includes some text
|
257
255
|
|
258
256
|
|
259
|
-
* **Then show me the e?
|
260
|
-
|
261
|
-
Print all sent emails to STDOUT.
|
262
|
-
|
263
|
-
|
264
|
-
* **Then that e?mail should( not)? have the following lines in the body:**
|
265
|
-
|
266
|
-
Example:
|
267
|
-
|
268
|
-
And that mail should have the following lines in the body:
|
269
|
-
"""
|
270
|
-
All of these lines
|
271
|
-
need to be present
|
272
|
-
"""
|
273
|
-
|
274
|
-
You may skip lines, of course. Note that you may also omit text at the end of each line.
|
275
|
-
|
276
|
-
|
277
|
-
* **Then that e?mail should have the following (|content in the )body:**
|
278
|
-
|
279
|
-
Checks that the text should be included anywhere in the retrieved email body
|
257
|
+
* **Then show me the e?mail( header)?s**
|
280
258
|
|
259
|
+
Print all sent emails to STDOUT (optionally only the headers).
|
281
260
|
|
282
|
-
### file_attachment_steps.rb
|
283
261
|
|
284
|
-
* **
|
262
|
+
* **Then show me the e?mail( header)?s with:**
|
285
263
|
|
286
|
-
|
264
|
+
Print a subset of all sent emails to STDOUT
|
265
|
+
This uses the same syntax as `Then an email should have been sent with:`
|
287
266
|
|
288
267
|
|
289
268
|
### session_steps.rb
|
@@ -340,8 +319,6 @@ Please note that the two approaches branch. While ActiveSupport will freeze the
|
|
340
319
|
When it is a few hours earlier
|
341
320
|
|
342
321
|
|
343
|
-
|
344
|
-
|
345
322
|
### web_steps.rb
|
346
323
|
|
347
324
|
Most of cucumber-rails' original web steps plus a few of our own.
|
@@ -569,10 +546,7 @@ deprecation notice. Decide for yourself whether you want to use them:
|
|
569
546
|
* **Then the "..." field should( not)? have an error**
|
570
547
|
|
571
548
|
|
572
|
-
* **Then the "..."
|
573
|
-
|
574
|
-
|
575
|
-
* **Then the "..." checkbox should( not)? be checked( and disabled)?**
|
549
|
+
* **Then the "..." checkbox should( not)? be checked?**
|
576
550
|
|
577
551
|
|
578
552
|
* **Then the radio button "..." should( not)? be (checked|selected)**
|
@@ -625,14 +599,12 @@ deprecation notice. Decide for yourself whether you want to use them:
|
|
625
599
|
* **When I reload the page**
|
626
600
|
|
627
601
|
|
628
|
-
* **Then (the tag )?"..." should
|
602
|
+
* **Then (the tag )?"..." should be visible**
|
629
603
|
|
630
604
|
Checks that an element is actually present and visible, also considering styles.
|
631
605
|
Within a selenium test, the browser is asked whether the element is really visible
|
632
606
|
In a non-selenium test, we only check for `.hidden`, `.invisible` or `style: display:none`
|
633
607
|
|
634
|
-
The step 'Then (the tag )?"..." should **not** be visible' is ambiguous. Please use 'Then (the tag )?"..." should be hidden' or 'Then I should not see "..."' instead. Note that the **not** option will be removed in future versions of Spreewald.
|
635
|
-
|
636
608
|
More details [here](https://makandracards.com/makandra/1049-capybara-check-that-a-page-element-is-hidden-via-css)
|
637
609
|
|
638
610
|
|
@@ -680,16 +652,11 @@ deprecation notice. Decide for yourself whether you want to use them:
|
|
680
652
|
|
681
653
|
Then "Sponsor" should link to "http://makandra.com/"
|
682
654
|
|
683
|
-
Don't forget the trailing slash. Otherwise you'll get the error
|
655
|
+
Don't forget the trailing slash. Otherwise you'll get the error
|
684
656
|
expected: /http:\/\/makandra.com(\?[^\/]*)?$/
|
685
657
|
got: "http://makandra.com/" (using =~)
|
686
658
|
|
687
659
|
|
688
|
-
* **Then I should get a text response**
|
689
|
-
|
690
|
-
Checks that the result has content type `text/plain`
|
691
|
-
|
692
|
-
|
693
660
|
* **When I follow "..." inside any "..."**
|
694
661
|
|
695
662
|
Click a link within an element matching the given selector. Will try to be clever
|
@@ -715,9 +682,9 @@ deprecation notice. Decide for yourself whether you want to use them:
|
|
715
682
|
* **When I enter "..." into the browser dialog**
|
716
683
|
|
717
684
|
|
718
|
-
* **Then the "..." (field|button|checkbox) should( not)? be disabled**
|
685
|
+
* **Then the "..." (field|button|checkbox|radio button) should( not)? be disabled**
|
719
686
|
|
720
|
-
Tests that an input, button or
|
687
|
+
Tests that an input, button, checkbox or radio button with the given label is disabled.
|
721
688
|
|
722
689
|
|
723
690
|
* **Then the "..." field should( not)? be visible**
|
@@ -725,13 +692,6 @@ deprecation notice. Decide for yourself whether you want to use them:
|
|
725
692
|
Tests that a field with the given label is visible.
|
726
693
|
|
727
694
|
|
728
|
-
* **When I wait for the page to load**
|
729
|
-
|
730
|
-
Waits for the page to finish loading and AJAX requests to finish.
|
731
|
-
|
732
|
-
More details [here](https://makandracards.com/makandra/12139-waiting-for-page-loads-and-ajax-requests-to-finish-with-capybara).
|
733
|
-
|
734
|
-
|
735
695
|
* **When I perform basic authentication as ".../..." and go to ...**
|
736
696
|
|
737
697
|
Performs HTTP basic authentication with the given credentials and visits the given path.
|
data/features/binary.feature
CHANGED
@@ -240,7 +240,7 @@ Feature: The `spreewald` binary
|
|
240
240
|
|
241
241
|
Scenario: Print version
|
242
242
|
When I run `spreewald --version`
|
243
|
-
Then the output should contain "Spreewald
|
243
|
+
Then the output should contain "Spreewald 3."
|
244
244
|
|
245
245
|
When I run `spreewald -v`
|
246
|
-
Then the output should contain "Spreewald
|
246
|
+
Then the output should contain "Spreewald 3."
|
@@ -5,15 +5,8 @@ Then /^it should work(.+?)?$/ do |message|
|
|
5
5
|
pending(message)
|
6
6
|
end.overridable
|
7
7
|
|
8
|
-
# nodoc
|
9
|
-
Then 'debugger' do
|
10
|
-
warn 'The step "Then debugger" will be removed in future versions of Spreewald. Please use "Then console" instead.'
|
11
|
-
step 'console' # Alias
|
12
|
-
end.overridable
|
13
|
-
|
14
8
|
# Pauses test execution and opens an IRB shell with current context. Does not halt the application-
|
15
|
-
# under-test.
|
16
|
-
# for its job)
|
9
|
+
# under-test.
|
17
10
|
Then 'console' do
|
18
11
|
require 'irb'
|
19
12
|
ARGV.clear # IRB takes ARGV as its own arguments
|
@@ -17,54 +17,58 @@ end.overridable
|
|
17
17
|
# From: max.mustermann@example.com
|
18
18
|
# Reply-To: mmuster@gmail.com
|
19
19
|
# To: john.doe@example.com
|
20
|
+
# CC: jane.doe@example.com
|
21
|
+
# BCC: johnny.doe@example.com
|
20
22
|
# Subject: The subject may contain "quotes"
|
21
|
-
# Attachments:
|
23
|
+
# Attachments: image.jpg, attachment.pdf
|
24
|
+
#
|
25
|
+
# This is the message body. You can use * as a wildcard to omit the rest
|
26
|
+
# of a line *
|
27
|
+
# Or you can omit multiple lines if the asterisk is the only
|
28
|
+
# character in a single line, like this:
|
29
|
+
# *
|
22
30
|
#
|
23
|
-
# Message body goes here.
|
24
31
|
# """
|
25
32
|
#
|
26
|
-
# You may skip lines in the header, of course.
|
27
|
-
|
28
|
-
# a prefix.
|
29
|
-
Then /^(an|no) e?mail should have been sent with:$/ do |mode, raw_data|
|
33
|
+
# You may skip lines in the header, of course.
|
34
|
+
Then /^(an?|no)( HTML| plain-text|) e?mail should have been sent with:$/ do |mode, type, raw_data|
|
30
35
|
patiently do
|
31
|
-
raw_data.strip
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
36
|
+
results = MailFinder.find(raw_data, type.strip)
|
37
|
+
|
38
|
+
if mode == 'no'
|
39
|
+
expect(results).to be_empty
|
40
|
+
else
|
41
|
+
if results.one?
|
42
|
+
@mail = results.mails[0]
|
43
|
+
elsif results.many?
|
44
|
+
warn <<-WARNING
|
45
|
+
#{results.size} emails were found with the following conditions.
|
46
|
+
You may want to make the description more precise or clear the emails in between.
|
47
|
+
#{raw_data}
|
48
|
+
WARNING
|
49
|
+
else
|
50
|
+
message = <<-ERROR
|
51
|
+
No matching mail was found. There were #{ActionMailer::Base.deliveries.size} mails in total.
|
52
|
+
#{results.matching_header.size} of those had matching headers.
|
53
|
+
ERROR
|
54
|
+
if results.matching_header.empty?
|
55
|
+
message << "Expected\n" + '-' * 80 + "\n"
|
56
|
+
message << raw_data.split(/\n\n/, 2)[0] # Show the expected header
|
57
|
+
message << "\n" + '-' * 80 + "\n\n"
|
58
|
+
message << MailFinder.show_mails(ActionMailer::Base.deliveries, true)
|
59
|
+
else
|
60
|
+
message << "\nTried to match #{results.body_regex.inspect} in the following mails:\n"
|
61
|
+
message << results.matching_header.map { |mail| MailFinder.email_text_body(mail, type.strip).strip.inspect }.join("\n")
|
62
|
+
message << "\n"
|
63
|
+
end
|
64
|
+
raise RSpec::Expectations::ExpectationNotMetError.new(message)
|
38
65
|
end
|
39
66
|
end
|
40
|
-
conditions[:body] = body if body
|
41
|
-
@mail = MailFinder.find(conditions)
|
42
|
-
expectation = mode == 'no' ? 'not_to' : 'to'
|
43
|
-
expect(@mail).send(expectation, be_present)
|
44
|
-
end
|
45
|
-
end.overridable
|
46
|
-
|
47
|
-
# Example:
|
48
|
-
#
|
49
|
-
# Then an email should have been sent from "max.mustermann@example.com" to "john.doe@example.com" with bcc "john.wane@example.com" and with cc "foo@bar.com" and the subject "The subject" and the body "The body" and the attachments "attachment.pdf"
|
50
|
-
#
|
51
|
-
# You may skip parts, of course.
|
52
|
-
Then /^(an|no) e?mail should have been sent((?: |and|with|from "[^"]+"|bcc "[^"]+"|cc "[^"]+"|to "[^"]+"|the subject "[^"]+"|the body "[^"]+"|the attachments "[^"]+")+)$/ do |mode, query|
|
53
|
-
patiently do
|
54
|
-
conditions = {}
|
55
|
-
conditions[:to] = $1 if query =~ /to "([^"]+)"/
|
56
|
-
conditions[:Cc] = $1 if query =~ /cc "([^"]+)"/
|
57
|
-
conditions[:bcc] = $1 if query =~ /bcc "([^"]+)"/
|
58
|
-
conditions[:from] = $1 if query =~ /from "([^"]+)"/
|
59
|
-
conditions[:subject] = $1 if query =~ /the subject "([^"]+)"/
|
60
|
-
conditions[:body] = $1 if query =~ /the body "([^"]+)"/
|
61
|
-
conditions[:attachments] = $1 if query =~ /the attachments "([^"]+)"/
|
62
|
-
@mail = MailFinder.find(conditions)
|
63
|
-
expectation = mode == 'no' ? 'not_to' : 'to'
|
64
|
-
expect(@mail).send(expectation, be_present)
|
65
67
|
end
|
66
68
|
end.overridable
|
67
69
|
|
70
|
+
# Please note that this step will only follow HTTP and HTTPS links.
|
71
|
+
# Other links (such as mailto: or ftp:// links) are ignored.
|
68
72
|
When /^I follow the (first|second|third)? ?link in the e?mail$/ do |index_in_words|
|
69
73
|
mail = @mail || ActionMailer::Base.deliveries.last
|
70
74
|
index = { nil => 0, 'first' => 0, 'second' => 1, 'third' => 2 }[index_in_words]
|
@@ -72,7 +76,7 @@ When /^I follow the (first|second|third)? ?link in the e?mail$/ do |index_in_wor
|
|
72
76
|
|
73
77
|
paths = if mail.html_part
|
74
78
|
dom = Nokogiri::HTML(mail.html_part.body.to_s)
|
75
|
-
(dom / 'a[href]').map { |a| a['href'].match(url_pattern)[1] }
|
79
|
+
(dom / 'a[href]').map { |a| a['href'].match(url_pattern) }.compact.map { |match| match[1] }
|
76
80
|
else
|
77
81
|
mail_body = MailFinder.email_text_body(mail).to_s
|
78
82
|
mail_body.scan(url_pattern).flatten(1)
|
@@ -86,45 +90,31 @@ Then /^no e?mail should have been sent$/ do
|
|
86
90
|
end.overridable
|
87
91
|
|
88
92
|
# Checks that the last sent email includes some text
|
89
|
-
Then /^I should see "([^\"]*)" in the e?mail$/ do |text|
|
90
|
-
expect(MailFinder.email_text_body(ActionMailer::Base.deliveries.last)).to include(text)
|
93
|
+
Then /^I should see "([^\"]*)" in the( HTML| plain-text|) e?mail$/ do |text, type|
|
94
|
+
expect(MailFinder.email_text_body(ActionMailer::Base.deliveries.last, type.strip)).to include(text)
|
91
95
|
end.overridable
|
92
96
|
|
93
|
-
# Print all sent emails to STDOUT.
|
94
|
-
Then /^show me the e?
|
95
|
-
ActionMailer::Base.deliveries.
|
96
|
-
puts
|
97
|
-
|
98
|
-
puts
|
99
|
-
"To: #{mail.to}",
|
100
|
-
"Subject: #{mail.subject}",
|
101
|
-
"\n" + MailFinder.email_text_body(mail)
|
102
|
-
].join("\n")
|
103
|
-
print "-" * 80
|
97
|
+
# Print all sent emails to STDOUT (optionally only the headers).
|
98
|
+
Then /^show me the e?mail( header)?s$/ do |only_header|
|
99
|
+
if ActionMailer::Base.deliveries.empty?
|
100
|
+
puts MailFinder.show_mails(ActionMailer::Base.deliveries, only_header)
|
101
|
+
else
|
102
|
+
puts "No emails found" if ActionMailer::Base.deliveries.empty?
|
104
103
|
end
|
105
|
-
end.overridable
|
106
104
|
|
107
|
-
|
108
|
-
#
|
109
|
-
# And that mail should have the following lines in the body:
|
110
|
-
# """
|
111
|
-
# All of these lines
|
112
|
-
# need to be present
|
113
|
-
# """
|
114
|
-
#
|
115
|
-
# You may skip lines, of course. Note that you may also omit text at the end of each line.
|
116
|
-
Then /^that e?mail should( not)? have the following lines in the body:$/ do |negate, body|
|
117
|
-
expectation = negate ? 'not_to' : 'to'
|
118
|
-
mail = @mail || ActionMailer::Base.deliveries.last
|
119
|
-
email_text_body = MailFinder.email_text_body(mail)
|
105
|
+
end.overridable
|
120
106
|
|
121
|
-
|
122
|
-
|
107
|
+
# Print a subset of all sent emails to STDOUT
|
108
|
+
# This uses the same syntax as `Then an email should have been sent with:`
|
109
|
+
Then /^show me the e?mail( header)?s with:$/ do |only_header, raw_data|
|
110
|
+
results = MailFinder.find(raw_data)
|
111
|
+
if results.empty?
|
112
|
+
if results.matching_header.empty?
|
113
|
+
puts "There are no emails matching the given header."
|
114
|
+
else
|
115
|
+
puts "There are no emails matching the given header and body, but #{results.matching_header.size} matching only the header."
|
116
|
+
end
|
123
117
|
end
|
124
|
-
end.overridable
|
125
118
|
|
126
|
-
|
127
|
-
Then /^that e?mail should have the following (?:|content in the )body:$/ do |body|
|
128
|
-
mail = @mail || ActionMailer::Base.deliveries.last
|
129
|
-
expect(MailFinder.email_text_body(mail)).to include(body.strip)
|
119
|
+
print MailFinder.show_mails(results.mails, only_header)
|
130
120
|
end.overridable
|