spreewald 4.1.0 → 4.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (84) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/test.yml +3 -6
  3. data/.ruby-version +1 -1
  4. data/CHANGELOG.md +27 -0
  5. data/Gemfile.lock +1 -1
  6. data/{Gemfile.ruby245 → Gemfile.ruby300} +2 -0
  7. data/Gemfile.ruby300.lock +108 -0
  8. data/README.md +1 -1
  9. data/Rakefile +3 -11
  10. data/lib/spreewald/browser_tab_steps.rb +1 -1
  11. data/lib/spreewald/development_steps.rb +5 -5
  12. data/lib/spreewald/email_steps.rb +4 -18
  13. data/lib/spreewald_support/version.rb +1 -1
  14. data/lib/steps/follow_the_link.rb +63 -0
  15. data/lib/steps/show_me_the_mails.rb +20 -0
  16. data/spec/steps/follow_the_link_spec.rb +81 -0
  17. data/spec/steps/show_me_the_mails_spec.rb +96 -0
  18. data/tests/rails-6_capybara-3/.ruby-version +1 -1
  19. data/tests/rails-6_capybara-3/Gemfile +4 -2
  20. data/tests/rails-6_capybara-3/Gemfile.lock +176 -142
  21. data/tests/rails-6_capybara-3/config.ru +1 -0
  22. data/tests/rails-6_capybara-3/config/cucumber.yml +1 -1
  23. data/tests/rails-6_capybara-3/config/environments/development.rb +21 -3
  24. data/tests/rails-6_capybara-3/config/environments/test.rb +12 -1
  25. data/tests/rails-6_capybara-3/config/initializers/backtrace_silencers.rb +4 -3
  26. data/tests/rails-6_capybara-3/config/initializers/filter_parameter_logging.rb +3 -1
  27. data/tests/rails-6_capybara-3/config/initializers/new_framework_defaults_6_1.rb +67 -0
  28. data/tests/rails-6_capybara-3/config/initializers/permissions_policy.rb +11 -0
  29. data/tests/shared/features/shared/iframe_steps.feature +1 -2
  30. metadata +13 -111
  31. data/Gemfile.ruby245.lock +0 -73
  32. data/tests/rails-4_capybara-2/Gemfile +0 -24
  33. data/tests/rails-4_capybara-2/Gemfile.lock +0 -230
  34. data/tests/rails-4_capybara-2/README.rdoc +0 -28
  35. data/tests/rails-4_capybara-2/Rakefile +0 -6
  36. data/tests/rails-4_capybara-2/app +0 -1
  37. data/tests/rails-4_capybara-2/bin/bundle +0 -3
  38. data/tests/rails-4_capybara-2/bin/rails +0 -4
  39. data/tests/rails-4_capybara-2/bin/rake +0 -4
  40. data/tests/rails-4_capybara-2/bin/setup +0 -29
  41. data/tests/rails-4_capybara-2/config.ru +0 -4
  42. data/tests/rails-4_capybara-2/config/application.rb +0 -35
  43. data/tests/rails-4_capybara-2/config/boot.rb +0 -3
  44. data/tests/rails-4_capybara-2/config/cucumber.yml +0 -8
  45. data/tests/rails-4_capybara-2/config/database.yml +0 -18
  46. data/tests/rails-4_capybara-2/config/environment.rb +0 -5
  47. data/tests/rails-4_capybara-2/config/environments/development.rb +0 -28
  48. data/tests/rails-4_capybara-2/config/environments/test.rb +0 -42
  49. data/tests/rails-4_capybara-2/config/initializers/backtrace_silencers.rb +0 -7
  50. data/tests/rails-4_capybara-2/config/initializers/cookies_serializer.rb +0 -3
  51. data/tests/rails-4_capybara-2/config/initializers/filter_parameter_logging.rb +0 -4
  52. data/tests/rails-4_capybara-2/config/initializers/inflections.rb +0 -16
  53. data/tests/rails-4_capybara-2/config/initializers/mime_types.rb +0 -4
  54. data/tests/rails-4_capybara-2/config/initializers/session_store.rb +0 -3
  55. data/tests/rails-4_capybara-2/config/initializers/silence_deprecation_warnings.rb +0 -11
  56. data/tests/rails-4_capybara-2/config/initializers/to_time_preserves_timezone.rb +0 -10
  57. data/tests/rails-4_capybara-2/config/initializers/wrap_parameters.rb +0 -14
  58. data/tests/rails-4_capybara-2/config/locales/en.yml +0 -23
  59. data/tests/rails-4_capybara-2/config/routes.rb +0 -1
  60. data/tests/rails-4_capybara-2/config/secrets.yml +0 -22
  61. data/tests/rails-4_capybara-2/db +0 -1
  62. data/tests/rails-4_capybara-2/features/browser_tab_steps.feature +0 -1
  63. data/tests/rails-4_capybara-2/features/development_steps.feature +0 -1
  64. data/tests/rails-4_capybara-2/features/email_steps.feature +0 -1
  65. data/tests/rails-4_capybara-2/features/iframe_steps.feature +0 -1
  66. data/tests/rails-4_capybara-2/features/overriding.feature +0 -1
  67. data/tests/rails-4_capybara-2/features/session_steps.feature +0 -1
  68. data/tests/rails-4_capybara-2/features/step_definitions/overriding_steps.rb +0 -1
  69. data/tests/rails-4_capybara-2/features/step_definitions/test_steps.rb +0 -1
  70. data/tests/rails-4_capybara-2/features/support/env.rb +0 -66
  71. data/tests/rails-4_capybara-2/features/support/paths.rb +0 -1
  72. data/tests/rails-4_capybara-2/features/support/selectors.rb +0 -1
  73. data/tests/rails-4_capybara-2/features/support/selenium.rb +0 -1
  74. data/tests/rails-4_capybara-2/features/table_steps.feature +0 -1
  75. data/tests/rails-4_capybara-2/features/time_steps.feature +0 -1
  76. data/tests/rails-4_capybara-2/features/web_steps.feature +0 -1
  77. data/tests/rails-4_capybara-2/lib/tasks/cucumber.rake +0 -65
  78. data/tests/rails-4_capybara-2/log/.keep +0 -0
  79. data/tests/rails-4_capybara-2/public/404.html +0 -67
  80. data/tests/rails-4_capybara-2/public/422.html +0 -67
  81. data/tests/rails-4_capybara-2/public/500.html +0 -66
  82. data/tests/rails-4_capybara-2/public/favicon.ico +0 -0
  83. data/tests/rails-4_capybara-2/public/fixture_files +0 -1
  84. data/tests/rails-4_capybara-2/script/cucumber +0 -10
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6b97388391eda8359eab973a0a92896ee7d10e7fc4db749b7f22fb326eddf268
4
- data.tar.gz: 77aea5e617594133107957b887d5f4848a91532fc46b835b1b5af07164f652e2
3
+ metadata.gz: 9d3a85d0ee7a8a0ebd403ef168a1788a21ce14dd3b3966aa431b1d0481f25e05
4
+ data.tar.gz: f68eb3cecf0e1792fada9ec58a664f6d8652fb700ebd07cee9a9789c260690a4
5
5
  SHA512:
6
- metadata.gz: 43272a84d5e31da1f22426ef84908591696765e4ca394a7ac85ad1d87ffa194aefb7169a104743c162f79b4ab4e9048966c760a51741be2e78d29d3263a3760a
7
- data.tar.gz: 4bb7a38423937d4b5675dfdff73c3309632d7400152389b9e0617f178be076cd156234e7519faa71f97df7bc90a386c5cd87858cb9a96e6ea1c1f163c468dd30
6
+ metadata.gz: 8276a0f55cfbdab771e028d05117291ce3cff8ad082e66a8a6828805392ae7e36c26240033fa6f9e37e1de25f2c6c9ff6f5a3a6c7f8b4b16210a1287819a5cf8
7
+ data.tar.gz: 35d84f7231336eb6edf2e44c91d128b6ebb38a2f7c0119906c0df9f29f94f41d5f2b5ba51532156fd465533adfa8fbc061ce824d9f90b433a0c20ee50fc76d01
@@ -14,16 +14,13 @@ jobs:
14
14
  fail-fast: false
15
15
  matrix:
16
16
  include:
17
- # Test projects
18
- - ruby: 2.4.5
19
- gemfile: tests/rails-4_capybara-2/Gemfile
20
- - ruby: 2.6.6
17
+ - ruby: 3.0.0
21
18
  gemfile: tests/rails-6_capybara-3/Gemfile
22
19
  # Used to run rspec and integration tests for spreewald binary:
23
- - ruby: 2.4.5
24
- gemfile: Gemfile.ruby245
25
20
  - ruby: 2.6.6
26
21
  gemfile: Gemfile.ruby266
22
+ - ruby: 3.0.0
23
+ gemfile: Gemfile.ruby300
27
24
  env:
28
25
  BUNDLE_GEMFILE: "${{ matrix.gemfile }}"
29
26
  steps:
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 2.4.5
1
+ 3.0.0
data/CHANGELOG.md CHANGED
@@ -3,6 +3,33 @@ 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
+
12
+ ## 4.1.2
13
+ - Multiple invocations of console don't raise anymore
14
+
15
+ ## 4.1.1
16
+ - The step `I open .. in a new browser tab` is now using the `noopener` option (see issue [#174])
17
+
18
+ ## 4.1.0
19
+
20
+ - New steps:
21
+ - When ... inside the ... iframe
22
+
23
+ - New steps only available for Capybara 3+:
24
+ - When I switch to the ... iframe
25
+ - When I switch back to the whole page
26
+ - The I switch back to the whole page step does not work reliably with Capybara 2 and lead to StaleReferenceErrors, therefore we decided to not make these steps available for Capybara 2.
27
+
28
+ - Small improvements:
29
+ - Trying to match against unsupported email headers will raise an error. Supported headers are "To", "CC", "BCC", "From", "Reply-To", "Subject", "Attachments"
30
+ - It's now possible to have indented header lines in email steps.
31
+ - If there's not an explicit text part in a mail, Spreewald determines if the email body is HTML or plaintext and converts it to plaintext accordingly.
32
+
6
33
  ## 4.0.0
7
34
 
8
35
  - Dropped support for capybara 1, Ruby 2.1 and Rails 3.2.
data/Gemfile.lock CHANGED
@@ -12,4 +12,4 @@ DEPENDENCIES
12
12
  rake
13
13
 
14
14
  BUNDLED WITH
15
- 2.2.14
15
+ 2.2.3
@@ -1,5 +1,7 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
+ ruby '3.0.0'
4
+
3
5
  gem 'rake'
4
6
  gem 'rspec'
5
7
  gem 'cucumber'
@@ -0,0 +1,108 @@
1
+ GEM
2
+ remote: https://rubygems.org/
3
+ specs:
4
+ activesupport (6.1.3.1)
5
+ concurrent-ruby (~> 1.0, >= 1.0.2)
6
+ i18n (>= 1.6, < 2)
7
+ minitest (>= 5.1)
8
+ tzinfo (~> 2.0)
9
+ zeitwerk (~> 2.3)
10
+ aruba (1.0.4)
11
+ childprocess (>= 2.0, < 5.0)
12
+ contracts (~> 0.16.0)
13
+ cucumber (>= 2.4, < 6.0)
14
+ rspec-expectations (~> 3.4)
15
+ thor (~> 1.0)
16
+ builder (3.2.4)
17
+ childprocess (4.0.0)
18
+ concurrent-ruby (1.1.8)
19
+ contracts (0.16.0)
20
+ cucumber (5.3.0)
21
+ builder (~> 3.2, >= 3.2.4)
22
+ cucumber-core (~> 8.0, >= 8.0.1)
23
+ cucumber-create-meta (~> 2.0, >= 2.0.2)
24
+ cucumber-cucumber-expressions (~> 10.3, >= 10.3.0)
25
+ cucumber-gherkin (~> 15.0, >= 15.0.2)
26
+ cucumber-html-formatter (~> 9.0, >= 9.0.0)
27
+ cucumber-messages (~> 13.1, >= 13.1.0)
28
+ cucumber-wire (~> 4.0, >= 4.0.1)
29
+ diff-lcs (~> 1.4, >= 1.4.4)
30
+ multi_test (~> 0.1, >= 0.1.2)
31
+ sys-uname (~> 1.2, >= 1.2.1)
32
+ cucumber-core (8.0.1)
33
+ cucumber-gherkin (~> 15.0, >= 15.0.2)
34
+ cucumber-messages (~> 13.0, >= 13.0.1)
35
+ cucumber-tag-expressions (~> 2.0, >= 2.0.4)
36
+ cucumber-create-meta (2.0.4)
37
+ cucumber-messages (~> 13.1, >= 13.1.0)
38
+ sys-uname (~> 1.2, >= 1.2.1)
39
+ cucumber-cucumber-expressions (10.3.0)
40
+ cucumber-gherkin (15.0.2)
41
+ cucumber-messages (~> 13.0, >= 13.0.1)
42
+ cucumber-html-formatter (9.0.0)
43
+ cucumber-messages (~> 13.0, >= 13.0.1)
44
+ cucumber-messages (13.2.1)
45
+ protobuf-cucumber (~> 3.10, >= 3.10.8)
46
+ cucumber-tag-expressions (2.0.4)
47
+ cucumber-wire (4.0.1)
48
+ cucumber-core (~> 8.0, >= 8.0.1)
49
+ cucumber-cucumber-expressions (~> 10.3, >= 10.3.0)
50
+ cucumber-messages (~> 13.0, >= 13.0.1)
51
+ diff-lcs (1.4.4)
52
+ ffi (1.15.0)
53
+ gemika (0.5.0)
54
+ i18n (1.8.10)
55
+ concurrent-ruby (~> 1.0)
56
+ mail (2.7.1)
57
+ mini_mime (>= 0.1.1)
58
+ middleware (0.1.0)
59
+ mini_mime (1.0.3)
60
+ minitest (5.14.4)
61
+ multi_test (0.1.2)
62
+ nokogiri (1.11.2-x86_64-linux)
63
+ racc (~> 1.4)
64
+ protobuf-cucumber (3.10.8)
65
+ activesupport (>= 3.2)
66
+ middleware
67
+ thor
68
+ thread_safe
69
+ racc (1.5.2)
70
+ rake (13.0.3)
71
+ rspec (3.10.0)
72
+ rspec-core (~> 3.10.0)
73
+ rspec-expectations (~> 3.10.0)
74
+ rspec-mocks (~> 3.10.0)
75
+ rspec-core (3.10.1)
76
+ rspec-support (~> 3.10.0)
77
+ rspec-expectations (3.10.1)
78
+ diff-lcs (>= 1.2.0, < 2.0)
79
+ rspec-support (~> 3.10.0)
80
+ rspec-mocks (3.10.2)
81
+ diff-lcs (>= 1.2.0, < 2.0)
82
+ rspec-support (~> 3.10.0)
83
+ rspec-support (3.10.2)
84
+ sys-uname (1.2.2)
85
+ ffi (~> 1.1)
86
+ thor (1.1.0)
87
+ thread_safe (0.3.6)
88
+ tzinfo (2.0.4)
89
+ concurrent-ruby (~> 1.0)
90
+ zeitwerk (2.4.2)
91
+
92
+ PLATFORMS
93
+ x86_64-linux
94
+
95
+ DEPENDENCIES
96
+ aruba
97
+ cucumber
98
+ gemika
99
+ mail
100
+ nokogiri
101
+ rake
102
+ rspec
103
+
104
+ RUBY VERSION
105
+ ruby 3.0.0p0
106
+
107
+ BUNDLED WITH
108
+ 2.2.3
data/README.md CHANGED
@@ -21,7 +21,7 @@ Or install it yourself as:
21
21
 
22
22
  ## Supported versions
23
23
 
24
- Spreewald is currently tested against Ruby 2.4.5 with Rails 4 and Capybara 2 and Ruby 2.6.6 with Rails 6 and Capybara 3.
24
+ Spreewald is currently tested against and Ruby 2.6.6 with Rails 6 and Capybara 3.
25
25
 
26
26
  ## Usage
27
27
 
data/Rakefile CHANGED
@@ -65,22 +65,14 @@ def run_tests(gemfile, ruby)
65
65
  # Run specs and integration tests for Spreewald binary
66
66
  [
67
67
  system("BUNDLE_GEMFILE=#{gemfile} bundle exec rspec"),
68
- system("BUNDLE_GEMFILE=#{gemfile} bundle exec cucumber"),
68
+ system("BUNDLE_GEMFILE=#{gemfile} bundle exec cucumber --publish-quiet"),
69
69
  ].all?
70
70
  end
71
71
  end
72
72
 
73
73
  def cucumber_command(directory, ruby_version)
74
- command = "cd #{directory} && BUNDLE_GEMFILE=Gemfile bundle exec cucumber"
75
- if Gem::Version.new(ruby_version) > Gem::Version.new('2.5')
76
- # Modern cucumber sees pending tests as failures.
77
- # We don't want this.
78
- command << ' --no-strict-pending'
79
- else
80
- # Ruby < 2.5 means the capybara 2 Test project.
81
- # Omit scenarios that only work with modern Capybara.
82
- command << ' --tags "not @not-capybara-2"'
83
- end
74
+ command = "cd #{directory} && BUNDLE_GEMFILE=Gemfile bundle exec cucumber --publish-quiet"
75
+ command << ' --no-strict-pending'
84
76
  command
85
77
  end
86
78
 
@@ -19,7 +19,7 @@ When /^I open (.+?) in a new browser tab$/ do |page_name|
19
19
  previous_handles_count = browser.window_handles.size
20
20
  relative_target_path = path_to(page_name)
21
21
 
22
- page.execute_script "window.open('#{relative_target_path}', '_blank')"
22
+ page.execute_script "window.open('#{relative_target_path}', '_blank', 'noopener')"
23
23
  step "there should be #{previous_handles_count + 1} browser tabs"
24
24
  step "I switch to the new browser tab"
25
25
  end.overridable
@@ -11,11 +11,6 @@ Then 'console' do
11
11
  require 'irb'
12
12
  ARGV.clear # IRB takes ARGV as its own arguments
13
13
 
14
- # `source` is defined by Capybara as a shortcut to `page.source`. IRB tries to
15
- # create an alias with the same name and fails with a warning. To avoid this,
16
- # we remove the alias here.
17
- undef :source
18
-
19
14
  # We adapted the steps of IRB.run
20
15
  # https://github.com/ruby/ruby/blob/c08f7b80889b531865e74bc5f573df8fa27f2088/lib/irb.rb#L418
21
16
  # with injected workspace. See https://github.com/makandra/spreewald/issues/77 for reasons.
@@ -24,6 +19,11 @@ Then 'console' do
24
19
  # "already initialized constant" warnings
25
20
  unless IRB.conf[:LOAD_MODULES]
26
21
  IRB.setup(nil)
22
+
23
+ # `source` is defined by Capybara as a shortcut to `page.source`. IRB tries to
24
+ # create an alias with the same name and fails with a warning. To avoid this,
25
+ # we remove the alias here.
26
+ undef :source
27
27
  end
28
28
 
29
29
  workspace = IRB::WorkSpace.new(binding)
@@ -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.0'
2
+ VERSION = '4.2.3'
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
+