spreewald 4.1.2 → 4.2.2

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: a4c751f9710de7f192ae23a8184dd2f7a929c2a9381f6fd3ee11e7f84c2012e4
4
- data.tar.gz: 5f94bfcf3744f8f2f44d688129c4e490e98b987eb2c97116431c8e56a5b9714c
3
+ metadata.gz: 6e425e7e26a5116b37aefcfc41a7350d08392a96e2bfb8a1a90b43299dfad007
4
+ data.tar.gz: 313450b0319dc774bbc9de556537be45abff675075df3b6e5d8238590ca600ce
5
5
  SHA512:
6
- metadata.gz: 63d52ea274f3d44d63c460fd29adf935c77790093010b4dcfe2ddadf5a6f57a64407eeef686ad35acca5ee0ad79d2d0e6977886cad4d06ac17ba011c0b5287e7
7
- data.tar.gz: 52dea6eae2351828a62aafc3d31fba6c0e156981c530cd8f67b3f0623516cea06ffe239af78b90562304cb5158e0bc5fc4836a28d02baae26b1401bee9236cc9
6
+ metadata.gz: 1529fe5cf2bc32e637042b622487dfa43ce3d18ebfe201cf3c97dc6163334c3f70c2560d6a21703c3f141bc07fcec08c1109f84b51dd33d70492007fdf04ced9
7
+ data.tar.gz: 6b4ab76bd09f08c63a8789c88e1fe65b8888255cf7805cf9dae2b114259801fe97c2a66f3facad97dc18f2f5dee69fe1c7e338fe9594c84a871671e1958238c3
data/CHANGELOG.md CHANGED
@@ -3,6 +3,12 @@ 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
+ ## 4.2.2
7
+ - Fixes the "Show me the email" step (#171)
8
+ - Fixes the "I follow the link in the email" step. (#172, #173)
9
+ - It works for emails with and without explicit html parts
10
+ - There's a better error message if no links are found
11
+
6
12
  ## 4.1.2
7
13
  - Multiple invocations of console don't raise anymore
8
14
 
@@ -1,6 +1,8 @@
1
1
  # coding: UTF-8
2
2
 
3
3
  require 'spreewald_support/mail_finder'
4
+ require 'steps/show_me_the_mails'
5
+ require 'steps/follow_the_link'
4
6
 
5
7
  Before do
6
8
  ActionMailer::Base.deliveries.clear
@@ -73,18 +75,7 @@ end.overridable
73
75
  # Other links (such as mailto: or ftp:// links) are ignored.
74
76
  When /^I follow the (first|second|third)? ?link in the e?mail$/ do |index_in_words|
75
77
  mail = @mail || ActionMailer::Base.deliveries.last
76
- index = { nil => 0, 'first' => 0, 'second' => 1, 'third' => 2 }[index_in_words]
77
- url_pattern = %r((?:https?://[^/]+)([^"'\s]+))
78
-
79
- paths = if mail.html_part
80
- dom = Nokogiri::HTML(mail.html_part.body.to_s)
81
- (dom / 'a[href]').map { |a| a['href'].match(url_pattern) }.compact.map { |match| match[1] }
82
- else
83
- mail_body = MailFinder.email_text_body(mail).to_s
84
- mail_body.scan(url_pattern).flatten(1)
85
- end
86
-
87
- visit paths[index]
78
+ Spreewald::Steps::FollowTheLink.new(mail, index_in_words).run
88
79
  end.overridable
89
80
 
90
81
  Then /^no e?mail should have been sent$/ do
@@ -98,12 +89,7 @@ end.overridable
98
89
 
99
90
  # Print all sent emails to STDOUT (optionally only the headers).
100
91
  Then /^show me the e?mail( header)?s$/ do |only_header|
101
- if ActionMailer::Base.deliveries.empty?
102
- puts MailFinder.show_mails(ActionMailer::Base.deliveries, only_header)
103
- else
104
- puts "No emails found" if ActionMailer::Base.deliveries.empty?
105
- end
106
-
92
+ Spreewald::Steps::ShowMeTheMails.new(ActionMailer::Base.deliveries, only_header).run
107
93
  end.overridable
108
94
 
109
95
  # Print a subset of all sent emails to STDOUT
@@ -1,3 +1,3 @@
1
1
  module Spreewald
2
- VERSION = '4.1.2'
2
+ VERSION = '4.2.2'
3
3
  end
@@ -0,0 +1,63 @@
1
+ module Spreewald
2
+ module Steps
3
+ class FollowTheLink
4
+ class NoVisitableLinkFound < StandardError
5
+ def initialize(paths, index)
6
+ error_message = <<~MESSAGE
7
+ Could not follow the #{index} link in the email.
8
+ MESSAGE
9
+ if paths&.empty?
10
+ error_message << "Found no link paths in the email."
11
+ else
12
+ error_message << "Found these link paths in the email: #{paths.join(', ')}"
13
+ end
14
+ super(error_message)
15
+ end
16
+ end
17
+
18
+ URL_PATTERN = %r((?:https?://[^/]+)([^"'\s]+))
19
+
20
+ def initialize(mail, index_in_words)
21
+ @mail = mail
22
+ @index_in_words = index_in_words
23
+ end
24
+
25
+ def run
26
+ index = { nil => 0, 'first' => 0, 'second' => 1, 'third' => 2 }[@index_in_words]
27
+
28
+ paths = if @mail.html_part || body_text_html?
29
+ search_for_links_in_html
30
+ else
31
+ search_for_links_in_plaintext
32
+ end
33
+
34
+ if paths[index]
35
+ visit_path paths[index]
36
+ else
37
+ raise NoVisitableLinkFound.new(paths, @index_in_words) unless paths[index]
38
+ end
39
+ end
40
+
41
+ private
42
+
43
+ def visit_path(path)
44
+ Capybara.visit(path)
45
+ end
46
+
47
+ def body_text_html?
48
+ @mail.body.to_s.include? "<html>"
49
+ end
50
+
51
+ def search_for_links_in_html
52
+ body = @mail.html_part ? @mail.html_part.body : @mail.body
53
+ dom = Nokogiri::HTML(body.to_s)
54
+ (dom / 'a[href]').map { |a| a['href'].match(URL_PATTERN) }.compact.map { |match| match[1] }
55
+ end
56
+
57
+ def search_for_links_in_plaintext
58
+ mail_body = MailFinder.email_text_body(@mail).to_s
59
+ mail_body.scan(URL_PATTERN).flatten(1)
60
+ end
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,20 @@
1
+ require 'spreewald_support/mail_finder'
2
+
3
+ module Spreewald
4
+ module Steps
5
+ class ShowMeTheMails
6
+ def initialize(mails, only_header = false)
7
+ @mails = mails
8
+ @only_header = only_header
9
+ end
10
+
11
+ def run
12
+ if @mails.empty?
13
+ puts "No emails found"
14
+ else
15
+ puts MailFinder.show_mails(@mails, @only_header)
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,81 @@
1
+ require "steps/follow_the_link"
2
+
3
+ describe Spreewald::Steps::FollowTheLink do
4
+ it "raises helpful error message if no link is found" do
5
+ mail_without_links = Mail.new do
6
+ html_part do
7
+ body "<html><body>no link</body></html>"
8
+ end
9
+
10
+ text_part do
11
+ body "no link either"
12
+ end
13
+ end
14
+
15
+ step = ->() { Spreewald::Steps::FollowTheLink.new(mail_without_links, "first").run }
16
+ expect(step).to raise_error Spreewald::Steps::FollowTheLink::NoVisitableLinkFound
17
+ end
18
+
19
+ it "finds links in multipart html email" do
20
+ mail = Mail.new do
21
+ html_part do
22
+ body "<html><body><a href='https://www.example.com/abc'>a link</a><a href='https://www.example.com/def'>second link</a></body></html>"
23
+ end
24
+
25
+ text_part do
26
+ body "no link here"
27
+ end
28
+ end
29
+
30
+ step = Spreewald::Steps::FollowTheLink.new(mail, "first")
31
+ expect(step).to receive(:visit_path).with("/abc")
32
+ step.run
33
+ end
34
+
35
+ it "finds the second link in a multipart html email" do
36
+ mail = Mail.new do
37
+ html_part do
38
+ body "<html><body><a href='https://www.example.com/abc'>a link</a><a href='https://www.example.com/def'>second link</a></body></html>"
39
+ end
40
+
41
+ text_part do
42
+ body "no link here"
43
+ end
44
+ end
45
+
46
+ step = Spreewald::Steps::FollowTheLink.new(mail, "second")
47
+ expect(step).to receive(:visit_path).with("/def")
48
+ step.run
49
+ end
50
+
51
+ it "finds links in html email" do
52
+ mail = Mail.new do
53
+ text_part do
54
+ body "my link: https://www.example.com/abc"
55
+ end
56
+ end
57
+
58
+ step = Spreewald::Steps::FollowTheLink.new(mail, "first")
59
+ expect(step).to receive(:visit_path).with("/abc")
60
+ step.run
61
+ end
62
+
63
+ it "finds links in non multipart text emails" do
64
+ plaintext_email = Mail.new(body: 'a link: https://www.example.com/abc')
65
+ step = Spreewald::Steps::FollowTheLink.new(plaintext_email, "first")
66
+
67
+ expect(step).to receive(:visit_path).with("/abc")
68
+ step.run
69
+ end
70
+
71
+ it "finds links in non multipart html emails" do
72
+ html_mail = Mail.new(body: <<-HTML)
73
+ <html><body><a href="https://www.example.com/abc">this is a link!</a></body></html>
74
+ HTML
75
+ step = Spreewald::Steps::FollowTheLink.new(html_mail, "first")
76
+
77
+ expect(step).to receive(:visit_path).with("/abc")
78
+ step.run
79
+ end
80
+ end
81
+
@@ -0,0 +1,96 @@
1
+ require "steps/show_me_the_mails"
2
+
3
+ describe Spreewald::Steps::ShowMeTheMails do
4
+ context "without deliveries" do
5
+ it "logs 'no emails found'" do
6
+ step = Spreewald::Steps::ShowMeTheMails.new([])
7
+
8
+ expect { step.run }.to output("No emails found\n").to_stdout
9
+ end
10
+
11
+ it "logs 'no emails found' with only headers enabled" do
12
+ step = Spreewald::Steps::ShowMeTheMails.new([], true)
13
+
14
+ expect { step.run }.to output("No emails found\n").to_stdout
15
+ end
16
+ end
17
+
18
+ context "with deliveries" do
19
+ it "logs the email" do
20
+ mail = Mail.new do
21
+ html_part do
22
+ body "<html><body>html part</body></html>"
23
+ end
24
+ end
25
+
26
+ expected_output = <<~TXT
27
+ E-Mail #0
28
+ --------------------------------------------------------------------------------
29
+ From:
30
+ Subject:
31
+
32
+ html part
33
+ --------------------------------------------------------------------------------
34
+
35
+ TXT
36
+ step = Spreewald::Steps::ShowMeTheMails.new([mail])
37
+ expect { step.run }.to output(expected_output).to_stdout
38
+ end
39
+
40
+ it "logs only headers with only headers enabled" do
41
+ mail = Mail.new do
42
+ html_part do
43
+ body "<html><body>html part</body></html>"
44
+ end
45
+ end
46
+
47
+ expected_output = <<~TXT
48
+ E-Mail #0
49
+ --------------------------------------------------------------------------------
50
+ From:
51
+ Subject:
52
+ --------------------------------------------------------------------------------
53
+
54
+ TXT
55
+ step = Spreewald::Steps::ShowMeTheMails.new([mail], true)
56
+ expect { step.run }.to output(expected_output).to_stdout
57
+ end
58
+ end
59
+
60
+ context "with multiple deliveries" do
61
+ it "logs the emails" do
62
+ mail_one = Mail.new do
63
+ html_part do
64
+ body "<html><body>html part</body></html>"
65
+ end
66
+ end
67
+
68
+ mail_two = Mail.new do
69
+ html_part do
70
+ body "<html><body>html2 part</body></html>"
71
+ end
72
+ end
73
+
74
+ expected_output = <<~TXT
75
+ E-Mail #0
76
+ --------------------------------------------------------------------------------
77
+ From:
78
+ Subject:
79
+
80
+ html part
81
+ --------------------------------------------------------------------------------
82
+
83
+ E-Mail #1
84
+ --------------------------------------------------------------------------------
85
+ From:
86
+ Subject:
87
+
88
+ html2 part
89
+ --------------------------------------------------------------------------------
90
+
91
+ TXT
92
+ step = Spreewald::Steps::ShowMeTheMails.new([mail_one, mail_two])
93
+ expect { step.run }.to output(expected_output).to_stdout
94
+ end
95
+ end
96
+ end
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ../..
3
3
  specs:
4
- spreewald (4.1.2)
4
+ spreewald (4.2.2)
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 (4.1.2)
4
+ spreewald (4.2.2)
5
5
  cucumber
6
6
  cucumber_priority (>= 0.3.0)
7
7
  rspec (>= 2.13.0)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spreewald
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.1.2
4
+ version: 4.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tobias Kraze
@@ -176,10 +176,14 @@ files:
176
176
  - lib/spreewald_support/unsupported_email_header.rb
177
177
  - lib/spreewald_support/version.rb
178
178
  - lib/spreewald_support/web_steps_helpers.rb
179
+ - lib/steps/follow_the_link.rb
180
+ - lib/steps/show_me_the_mails.rb
179
181
  - spec/spec_helper.rb
180
182
  - spec/spreewald_support/comparision_spec.rb
181
183
  - spec/spreewald_support/mail_to_plaintext_converter_spec.rb
182
184
  - spec/spreewald_support/tolerance_for_selenium_sync_issues_spec.rb
185
+ - spec/steps/follow_the_link_spec.rb
186
+ - spec/steps/show_me_the_mails_spec.rb
183
187
  - spec/support/world.rb
184
188
  - spreewald.gemspec
185
189
  - support/parser.rb