spreewald 2.8.0 → 2.99.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 59c446ad46ae093a7bb103d7e4959dbbc7e29327cbc30e5730aff221f8488e36
4
- data.tar.gz: e23e4bd833a6234e6ce2b4e6ab104f102708bab13ab54f10aad8b97df08cd39b
3
+ metadata.gz: 71f40dbc5a327e21940b95c4a4a9b1946e0c30b2090e3f46e927b81f3f44a18b
4
+ data.tar.gz: c464bee9033caa6ae2b32984058aa0e37128483a2aa299780e60297b5c81b7d4
5
5
  SHA512:
6
- metadata.gz: 8d7b6e7ddd55b75433d7c800045c09f68b7175646de8a3f9ac11a5741ee83ce39c22d8bb5a8b5d9d77b4d22df01eda5de51093de4a76cabf73ae354308b12abc
7
- data.tar.gz: bc169b566a8878be0ad26b2b1522b960b57772d80d135ffbe4a34476c673282d75b7666d9ccf14a585c229739b3d543620f578c3b59a7e6f62cf036a5df2f90c
6
+ metadata.gz: a927120e6558399206bbd0c97e08c7410f7af5e700b1756daa091e961f9407c237509496791d4dc8f58a7c3e74ab3b78a6b97bca2b1bffa1dc1824ebf999a040
7
+ data.tar.gz: 12964e9c67396df967c29d1fa3925b6e01f0d0ba747ed016d15fa1cbee2c02e8b71173f6cf57e953cec9ad0d3df7dba6caf71d253e54739e3444c1b22687c2ef
@@ -3,6 +3,30 @@ 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
+ ## 2.99.3
7
+ - Introduce wildcard for the beginning of a line. (see issue #155)
8
+ - This will allow you to check for a specific sentence inside the body
9
+
10
+ ## 2.99.2
11
+
12
+ - Fix deduplication of linebreaks for html mails in mail finder. (see issue [#153](https://github.com/makandra/spreewald/issues/153))
13
+
14
+ ## 2.99.1
15
+
16
+ - Reintroduced support for emails with CRLF line ending
17
+
18
+ ## 2.99.0
19
+ - The following steps were deprecated and will be removed in the upcoming major version:
20
+ - `/^the "([^"]*)" field should have no error$/` (see [#134](https://github.com/makandra/spreewald/issues/134))
21
+ - `/^I should get a text response$/` (see [#135](https://github.com/makandra/spreewald/issues/135))
22
+ - `/^I wait for the page to load$/` (see [#136](https://github.com/makandra/spreewald/issues/136))
23
+ - The step `and disabled` modifier of the step `/^the "([^"]*)" checkbox should( not)? be checked( and disabled)?$/` has been deprecated.
24
+
25
+ ## 2.9.0
26
+ - 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.
27
+ - 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:`.
28
+ - 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:`.
29
+
6
30
  ## 2.8.0
7
31
  - Add radio buttons to the `the "..." (field|button|checkbox|radio button) should( not)? be disabled` step.
8
32
 
@@ -64,7 +88,7 @@ This project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html
64
88
  * It can now be composed with the 'within' step
65
89
  * It can now truly match negative numbers
66
90
  * It dropped the hidden dependency on the HTMLEntities gem
67
- * 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))
91
+ * 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))
68
92
 
69
93
  ## 2.2.0
70
94
  - Add a new step `I should( not)? see a link labeled "STRING"`.
@@ -97,7 +121,7 @@ The "it should work" step now takes an optional reason.
97
121
  The word "within" can now be used in arguments for other steps without causing errors ([Issue #53](https://github.com/makandra/spreewald/issues/80))
98
122
 
99
123
  ## 1.12.3
100
- Prevent wall of warnings when `Then console` is used multiple times in on test run ([issue](https://github.com/makandra/spreewald/issues/80))
124
+ Prevent wall of warnings when `Then console` is used multiple times in on test run ([issue](https://github.com/makandra/spreewald/issues/80))
101
125
 
102
126
  ## 1.12.2
103
127
  Always check the current driver by its class (see [issue](https://github.com/makandra/spreewald/issues/74))
@@ -111,4 +135,3 @@ Always check the current driver by its class (see [issue](https://github.com/mak
111
135
  ## 1.11.6 2018-08-28
112
136
  - Added CHANGELOG
113
137
  - Replaced `field_labeled` with `find_field` (https://github.com/teamcapybara/capybara/blob/master/History.md#removed)
114
-
data/README.md CHANGED
@@ -216,7 +216,7 @@ the step definitions.
216
216
  * **When I clear my e?mails**
217
217
 
218
218
 
219
- * **Then (an|no) e?mail should have been sent with:**
219
+ * **Then (an?|no)( HTML| plain-text|) e?mail should have been sent with:**
220
220
 
221
221
  Example:
222
222
 
@@ -225,24 +225,23 @@ the step definitions.
225
225
  From: max.mustermann@example.com
226
226
  Reply-To: mmuster@gmail.com
227
227
  To: john.doe@example.com
228
+ CC: jane.doe@example.com
229
+ BCC: johnny.doe@example.com
228
230
  Subject: The subject may contain "quotes"
229
- Attachments: ...
231
+ Attachments: image.jpg, attachment.pdf
230
232
 
231
- Message body goes here.
232
- """
233
-
234
- You may skip lines in the header, of course. Note that the mail body is only checked for
235
- _inclusion_. That means you can only test a prefix of the body. The subject may also be
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:
233
+ This is the message body. You can use * as a wildcard to omit the rest
234
+ of a line *
235
+ Or you can omit multiple lines if the asterisk is the only
236
+ character in a single line, like this:
237
+ *
242
238
 
243
- 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"
239
+ """
244
240
 
245
- You may skip parts, of course.
241
+ Because of backwards-compatibility, the body currently only has to be a prefix
242
+ of the real body. However, this is deprecated and will be removed in a future
243
+ version. Use wildcards instead.
244
+ You may skip lines in the header, of course.
246
245
 
247
246
 
248
247
  * **When I follow the (first|second|third)? link in the e?mail**
@@ -254,32 +253,20 @@ the step definitions.
254
253
  * **Then no e?mail should have been sent**
255
254
 
256
255
 
257
- * **Then I should see "..." in the e?mail**
256
+ * **Then I should see "..." in the( HTML| plain-text|) e?mail**
258
257
 
259
258
  Checks that the last sent email includes some text
260
259
 
261
260
 
262
- * **Then show me the e?mails**
263
-
264
- Print all sent emails to STDOUT.
261
+ * **Then show me the e?mail( header)?s**
265
262
 
266
-
267
- * **Then that e?mail should( not)? have the following lines in the body:**
268
-
269
- Example:
270
-
271
- And that mail should have the following lines in the body:
272
- """
273
- All of these lines
274
- need to be present
275
- """
276
-
277
- You may skip lines, of course. Note that you may also omit text at the end of each line.
263
+ Print all sent emails to STDOUT (optionally only the headers).
278
264
 
279
265
 
280
- * **Then that e?mail should have the following (|content in the )body:**
266
+ * **Then show me the e?mail( header)?s with:**
281
267
 
282
- Checks that the text should be included anywhere in the retrieved email body
268
+ Print a subset of all sent emails to STDOUT
269
+ This uses the same syntax as `Then an email should have been sent with:`
283
270
 
284
271
 
285
272
  ### file_attachment_steps.rb
@@ -17,49 +17,74 @@ 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. Note that the mail body is only checked for
27
- # _inclusion_. That means you can only test a prefix of the body. The subject may also be
28
- # a prefix.
29
- Then /^(an|no) e?mail should have been sent with:$/ do |mode, raw_data|
33
+ # Because of backwards-compatibility, the body currently only has to be a prefix
34
+ # of the real body. However, this is deprecated and will be removed in a future
35
+ # version. Use wildcards instead.
36
+ # You may skip lines in the header, of course.
37
+ Then /^(an?|no)( HTML| plain-text|) e?mail should have been sent with:$/ do |mode, type, raw_data|
30
38
  patiently do
31
- raw_data.strip!
32
- header, body = raw_data.split(/\n\n/, 2) # 2: maximum number of fields
33
- conditions = {}
34
- header.split("\n").each do |row|
35
- if row.match(/^[a-z\-]+: /i)
36
- key, value = row.split(": ", 2)
37
- conditions[key.underscore.to_sym] = value
39
+ results = MailFinder.find(raw_data, type.strip)
40
+
41
+ if mode == 'no'
42
+ expect(results).to be_empty
43
+ else
44
+ if results.one?
45
+ @mail = results.mails[0]
46
+ elsif results.many?
47
+ warn <<-WARNING
48
+ #{results.size} emails were found with the following conditions.
49
+ You may want to make the description more precise or clear the emails in between.
50
+ #{raw_data}
51
+ WARNING
52
+ else
53
+ message = <<-ERROR
54
+ No matching mail was found. There were #{ActionMailer::Base.deliveries.size} mails in total.
55
+ #{results.matching_header.size} of those had matching headers.
56
+ ERROR
57
+ if results.matching_header.empty?
58
+ message << "Expected\n" + '-' * 80 + "\n"
59
+ message << raw_data.split(/\n\n/, 2)[0] # Show the expected header
60
+ message << "\n" + '-' * 80 + "\n\n"
61
+ message << MailFinder.show_mails(ActionMailer::Base.deliveries, true)
62
+ else
63
+ message << "\nTried to match #{results.body_regex.inspect} in the following mails:\n"
64
+ message << results.matching_header.map { |mail| MailFinder.email_text_body(mail, type.strip).strip.inspect }.join("\n")
65
+ message << "\n"
66
+ end
67
+ raise RSpec::Expectations::ExpectationNotMetError.new(message)
38
68
  end
39
69
  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
70
  end
45
71
  end.overridable
46
72
 
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.
73
+ # nodoc (deprecated)
52
74
  Then /^(an|no) e?mail should have been sent((?: |and|with|from "[^"]+"|bcc "[^"]+"|cc "[^"]+"|to "[^"]+"|the subject "[^"]+"|the body "[^"]+"|the attachments "[^"]+")+)$/ do |mode, query|
75
+ warn "The step `an email should have been sent (from ...) (to ...) (cc ...) ...` has been deprecated in favor of `(an?|no)( HTML| plain-text|) e?mail should have been sent with:`"
53
76
  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)
77
+ filename_method = Rails::VERSION::MAJOR < 3 ? 'original_filename' : 'filename'
78
+ @mail = ActionMailer::Base.deliveries.find do |mail|
79
+ [ query =~ /to "([^"]+)"/ && !mail.to.include?(MailFinder.resolve_email $1),
80
+ query =~ /cc "([^"]+)"/ && !mail.cc.include?(MailFinder.resolve_email $1),
81
+ query =~ /bcc "([^"]+)"/ && !mail.bcc.include?(MailFinder.resolve_email $1),
82
+ query =~ /from "([^"]+)"/ && !mail.from.include?(MailFinder.resolve_email $1),
83
+ query =~ /reply_to "([^"]+)"/ && !mail.reply_to.include?(MailFinder.resolve_email $1),
84
+ query =~ /subject "([^"]+)"/ && !mail.subject.include?($1),
85
+ query =~ /the attachments "([^"]+)"/ && $1.split(/\s*,\s*/).sort != Array(mail.attachments).collect(&:"#{filename_method}").sort
86
+ ].none?
87
+ end
63
88
  expectation = mode == 'no' ? 'not_to' : 'to'
64
89
  expect(@mail).send(expectation, be_present)
65
90
  end
@@ -88,34 +113,38 @@ Then /^no e?mail should have been sent$/ do
88
113
  end.overridable
89
114
 
90
115
  # Checks that the last sent email includes some text
91
- Then /^I should see "([^\"]*)" in the e?mail$/ do |text|
92
- expect(MailFinder.email_text_body(ActionMailer::Base.deliveries.last)).to include(text)
116
+ Then /^I should see "([^\"]*)" in the( HTML| plain-text|) e?mail$/ do |text, type|
117
+ expect(MailFinder.email_text_body(ActionMailer::Base.deliveries.last, type.strip)).to include(text)
118
+ end.overridable
119
+
120
+ # Print all sent emails to STDOUT (optionally only the headers).
121
+ Then /^show me the e?mail( header)?s$/ do |only_header|
122
+ if ActionMailer::Base.deliveries.empty?
123
+ puts MailFinder.show_mails(ActionMailer::Base.deliveries, only_header)
124
+ else
125
+ puts "No emails found" if ActionMailer::Base.deliveries.empty?
126
+ end
127
+
93
128
  end.overridable
94
129
 
95
- # Print all sent emails to STDOUT.
96
- Then /^show me the e?mails$/ do
97
- ActionMailer::Base.deliveries.each_with_index do |mail, i|
98
- puts "E-Mail ##{i}"
99
- print "-" * 80
100
- puts [ "From: #{mail.from}",
101
- "To: #{mail.to}",
102
- "Subject: #{mail.subject}",
103
- "\n" + MailFinder.email_text_body(mail)
104
- ].join("\n")
105
- print "-" * 80
130
+ # Print a subset of all sent emails to STDOUT
131
+ # This uses the same syntax as `Then an email should have been sent with:`
132
+ Then /^show me the e?mail( header)?s with:$/ do |only_header, raw_data|
133
+ results = MailFinder.find(raw_data)
134
+ if results.empty?
135
+ if results.matching_header.empty?
136
+ puts "There are no emails matching the given header."
137
+ else
138
+ puts "There are no emails matching the given header and body, but #{results.matching_header.size} matching only the header."
139
+ end
106
140
  end
141
+
142
+ print MailFinder.show_mails(results.mails, only_header)
107
143
  end.overridable
108
144
 
109
- # Example:
110
- #
111
- # And that mail should have the following lines in the body:
112
- # """
113
- # All of these lines
114
- # need to be present
115
- # """
116
- #
117
- # You may skip lines, of course. Note that you may also omit text at the end of each line.
145
+ # nodoc (deprecated)
118
146
  Then /^that e?mail should( not)? have the following lines in the body:$/ do |negate, body|
147
+ warn "The step /^that e?mail should( not)? have the following lines in the body:$/ has been deprecated in favor of the updated step /^(an?|no)( HTML| plain-text|) e?mail should have been sent with:$/."
119
148
  expectation = negate ? 'not_to' : 'to'
120
149
  mail = @mail || ActionMailer::Base.deliveries.last
121
150
  email_text_body = MailFinder.email_text_body(mail)
@@ -125,8 +154,9 @@ Then /^that e?mail should( not)? have the following lines in the body:$/ do |neg
125
154
  end
126
155
  end.overridable
127
156
 
128
- # Checks that the text should be included anywhere in the retrieved email body
157
+ # nodoc (deprecated)
129
158
  Then /^that e?mail should have the following (?:|content in the )body:$/ do |body|
159
+ warn "The step /^that e?mail should have the following( content in the)? body:$/ has been deprecated in favor of the updated step /^(an?|no)( HTML| plain-text|) e?mail should have been sent with:$/."
130
160
  mail = @mail || ActionMailer::Base.deliveries.last
131
161
  expect(MailFinder.email_text_body(mail)).to include(body.strip)
132
162
  end.overridable
@@ -397,6 +397,7 @@ Then /^the "([^\"]*)" field should( not)? have an error$/ do |label, negate|
397
397
  end.overridable
398
398
 
399
399
  Then /^the "([^"]*)" field should have no error$/ do |field|
400
+ warn 'The step /^the "([^"]*)" field should have no error$/ is deprecated and scheduled for removal. Use the step /^the "([^\"]*)" field should( not)? have an error$/ instead.'
400
401
  patiently do
401
402
  element = find_field(field)
402
403
  classes = element.find(:xpath, '..')[:class].split(' ')
@@ -408,6 +409,10 @@ end.overridable
408
409
  Then /^the "([^"]*)" checkbox should( not)? be checked( and disabled)?$/ do |label, negate, disabled|
409
410
  expectation = negate ? :not_to : :to
410
411
 
412
+ if disabled
413
+ warn 'The step /^the "([^"]*)" checkbox should( not)? be checked( and disabled)?$/ will lose the `and disabled` modifier in Spreewald 3. In that version, the step will find a checkbox regardless of whether it is disabled.'
414
+ end
415
+
411
416
  patiently do
412
417
  field = if Spreewald::Comparison.compare_versions(Capybara::VERSION, :<, "2.1")
413
418
  find_field(label)
@@ -618,6 +623,7 @@ end.overridable
618
623
 
619
624
  # Checks that the result has content type `text/plain`
620
625
  Then /^I should get a text response$/ do
626
+ warn 'The step /^I should get a text response$/ is deprecated and scheduled for removal. Use `I should get a response with content-type "text/plain"` instead.'
621
627
  step 'I should get a response with content-type "text/plain"'
622
628
  end.overridable
623
629
 
@@ -709,6 +715,7 @@ end.overridable
709
715
  #
710
716
  # More details [here](https://makandracards.com/makandra/12139-waiting-for-page-loads-and-ajax-requests-to-finish-with-capybara).
711
717
  When /^I wait for the page to load$/ do
718
+ warn 'The step /^I wait for the page to load$/ is deprecated and scheduled for removal. Please see https://github.com/makandra/spreewald/issues/136'
712
719
  if javascript_capable?
713
720
  patiently do
714
721
  # when no jQuery is loaded, we assume there are no pending AJAX requests
@@ -5,22 +5,38 @@ class MailFinder
5
5
 
6
6
  attr_accessor :user_identity
7
7
 
8
- def find(conditions)
8
+ def find(raw_data, type = '')
9
+ header, body = raw_data.split(/\n\n/, 2) # 2: maximum number of fields
10
+ conditions = {}
11
+ header.split("\n").each do |row|
12
+ if row.match(/^[A-Za-z\-]+: /i)
13
+ key, value = row.split(": ", 2)
14
+ conditions[key.strip.underscore.to_sym] = value.strip
15
+ end
16
+ end
17
+
9
18
  filename_method = Rails::VERSION::MAJOR < 3 ? 'original_filename' : 'filename'
10
- ActionMailer::Base.deliveries.detect do |mail|
11
- mail_body = email_text_body(mail)
19
+ matching_header = ActionMailer::Base.deliveries.select do |mail|
12
20
  [ conditions[:to].nil? || mail.to.include?(resolve_email conditions[:to]),
13
21
  conditions[:cc].nil? || mail.cc && mail.cc.include?(resolve_email conditions[:cc]),
14
22
  conditions[:bcc].nil? || mail.bcc && mail.bcc.include?(resolve_email conditions[:bcc]),
15
23
  conditions[:from].nil? || mail.from.include?(resolve_email conditions[:from]),
16
24
  conditions[:reply_to].nil? || mail.reply_to.include?(resolve_email conditions[:reply_to]),
17
25
  conditions[:subject].nil? || mail.subject.include?(conditions[:subject]),
18
- conditions[:body].nil? || mail_body.include?(conditions[:body]),
19
26
  conditions[:attachments].nil? || conditions[:attachments].split(/\s*,\s*/).sort == Array(mail.attachments).collect(&:"#{filename_method}").sort
20
27
  ].all?
21
- end.tap do |mail|
22
- log(mail)
23
28
  end
29
+
30
+ matching_mails = if body
31
+ body_regex = expected_body_regex(body)
32
+ matching_header.select do |mail|
33
+ body_regex =~ email_text_body(mail, type).strip
34
+ end
35
+ else
36
+ matching_header
37
+ end
38
+
39
+ Results.new(matching_mails, matching_header, body_regex)
24
40
  end
25
41
 
26
42
  def resolve_email(identity)
@@ -31,46 +47,62 @@ class MailFinder
31
47
  end
32
48
  end
33
49
 
34
- def log(mail)
35
- if mail.present?
36
- File.open("log/test_mails.log", "a") do |file|
37
- file << "From: #{mail.from}\n"
38
- file << "To: #{mail.to.join(', ')}\n" if mail.to
39
- file << "Subject: #{mail.subject}\n\n"
40
- file << email_text_body(mail)
41
- file << "\n-------------------------\n\n"
42
- end
43
- end
50
+ def header_representation(mail)
51
+ header = ""
52
+ header << "From: #{mail.from}\n"
53
+ header << "Reply-To: #{mail.reply_to.join(', ')}\n" if mail.reply_to
54
+ header << "To: #{mail.to.join(', ')}\n" if mail.to
55
+ header << "CC: #{mail.cc.join(', ')}\n" if mail.cc
56
+ header << "BCC: #{mail.bcc.join(', ')}\n" if mail.bcc
57
+ header << "Subject: #{mail.subject}\n"
44
58
  end
45
59
 
46
- def email_text_body(mail)
47
- body = if mail.parts.any?
48
- mail_bodies = mail.parts.map { |part|
49
- if part.header.to_s.include?('Quoted-printable')
50
- if Rails.version.starts_with?('2.3')
51
- part.body.to_s
52
- else
53
- part.decoded
54
- end
55
- elsif part.content_type.include?('multipart/alternative')
56
- part.parts.map(&:decoded)
57
- else
58
- part.decoded
59
- end
60
- }
61
- utf8_parts = mail_bodies.flatten.select{ |part|
62
- encoding = part.try(:encoding)
63
- encoding.nil? or # Ruby < 1.9.1
64
- encoding.name == 'UTF-8' # Ruby > 1.9.1
65
- }
66
- utf8_parts.join('\n')
67
- elsif mail.body.respond_to? :raw_source
68
- mail.body.raw_source
60
+ def email_text_body(mail, type = '')
61
+ body = if mail.html_part && type != 'plain-text'
62
+ dom = Nokogiri::HTML(mail.html_part.body.to_s)
63
+ dom.at_css('body').text.gsub(/[\r\n]+/, "\n")
64
+ elsif mail.text_part && type != 'HTML'
65
+ mail.text_part.body.to_s
69
66
  else
70
- mail.body
67
+ mail.body.to_s
71
68
  end
72
69
  body.gsub("\r\n", "\n") # The mail gem (>= 2.7.1) switched from \n to \r\n line breaks (LF to CRLF) in plain text mails.
73
70
  end
74
71
 
72
+ def show_mails(mails, only_header = false)
73
+ message = ""
74
+ mails.each_with_index do |mail, i|
75
+ message << "E-Mail ##{i}\n"
76
+ message << "-" * 80 + "\n"
77
+ message << header_representation(mail)
78
+ message << "\n" + email_text_body(mail).strip + "\n" unless only_header
79
+ message << "-" * 80 + "\n\n"
80
+ end
81
+ message
82
+ end
83
+
84
+ def expected_body_regex(expected_body)
85
+ # To stay backwards-compatible, this will only check whether an email
86
+ # starts with the expected body.
87
+ expected = '\A\n' + Regexp.quote(expected_body.strip) + '\n\Z'
88
+ expected.gsub! '\n\*\n', '\n[\s\S]*\n'
89
+ expected.gsub! '\*\n', '.*\n'
90
+ expected.gsub! '\n\*', '\n.*'
91
+
92
+ expected.gsub! '\A\n', '\A'
93
+ expected.gsub! '\n\Z', '' # Change '' to '\Z' to force that the whole body matches
94
+
95
+ Regexp.new(expected)
96
+ end
97
+
98
+ end
99
+ end
100
+
101
+ class MailFinder::Results < Struct.new(:mails, :matching_header, :body_regex)
102
+ extend Forwardable
103
+ delegate [:size, :one?, :empty?] => :mails
104
+
105
+ def many?
106
+ size > 1
75
107
  end
76
108
  end
@@ -1,3 +1,3 @@
1
1
  module Spreewald
2
- VERSION = '2.8.0'
2
+ VERSION = '2.99.3'
3
3
  end
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ../..
3
3
  specs:
4
- spreewald (2.8.0)
4
+ spreewald (2.99.3)
5
5
  cucumber
6
6
  cucumber_priority (>= 0.3.0)
7
7
  rspec (>= 2.13.0)
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ../..
3
3
  specs:
4
- spreewald (2.8.0)
4
+ spreewald (2.99.3)
5
5
  cucumber
6
6
  cucumber_priority (>= 0.3.0)
7
7
  rspec (>= 2.13.0)
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ../..
3
3
  specs:
4
- spreewald (2.8.0)
4
+ spreewald (2.99.3)
5
5
  cucumber
6
6
  cucumber_priority (>= 0.3.0)
7
7
  rspec (>= 2.13.0)
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ../..
3
3
  specs:
4
- spreewald (2.8.0)
4
+ spreewald (2.99.3)
5
5
  cucumber
6
6
  cucumber_priority (>= 0.3.0)
7
7
  rspec (>= 2.13.0)
@@ -17,7 +17,15 @@ class SpreewaldMailer < ApplicationMailer
17
17
  :subject => SUBJECT
18
18
  )
19
19
  end
20
-
20
+
21
+ def email_crlf
22
+ email
23
+ end
24
+
25
+ def email_with_umlauts
26
+ email
27
+ end
28
+
21
29
  def html_email_with_links
22
30
  email
23
31
  end
@@ -26,5 +34,17 @@ class SpreewaldMailer < ApplicationMailer
26
34
  email
27
35
  end
28
36
 
37
+ def html_email_with_linebreaks
38
+ email
39
+ end
40
+
41
+ def html_email_with_specific_line
42
+ email
43
+ end
44
+
45
+ def text_email_with_specific_line
46
+ email
47
+ end
48
+
29
49
  end
30
50
 
@@ -9,6 +9,16 @@ class EmailsController < ApplicationController
9
9
  render_nothing
10
10
  end
11
11
 
12
+ def send_crlf_email
13
+ deliver :email_crlf
14
+ render_nothing
15
+ end
16
+
17
+ def send_email_with_umlauts
18
+ deliver :email_with_umlauts
19
+ render_nothing
20
+ end
21
+
12
22
  def send_html_email_with_links
13
23
  deliver :html_email_with_links
14
24
  render_nothing
@@ -19,6 +29,21 @@ class EmailsController < ApplicationController
19
29
  render_nothing
20
30
  end
21
31
 
32
+ def send_html_email_with_linebreaks
33
+ deliver :html_email_with_linebreaks
34
+ render_nothing
35
+ end
36
+
37
+ def send_html_email_with_specific_line
38
+ deliver :html_email_with_specific_line
39
+ render_nothing
40
+ end
41
+
42
+ def send_text_email_with_specific_line
43
+ deliver :text_email_with_specific_line
44
+ render_nothing
45
+ end
46
+
22
47
  private
23
48
 
24
49
  def deliver(method_name)
@@ -21,6 +21,14 @@ class Mailer < ActionMailer::Base
21
21
  )
22
22
  end
23
23
 
24
+ def email_crlf
25
+ email
26
+ end
27
+
28
+ def email_with_umlauts
29
+ email
30
+ end
31
+
24
32
  def html_email_with_links
25
33
  email
26
34
  end
@@ -29,6 +37,18 @@ class Mailer < ActionMailer::Base
29
37
  email
30
38
  end
31
39
 
40
+ def html_email_with_linebreaks
41
+ email
42
+ end
43
+
44
+ def html_email_with_specific_line
45
+ email
46
+ end
47
+
48
+ def text_email_with_specific_line
49
+ email
50
+ end
51
+
32
52
  else
33
53
 
34
54
  def email
@@ -42,6 +62,10 @@ class Mailer < ActionMailer::Base
42
62
  body BODY
43
63
  end
44
64
 
65
+ def email_crlf
66
+ email
67
+ end
68
+
45
69
  def html_email_with_links
46
70
  email
47
71
  end
@@ -50,6 +74,14 @@ class Mailer < ActionMailer::Base
50
74
  email
51
75
  end
52
76
 
77
+ def html_email_with_specific_line
78
+ email
79
+ end
80
+
81
+ def text_email_with_specific_line
82
+ email
83
+ end
84
+
53
85
  end
54
86
 
55
87
  end
@@ -0,0 +1,5 @@
1
+ Body
2
+ with
3
+ CRLF
4
+ line
5
+ breaks
@@ -0,0 +1,6 @@
1
+ <p>
2
+ Hello!
3
+ </p>
4
+ <p>
5
+ Bye!
6
+ </p>
@@ -0,0 +1,11 @@
1
+ !!!
2
+ %html(lang="en" xmlns="http://www.w3.org/1999/xhtml")
3
+ %body
4
+ %p
5
+ Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.
6
+
7
+ %p
8
+ Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi. VERY IMPORTANT SENTENCE. Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.
9
+
10
+ %p
11
+ Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi.
@@ -0,0 +1,5 @@
1
+ Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.
2
+
3
+ Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi. VERY IMPORTANT SENTENCE. Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.
4
+
5
+ Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi.
@@ -6,8 +6,13 @@ Rails.application.routes.draw do
6
6
 
7
7
  get '/emails/do_nothing', to: 'emails#do_nothing'
8
8
  get '/emails/send_email', to: 'emails#send_email'
9
+ get '/emails/send_crlf_email', to: 'emails#send_crlf_email'
10
+ get '/emails/send_email_with_umlauts', to: 'emails#send_email_with_umlauts'
9
11
  get '/emails/send_html_email_with_links', to: 'emails#send_html_email_with_links'
10
12
  get '/emails/send_text_email_with_links', to: 'emails#send_text_email_with_links'
13
+ get '/emails/send_html_email_with_linebreaks', to: 'emails#send_html_email_with_linebreaks'
14
+ get '/emails/send_html_email_with_specific_line', to: 'emails#send_html_email_with_specific_line'
15
+ get '/emails/send_text_email_with_specific_line', to: 'emails#send_text_email_with_specific_line'
11
16
 
12
17
  get '/forms/checkbox_form', to: 'forms#checkbox_form'
13
18
  get '/forms/disabled_elements', to: 'forms#disabled_elements'
@@ -1,10 +1,10 @@
1
1
  Feature: Test Spreewald's email steps
2
-
2
+
3
3
  Scenario: /^no e?mail should have been sent$/
4
4
  When I go to "/emails/do_nothing"
5
5
  Then the following step should succeed:
6
6
  | no email should have been sent |
7
-
7
+
8
8
  When I go to "/emails/send_email"
9
9
  Then the following step should fail:
10
10
  | no email should have been sent |
@@ -50,6 +50,53 @@ Feature: Test Spreewald's email steps
50
50
  '''
51
51
  """
52
52
 
53
+ # Test with end-of-line wildcards
54
+ Then the following multiline step should succeed:
55
+ """
56
+ Then an email should have been sent with:
57
+ '''
58
+ From: from@example.com
59
+ Reply-To: reply-to@example.com
60
+ To: to@example.com
61
+ Subject: SUBJECT
62
+
63
+ Bo*
64
+ wi*
65
+ li*
66
+ br*
67
+ '''
68
+ """
69
+
70
+ # Test with multiple-line wildcards
71
+ Then the following multiline step should succeed:
72
+ """
73
+ Then an email should have been sent with:
74
+ '''
75
+ From: from@example.com
76
+ Reply-To: reply-to@example.com
77
+ To: to@example.com
78
+ Subject: SUBJECT
79
+
80
+ Body
81
+ *
82
+ breaks
83
+ '''
84
+ """
85
+
86
+ # Test with the whole body being a multiple-line wildcard
87
+ Then the following multiline step should succeed:
88
+ """
89
+ Then an email should have been sent with:
90
+ '''
91
+ From: from@example.com
92
+ Reply-To: reply-to@example.com
93
+ To: to@example.com
94
+ Subject: SUBJECT
95
+
96
+ *
97
+ '''
98
+ """
99
+
53
100
  # Test with incorrect From header
54
101
  Then the following multiline step should fail:
55
102
  """
@@ -83,6 +130,7 @@ Feature: Test Spreewald's email steps
83
130
  breaks
84
131
  '''
85
132
  """
133
+
86
134
  # Test with incorrect To header
87
135
  Then the following multiline step should fail:
88
136
  """
@@ -148,12 +196,121 @@ Feature: Test Spreewald's email steps
148
196
  with
149
197
  line
150
198
  breaks
151
-
199
+
152
200
  MORE-BODY
153
201
  '''
154
202
  """
155
203
 
156
- Scenario: /^(an|no) e?mail should have been sent((?: |and|with|from "[^"]+"|bcc "[^"]+"|cc "[^"]+"|to "[^"]+"|the subject "[^"]+"|the body "[^"]+"|the attachments "[^"]+")+)$/
204
+ # Test body with wildcard not at the end of a line
205
+ Then the following multiline step should fail:
206
+ """
207
+ Then an email should have been sent with:
208
+ '''
209
+ From: from@example.com
210
+ Reply-To: reply-to@example.com
211
+ To: to@example.com
212
+ Subject: SUBJECT
213
+
214
+ Body
215
+ t*e
216
+ line
217
+ break
218
+ '''
219
+ """
220
+
221
+ When I clear my emails
222
+ And I go to "/emails/send_crlf_email"
223
+
224
+ Then the following multiline step should succeed:
225
+ """
226
+ Then an email should have been sent with:
227
+ '''
228
+ From: from@example.com
229
+ Reply-To: reply-to@example.com
230
+ To: to@example.com
231
+ Subject: SUBJECT
232
+
233
+ Body
234
+ with
235
+ CRLF
236
+ line
237
+ breaks
238
+ '''
239
+ """
240
+
241
+ When I clear my emails
242
+ And I go to "/emails/send_email_with_umlauts"
243
+
244
+ Then the following multiline step should succeed:
245
+ """
246
+ Then an email should have been sent with:
247
+ '''
248
+ From: from@example.com
249
+ Reply-To: reply-to@example.com
250
+ To: to@example.com
251
+ Subject: SUBJECT
252
+
253
+ Viele Grüße
254
+ '''
255
+ """
256
+
257
+ When I clear my emails
258
+ And I go to "/emails/send_html_email_with_linebreaks"
259
+
260
+ Then the following multiline step should succeed:
261
+ """
262
+ Then an email should have been sent with:
263
+ '''
264
+ From: from@example.com
265
+ Reply-To: reply-to@example.com
266
+ To: to@example.com
267
+ Subject: SUBJECT
268
+
269
+ Hello!
270
+ Bye!
271
+ '''
272
+ """
273
+
274
+ # Test body with wildcard at the begin of a line
275
+ When I clear my emails
276
+ And I go to "/emails/send_html_email_with_specific_line"
277
+
278
+ Then the following multiline step should succeed:
279
+ """
280
+ Then an email should have been sent with:
281
+ '''
282
+ From: from@example.com
283
+ Reply-To: reply-to@example.com
284
+ To: to@example.com
285
+ Subject: SUBJECT
286
+
287
+ Lorem ipsum dolor sit amet, consetetur sadipscing elitr*
288
+ *VERY IMPORTANT SENTENCE*
289
+ Ut wisi enim ad minim veniam*
290
+ '''
291
+ """
292
+
293
+ When I clear my emails
294
+ And I go to "/emails/send_text_email_with_specific_line"
295
+
296
+ Then the following multiline step should succeed:
297
+ """
298
+ Then an email should have been sent with:
299
+ '''
300
+ From: from@example.com
301
+ Reply-To: reply-to@example.com
302
+ To: to@example.com
303
+ Subject: SUBJECT
304
+
305
+ Lorem ipsum dolor sit amet, consetetur sadipscing elitr*
306
+
307
+ *VERY IMPORTANT SENTENCE*
308
+
309
+ Ut wisi enim ad minim veniam*
310
+ '''
311
+ """
312
+
313
+ Scenario: Scenario: /^(an|no) e?mail should have been sent((?: |and|with|from "[^"]+"|bcc "[^"]+"|cc "[^"]+"|to "[^"]+"|the subject "[^"]+"|the body "[^"]+"|the attachments "[^"]+")+)$/
157
314
  When I go to "/emails/send_email"
158
315
 
159
316
  # Test with correct conditions
@@ -181,7 +338,7 @@ Feature: Test Spreewald's email steps
181
338
  '''
182
339
  """
183
340
 
184
- # Test with wrong body lines
341
+ # Test with wrong body lines
185
342
  Then the following multiline step should fail:
186
343
  """
187
344
  Then that email should have the following lines in the body:
@@ -215,7 +372,6 @@ Feature: Test Spreewald's email steps
215
372
  '''
216
373
  """
217
374
 
218
-
219
375
  Scenario: /^I follow the (first|second|third)? ?link in the e?mail$/ (HTML e-mail body)
220
376
  When I go to "/emails/send_html_email_with_links"
221
377
  And I follow the first link in the email
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spreewald
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.8.0
4
+ version: 2.99.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tobias Kraze
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-09-09 00:00:00.000000000 Z
11
+ date: 2020-11-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: cucumber
@@ -348,8 +348,13 @@ files:
348
348
  - tests/shared/app/views/layouts/mailer.html.erb
349
349
  - tests/shared/app/views/layouts/mailer.text.erb
350
350
  - tests/shared/app/views/mailer/email.text.erb
351
+ - tests/shared/app/views/mailer/email_crlf.text.erb
352
+ - tests/shared/app/views/mailer/email_with_umlauts.text.erb
353
+ - tests/shared/app/views/mailer/html_email_with_linebreaks.html
351
354
  - tests/shared/app/views/mailer/html_email_with_links.haml
355
+ - tests/shared/app/views/mailer/html_email_with_specific_line.haml
352
356
  - tests/shared/app/views/mailer/text_email_with_links.text.erb
357
+ - tests/shared/app/views/mailer/text_email_with_specific_line.text.erb
353
358
  - tests/shared/app/views/spreewald_mailer
354
359
  - tests/shared/app/views/static_pages/click_on.html.haml
355
360
  - tests/shared/app/views/static_pages/home.html.haml
@@ -579,8 +584,13 @@ test_files:
579
584
  - tests/shared/app/views/layouts/mailer.html.erb
580
585
  - tests/shared/app/views/layouts/mailer.text.erb
581
586
  - tests/shared/app/views/mailer/email.text.erb
587
+ - tests/shared/app/views/mailer/email_crlf.text.erb
588
+ - tests/shared/app/views/mailer/email_with_umlauts.text.erb
589
+ - tests/shared/app/views/mailer/html_email_with_linebreaks.html
582
590
  - tests/shared/app/views/mailer/html_email_with_links.haml
591
+ - tests/shared/app/views/mailer/html_email_with_specific_line.haml
583
592
  - tests/shared/app/views/mailer/text_email_with_links.text.erb
593
+ - tests/shared/app/views/mailer/text_email_with_specific_line.text.erb
584
594
  - tests/shared/app/views/spreewald_mailer
585
595
  - tests/shared/app/views/static_pages/click_on.html.haml
586
596
  - tests/shared/app/views/static_pages/home.html.haml