spreewald 2.3.0 → 2.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (153) hide show
  1. checksums.yaml +5 -5
  2. data/.gitignore +1 -1
  3. data/.travis.yml +14 -15
  4. data/CHANGELOG.md +33 -4
  5. data/Gemfile +1 -2
  6. data/Gemfile.lock +1 -16
  7. data/Gemfile.ruby266 +9 -0
  8. data/Gemfile.ruby266.lock +65 -0
  9. data/README.md +86 -12
  10. data/Rakefile +22 -7
  11. data/examples/paths.rb +36 -0
  12. data/examples/selectors.rb +28 -0
  13. data/lib/spreewald/all_steps.rb +4 -1
  14. data/lib/spreewald/browser_tab_steps.rb +91 -0
  15. data/lib/spreewald/development_steps.rb +1 -1
  16. data/lib/spreewald/email_steps.rb +11 -4
  17. data/lib/spreewald/session_steps.rb +18 -0
  18. data/lib/spreewald/time_steps.rb +102 -0
  19. data/lib/spreewald/timecop_steps.rb +6 -76
  20. data/lib/spreewald/web_steps.rb +7 -15
  21. data/lib/spreewald_support/driver_info.rb +8 -0
  22. data/lib/spreewald_support/tolerance_for_selenium_sync_issues.rb +9 -3
  23. data/lib/spreewald_support/version.rb +1 -1
  24. data/support/step_definition.rb +1 -1
  25. data/support/step_definition_file.rb +2 -0
  26. data/tests/rails-3_capybara-1/Gemfile +2 -1
  27. data/tests/rails-3_capybara-1/Gemfile.lock +3 -1
  28. data/tests/rails-3_capybara-1/app +1 -1
  29. data/tests/rails-3_capybara-1/config/cucumber.yml +1 -1
  30. data/tests/rails-3_capybara-1/config/database.yml +1 -1
  31. data/tests/rails-3_capybara-1/config/routes.rb +1 -0
  32. data/tests/rails-3_capybara-1/db +1 -1
  33. data/tests/rails-3_capybara-1/features/shared +1 -1
  34. data/tests/rails-3_capybara-1/features/support/paths.rb +1 -1
  35. data/tests/rails-3_capybara-1/features/support/selectors.rb +1 -1
  36. data/tests/rails-3_capybara-1/public +1 -1
  37. data/tests/rails-3_capybara-2/Gemfile +2 -1
  38. data/tests/rails-3_capybara-2/Gemfile.lock +3 -1
  39. data/tests/rails-3_capybara-2/Rakefile +1 -1
  40. data/tests/rails-3_capybara-2/app +1 -1
  41. data/tests/rails-3_capybara-2/config +1 -1
  42. data/tests/rails-3_capybara-2/config.ru +1 -1
  43. data/tests/rails-3_capybara-2/db +1 -1
  44. data/tests/rails-3_capybara-2/features +1 -1
  45. data/tests/rails-3_capybara-2/public +1 -1
  46. data/tests/rails-3_capybara-2/script +1 -1
  47. data/tests/rails-4_capybara-3/Gemfile +1 -1
  48. data/tests/rails-4_capybara-3/Gemfile.lock +3 -3
  49. data/tests/rails-4_capybara-3/app +1 -1
  50. data/tests/rails-4_capybara-3/config/routes.rb +1 -0
  51. data/tests/rails-4_capybara-3/db +1 -1
  52. data/tests/rails-4_capybara-3/features/browser_tab_steps.feature +1 -0
  53. data/tests/rails-4_capybara-3/features/development_steps.feature +1 -1
  54. data/tests/rails-4_capybara-3/features/email_steps.feature +1 -1
  55. data/tests/rails-4_capybara-3/features/overriding.feature +1 -1
  56. data/tests/rails-4_capybara-3/features/session_steps.feature +1 -0
  57. data/tests/rails-4_capybara-3/features/step_definitions/overriding_steps.rb +1 -1
  58. data/tests/rails-4_capybara-3/features/step_definitions/test_steps.rb +1 -1
  59. data/tests/rails-4_capybara-3/features/support/paths.rb +1 -1
  60. data/tests/rails-4_capybara-3/features/support/selectors.rb +1 -1
  61. data/tests/rails-4_capybara-3/features/table_steps.feature +1 -1
  62. data/tests/rails-4_capybara-3/features/time_steps.feature +1 -0
  63. data/tests/rails-4_capybara-3/features/web_steps.feature +1 -1
  64. data/tests/rails-4_capybara-3/public/fixture_files +1 -1
  65. data/tests/rails-6_capybara-3/.ruby-version +1 -0
  66. data/tests/rails-6_capybara-3/Gemfile +25 -0
  67. data/tests/rails-6_capybara-3/Gemfile.lock +264 -0
  68. data/tests/rails-6_capybara-3/README.md +24 -0
  69. data/tests/rails-6_capybara-3/Rakefile +6 -0
  70. data/tests/rails-6_capybara-3/app/controllers +1 -0
  71. data/tests/rails-6_capybara-3/app/mailers/application_mailer.rb +4 -0
  72. data/tests/rails-6_capybara-3/app/mailers/spreewald_mailer.rb +30 -0
  73. data/tests/rails-6_capybara-3/app/models/application_record.rb +3 -0
  74. data/tests/rails-6_capybara-3/app/views +1 -0
  75. data/tests/rails-6_capybara-3/bin/bundle +114 -0
  76. data/tests/rails-6_capybara-3/bin/rails +4 -0
  77. data/tests/rails-6_capybara-3/bin/rake +4 -0
  78. data/tests/rails-6_capybara-3/bin/setup +33 -0
  79. data/tests/rails-6_capybara-3/config.ru +5 -0
  80. data/tests/rails-6_capybara-3/config/application.rb +35 -0
  81. data/tests/rails-6_capybara-3/config/boot.rb +3 -0
  82. data/tests/rails-6_capybara-3/config/cucumber.yml +9 -0
  83. data/tests/rails-6_capybara-3/config/database.yml +25 -0
  84. data/tests/rails-6_capybara-3/config/environment.rb +5 -0
  85. data/tests/rails-6_capybara-3/config/environments/development.rb +48 -0
  86. data/tests/rails-6_capybara-3/config/environments/test.rb +45 -0
  87. data/tests/rails-6_capybara-3/config/initializers/application_controller_renderer.rb +8 -0
  88. data/tests/rails-6_capybara-3/config/initializers/backtrace_silencers.rb +7 -0
  89. data/tests/rails-6_capybara-3/config/initializers/content_security_policy.rb +28 -0
  90. data/tests/rails-6_capybara-3/config/initializers/cookies_serializer.rb +5 -0
  91. data/tests/rails-6_capybara-3/config/initializers/filter_parameter_logging.rb +4 -0
  92. data/tests/rails-6_capybara-3/config/initializers/inflections.rb +16 -0
  93. data/tests/rails-6_capybara-3/config/initializers/mime_types.rb +4 -0
  94. data/tests/rails-6_capybara-3/config/initializers/wrap_parameters.rb +14 -0
  95. data/tests/rails-6_capybara-3/config/locales/en.yml +33 -0
  96. data/tests/rails-6_capybara-3/config/routes.rb +1 -0
  97. data/tests/rails-6_capybara-3/db +1 -0
  98. data/tests/rails-6_capybara-3/features/browser_tab_steps.feature +1 -0
  99. data/tests/rails-6_capybara-3/features/development_steps.feature +1 -0
  100. data/tests/rails-6_capybara-3/features/email_steps.feature +1 -0
  101. data/tests/rails-6_capybara-3/features/overriding.feature +1 -0
  102. data/tests/rails-6_capybara-3/features/session_steps.feature +1 -0
  103. data/tests/{shared/app/views/emails/send_email.haml → rails-6_capybara-3/features/step_definitions/.gitkeep} +0 -0
  104. data/tests/rails-6_capybara-3/features/step_definitions/overriding_steps.rb +1 -0
  105. data/tests/rails-6_capybara-3/features/step_definitions/test_steps.rb +1 -0
  106. data/tests/rails-6_capybara-3/features/support/env.rb +66 -0
  107. data/tests/rails-6_capybara-3/features/support/paths.rb +1 -0
  108. data/tests/rails-6_capybara-3/features/support/selectors.rb +1 -0
  109. data/tests/rails-6_capybara-3/features/support/selenium.rb +3 -0
  110. data/tests/rails-6_capybara-3/features/table_steps.feature +1 -0
  111. data/tests/rails-6_capybara-3/features/time_steps.feature +1 -0
  112. data/tests/rails-6_capybara-3/features/web_steps.feature +1 -0
  113. data/tests/{shared/db/migrate/.gitignore → rails-6_capybara-3/lib/tasks/.keep} +0 -0
  114. data/tests/rails-6_capybara-3/lib/tasks/cucumber.rake +76 -0
  115. data/tests/rails-6_capybara-3/log/.keep +0 -0
  116. data/tests/rails-6_capybara-3/public/404.html +67 -0
  117. data/tests/rails-6_capybara-3/public/422.html +67 -0
  118. data/tests/rails-6_capybara-3/public/500.html +66 -0
  119. data/tests/rails-6_capybara-3/public/favicon.ico +0 -0
  120. data/tests/rails-6_capybara-3/public/fixture_files +1 -0
  121. data/tests/rails-6_capybara-3/script/cucumber +11 -0
  122. data/tests/shared/app/controllers/application_controller.rb +9 -0
  123. data/tests/shared/app/controllers/authenticated_controller.rb +10 -2
  124. data/tests/shared/app/controllers/emails_controller.rb +25 -7
  125. data/tests/shared/app/controllers/forms_controller.rb +3 -0
  126. data/tests/shared/app/controllers/static_pages_controller.rb +23 -0
  127. data/tests/shared/app/models/mailer.rb +16 -0
  128. data/tests/shared/app/views/layouts/mailer.html.erb +13 -0
  129. data/tests/shared/app/views/layouts/mailer.text.erb +1 -0
  130. data/tests/shared/app/views/mailer/{email.haml → email.text.erb} +0 -0
  131. data/tests/shared/app/views/mailer/html_email_with_links.haml +6 -0
  132. data/tests/shared/app/views/mailer/text_email_with_links.text.erb +6 -0
  133. data/tests/shared/app/views/spreewald_mailer +1 -0
  134. data/tests/shared/app/views/static_pages/session_1.haml +1 -0
  135. data/tests/shared/app/views/static_pages/session_2.haml +1 -0
  136. data/tests/shared/app/views/static_pages/session_3.haml +1 -0
  137. data/tests/shared/app/views/static_pages/tab_1.haml +3 -0
  138. data/tests/shared/app/views/static_pages/tab_2.haml +2 -0
  139. data/tests/shared/app/views/static_pages/tab_3.haml +1 -0
  140. data/tests/shared/app/views/static_pages/time.html.haml +2 -0
  141. data/tests/shared/app/views/static_pages/visibility.html.haml +8 -1
  142. data/tests/shared/app/views/static_pages/within.html.haml +3 -0
  143. data/tests/shared/config/routes.rb +40 -0
  144. data/tests/shared/db/migrate/.keep +0 -0
  145. data/tests/shared/features/shared/browser_tab_steps.feature +103 -0
  146. data/tests/shared/features/shared/email_steps.feature +18 -0
  147. data/tests/shared/features/shared/session_steps.feature +29 -0
  148. data/tests/shared/features/shared/time_steps.feature +31 -0
  149. data/tests/shared/features/shared/web_steps.feature +17 -0
  150. metadata +166 -12
  151. data/tests/rails-3_capybara-1/config/routes.rb +0 -5
  152. data/tests/rails-4_capybara-3/.gitignore +0 -17
  153. data/tests/rails-4_capybara-3/config/routes.rb +0 -3
@@ -13,6 +13,30 @@ module NavigationHelpers
13
13
  when /^the home\s?page$/
14
14
  root_path
15
15
 
16
+ when /^the (page|form) for the (.*?) above$/
17
+ action_prose = Regexp.last_match(1)
18
+ model_prose = Regexp.last_match(2)
19
+ route = "#{(action_prose == 'form') ? 'edit_' : ''}#{model_prose_to_route_segment(model_prose)}_path"
20
+ model = model_prose_to_class(model_prose)
21
+ send(route, model.reorder(:id).last!)
22
+
23
+ when /^the (page|form) for the (.*?) "(.*?)"$/
24
+ action_prose = Regexp.last_match(1)
25
+ model_prose = Regexp.last_match(2)
26
+ identifier = Regexp.last_match(3)
27
+ path_to_show_or_edit(action_prose, model_prose, identifier)
28
+
29
+ when /^the (.*?) (page|form) for "(.*?)"$/
30
+ model_prose = Regexp.last_match(1)
31
+ action_prose = Regexp.last_match(2)
32
+ identifier = Regexp.last_match(3)
33
+ path_to_show_or_edit(action_prose, model_prose, identifier)
34
+
35
+ when /^the (.*?) form$/
36
+ model_prose = Regexp.last_match(1)
37
+ route = "new_#{model_prose_to_route_segment(model_prose)}_path"
38
+ send(route)
39
+
16
40
  else
17
41
  begin
18
42
  page_name =~ /^the (.*) page$/
@@ -24,6 +48,18 @@ module NavigationHelpers
24
48
  end
25
49
  end
26
50
  end
51
+
52
+ private
53
+
54
+ def model_prose_to_class(model_prose)
55
+ model_prose.gsub(' ', '_').classify.constantize
56
+ end
57
+
58
+ def model_prose_to_route_segment(model_prose)
59
+ model_prose = model_prose.downcase
60
+ model_prose.gsub(/[\ \/]/, '_')
61
+ end
62
+
27
63
  end
28
64
 
29
65
  World(NavigationHelpers)
@@ -12,6 +12,27 @@ module HtmlSelectorsHelpers
12
12
  when "the page"
13
13
  "html > body"
14
14
 
15
+ # Auto-mapper for BEM classes and ARIA labels
16
+ #
17
+ # Usage examples:
18
+ # the main menu -> '.main-menu, [aria-label="main menu"]'
19
+ # the item box's header -> '.item-box--header, [aria-label="item box's header"]'
20
+ # the slider's item that is current -> '.slider--item.is-current, [aria-label="slider's item that is current"]'
21
+ when /^the (.*)$/
22
+ match = Regexp.last_match(1)
23
+ match =~ /^(.+?)(?:'s (.+?))?(?: that (.+))?$/
24
+
25
+ bem_selector = '.'
26
+ bem_selector << selectorify(Regexp.last_match(1))
27
+ bem_selector << '--' << selectorify(Regexp.last_match(2)) if Regexp.last_match(2)
28
+ bem_selector << '.' << selectorify(Regexp.last_match(3)) if Regexp.last_match(3)
29
+
30
+ aria_selector = '[aria-label="'
31
+ aria_selector << match.gsub('"', '\\"')
32
+ aria_selector << '"]'
33
+
34
+ [bem_selector, aria_selector].join(', ')
35
+
15
36
  # Add more mappings here.
16
37
  # Here is an example that pulls values out of the Regexp:
17
38
  #
@@ -35,6 +56,13 @@ module HtmlSelectorsHelpers
35
56
  "Now, go and add a mapping in #{__FILE__}"
36
57
  end
37
58
  end
59
+
60
+ private
61
+
62
+ def selectorify(string)
63
+ string.gsub(/ /, '-')
64
+ end
65
+
38
66
  end
39
67
 
40
68
  World(HtmlSelectorsHelpers)
@@ -1,9 +1,12 @@
1
1
  # coding: UTF-8
2
2
  require 'rspec/matchers'
3
3
 
4
+ ALREADY_LOADED_FILES = %w[all_steps timecop_steps]
5
+
4
6
  Dir[File.join(File.dirname(__FILE__), '*_steps.rb')].each do |f|
5
7
  name = File.basename(f, '.rb')
6
- unless name == 'all_steps'
8
+
9
+ unless ALREADY_LOADED_FILES.include?(name)
7
10
  require "spreewald/#{name}"
8
11
  end
9
12
  end
@@ -0,0 +1,91 @@
1
+ Before do
2
+ @previous_browser_tabs_count = nil
3
+ end
4
+
5
+ # Close all but the first browser tab
6
+ After do
7
+ next unless selenium_driver?
8
+
9
+ browser.switch_to.window(browser.window_handles.last)
10
+ while browser.window_handles.size > 1 do
11
+ browser.close
12
+ browser.switch_to.window(browser.window_handles.last)
13
+ end
14
+ end
15
+
16
+ # Opens [the page](https://github.com/makandra/spreewald/blob/master/examples/paths.rb) in a new browser tab and switches to it.
17
+ When /^I open (.+?) in a new browser tab$/ do |page_name|
18
+ require_selenium!
19
+ previous_handles_count = browser.window_handles.size
20
+ relative_target_path = path_to(page_name)
21
+
22
+ page.execute_script "window.open('#{relative_target_path}', '_blank')"
23
+ step "there should be #{previous_handles_count + 1} browser tabs"
24
+ step "I switch to the new browser tab"
25
+ end.overridable
26
+
27
+ # Closes the current browser tab and switches back to the first tab.
28
+ When 'I close the browser tab' do
29
+ require_selenium!
30
+ # Wait for browser tab to close
31
+ previous_handles_count = browser.window_handles.size
32
+ raise 'Cannot close the last remaining browser tab' if previous_handles_count == 1
33
+
34
+ browser.close
35
+ step "there should be #{previous_handles_count - 1} browser tabs"
36
+
37
+ # Closing the current tab causes Selenium to continue using a stale invalid tab handle
38
+ browser.switch_to.window(browser.window_handles.first)
39
+ end.overridable
40
+
41
+ # Waits for the new browser tab to appear, then switches to it.
42
+ When /^I switch to the new(?:ly opened)? browser tab$/ do
43
+ require_selenium!
44
+ step 'there should be at least 2 browser tabs'
45
+ browser.switch_to.window(browser.window_handles.last)
46
+ end.overridable
47
+
48
+ # Changes the browser context to the second-last browser tab.
49
+ When /^I switch(?: back)? to the previous browser tab$/ do
50
+ require_selenium!
51
+ previous_handle = browser.window_handles[-2] # Second last should be the previous browser tab
52
+ previous_handle ||= browser.window_handles.first # Fall back if only one tab is left
53
+ browser.switch_to.window(previous_handle)
54
+ end.overridable
55
+
56
+ # Required for the check whether a new browser tab was opened or not.
57
+ When 'I may open a new browser tab' do
58
+ @previous_browser_tabs_count = browser.window_handles.size
59
+ end.overridable
60
+
61
+ # Example (positive expectation):
62
+ #
63
+ # When I may open a new browser tab
64
+ # And I click on "Open link in new browser tab"
65
+ # Then I should have opened a new browser tab
66
+ #
67
+ # Example (negative expectation):
68
+ #
69
+ # When I may open a new browser tab
70
+ # And I click on "Open link in current browser tab"
71
+ # Then I should not have opened a new browser tab
72
+ Then /^I should( not)? have opened a new browser tab$/ do |negate|
73
+ raise "you need to use the 'I may open a new tab' step beforehand" unless @previous_browser_tabs_count
74
+ expected_browser_tab_count = negate ? @previous_browser_tabs_count : (@previous_browser_tabs_count + 1)
75
+
76
+ step "there should be #{expected_browser_tab_count} browser tabs"
77
+ end.overridable
78
+
79
+ Then /^there should be (\d+) browser tabs?$/ do |expected_browser_tabs|
80
+ patiently do
81
+ actual_browser_tabs = browser.window_handles.size
82
+ expect(actual_browser_tabs).to eq(expected_browser_tabs.to_i), "Expected #{expected_browser_tabs} browser tab to be open, but found #{actual_browser_tabs}"
83
+ end
84
+ end.overridable
85
+
86
+ Then /^there should be at least (\d+) browser tabs?$/ do |expected_browser_tabs|
87
+ patiently do
88
+ actual_browser_tabs = browser.window_handles.size
89
+ expect(actual_browser_tabs).to be >= (expected_browser_tabs.to_i), "Expected at least #{expected_browser_tabs} browser tab to be open, but found #{actual_browser_tabs}"
90
+ end
91
+ end.overridable
@@ -57,7 +57,7 @@ AfterStep('@slow-motion') do
57
57
  sleep 2
58
58
  end
59
59
 
60
- # Waits for keypress after each step
60
+ # Waits for a keypress after each step
61
61
  AfterStep('@single-step') do
62
62
  print "Single Stepping. Hit enter to continue"
63
63
  STDIN.getc
@@ -68,10 +68,17 @@ end.overridable
68
68
  When /^I follow the (first|second|third)? ?link in the e?mail$/ do |index_in_words|
69
69
  mail = @mail || ActionMailer::Base.deliveries.last
70
70
  index = { nil => 0, 'first' => 0, 'second' => 1, 'third' => 2 }[index_in_words]
71
- url_pattern = %r{(?:http|https)://[^/]+([^"'\s\\]*)}
72
- mail_body = MailFinder.email_text_body(mail).to_s
73
- only_path = mail_body.scan(url_pattern)[index][0]
74
- visit only_path
71
+ url_pattern = %r((?:https?://[^/]+)([^"'\s]+))
72
+
73
+ paths = if mail.html_part
74
+ dom = Nokogiri::HTML(mail.html_part.body.to_s)
75
+ (dom / 'a[href]').map { |a| a['href'].match(url_pattern)[1] }
76
+ else
77
+ mail_body = MailFinder.email_text_body(mail).to_s
78
+ mail_body.scan(url_pattern).flatten(1)
79
+ end
80
+
81
+ visit paths[index]
75
82
  end.overridable
76
83
 
77
84
  Then /^no e?mail should have been sent$/ do
@@ -0,0 +1,18 @@
1
+ # You can append `in the browser session "name"` to any other step to execute
2
+ # the step in a different browser session.
3
+ #
4
+ # You may need to update other steps to allow multiple sessions (e.g. your
5
+ # authentication steps have to support multiple logged in users).
6
+ # More details [here](https://makandracards.com/makandra/474480-how-to-make-a-cucumber-test-work-with-multiple-browser-sessions).
7
+ When /^(.*) in the browser session "([^"]+)"$/ do |nested_step, session_name|
8
+ Capybara.using_session(session_name) do
9
+ step(nested_step)
10
+ end
11
+ end.overridable(priority: 5)
12
+
13
+ # nodoc
14
+ When /^(.*) in the browser session "([^"]+)":$/ do |nested_step, session_name, table_or_string|
15
+ Capybara.using_session(session_name) do
16
+ step("#{nested_step}:", table_or_string)
17
+ end
18
+ end.overridable(priority: 5)
@@ -0,0 +1,102 @@
1
+ # coding: UTF-8
2
+
3
+
4
+ # Steps to travel through time
5
+ #
6
+ # This uses [Timecop](https://github.com/jtrupiano/timecop) or Active Support 4.1+ to stub Time.now / Time.current.
7
+ # The user is responsible for including one of the two gems.
8
+ #
9
+ # Please note that the two approaches branch. While ActiveSupport will freeze the time, Timecop will keep it running.
10
+ # FILE_COMMENT_END
11
+
12
+ major_minor_rails_version = defined?(ActiveSupport) ? [ActiveSupport::VERSION::MAJOR, ActiveSupport::VERSION::MINOR] : [0, 0]
13
+ is_at_least_rails_4_1 = (major_minor_rails_version <=> [4, 1]) != -1
14
+
15
+ if defined?(Timecop) || is_at_least_rails_4_1
16
+
17
+ module TimeHelpers
18
+
19
+ # When you have to make your rails app time zone aware you have to go 100%
20
+ # otherwise you are better off ignoring time zones at all.
21
+ # https://makandracards.com/makandra/8723-guide-to-localizing-a-rails-application
22
+
23
+ def use_timezones?
24
+ active_record_loaded = defined?(ActiveRecord::Base)
25
+ (!active_record_loaded || ActiveRecord::Base.default_timezone != :local) && Time.zone
26
+ end
27
+
28
+ def parse_time(str)
29
+ if use_timezones?
30
+ Time.zone.parse(str)
31
+ else
32
+ Time.parse(str)
33
+ end
34
+ end
35
+
36
+ def current_time
37
+ if use_timezones?
38
+ Time.current
39
+ else
40
+ Time.now
41
+ end
42
+ end
43
+
44
+ if defined?(Timecop)
45
+ # Emulate ActiveSupport time helper methods with Timecop - don't rename these methods
46
+ def travel(duration)
47
+ Timecop.travel(current_time + duration)
48
+ end
49
+
50
+ def travel_to(date_or_time)
51
+ Timecop.travel(date_or_time)
52
+ end
53
+
54
+ def travel_back
55
+ Timecop.return
56
+ end
57
+ else
58
+ require 'active_support/testing/time_helpers'
59
+ include ActiveSupport::Testing::TimeHelpers
60
+ end
61
+
62
+ end
63
+
64
+ World(TimeHelpers)
65
+
66
+ # Example:
67
+ #
68
+ # Given the date is 2012-02-10
69
+ # Given the time is 2012-02-10 13:40
70
+ When /^the (?:date|time) is "?(\d{4}-\d{2}-\d{2}(?: \d{1,2}:\d{2})?)"?$/ do |time|
71
+ travel_to parse_time(time)
72
+ end.overridable
73
+
74
+ # Example:
75
+ #
76
+ # Given the time is 13:40
77
+ When /^the time is "?(\d{1,2}:\d{2})"?$/ do |time_without_date|
78
+ travel_to parse_time(time_without_date) # date will be today
79
+ end.overridable
80
+
81
+ # Example:
82
+ #
83
+ # When it is 10 minutes later
84
+ # When it is a few hours earlier
85
+ When /^it is (\d+|an?|some|a few) (seconds?|minutes?|hours?|days?|weeks?|months?|years?) (later|earlier)$/ do |amount, unit, direction|
86
+ amount = case amount
87
+ when 'a', 'an'
88
+ 1
89
+ when 'some', 'a few'
90
+ 10
91
+ else
92
+ amount.to_i
93
+ end
94
+ amount = -amount if direction == 'earlier'
95
+ travel amount.send(unit)
96
+ end.overridable
97
+
98
+ After do
99
+ travel_back
100
+ end
101
+
102
+ end
@@ -1,79 +1,9 @@
1
- # coding: UTF-8
2
-
3
-
4
- # Steps to travel through time using [Timecop](https://github.com/jtrupiano/timecop).
5
- #
6
- # See [this article](https://makandracards.com/makandra/1222-useful-cucumber-steps-to-travel-through-time-with-timecop) for details.
1
+ # nodoc
7
2
  # FILE_COMMENT_END
8
3
 
4
+ warn <<-WARNING
5
+ Warning: The file spreewald/timecop_steps.rb is deprecated. It was moved to
6
+ spreewald/time_steps.rb. Please require the new file instead.
7
+ WARNING
9
8
 
10
- if defined?(Timecop)
11
-
12
- module TimecopHarness
13
-
14
- # When you have to make your rails app time zone aware you have to go 100%
15
- # otherwise you are better off ignoring time zones at all.
16
- # https://makandracards.com/makandra/8723-guide-to-localizing-a-rails-application
17
-
18
- def use_timezones?
19
- active_record_loaded = defined?(ActiveRecord::Base)
20
- (!active_record_loaded || ActiveRecord::Base.default_timezone != :local) && Time.zone
21
- end
22
-
23
- def parse_time(str)
24
- if use_timezones?
25
- Time.zone.parse(str)
26
- else
27
- Time.parse(str)
28
- end
29
- end
30
-
31
- def current_time
32
- if use_timezones?
33
- Time.current
34
- else
35
- Time.now
36
- end
37
- end
38
-
39
- end
40
-
41
- World(TimecopHarness)
42
-
43
- # Example:
44
- #
45
- # Given the date is 2012-02-10
46
- # Given the time is 2012-02-10 13:40
47
- When /^the (?:date|time) is "?(\d{4}-\d{2}-\d{2}(?: \d{1,2}:\d{2})?)"?$/ do |time|
48
- Timecop.travel(parse_time(time))
49
- end.overridable
50
-
51
- # Example:
52
- #
53
- # Given the time is 13:40
54
- When /^the time is "?(\d{1,2}:\d{2})"?$/ do |time_without_date|
55
- Timecop.travel(parse_time(time_without_date)) # date will be today
56
- end.overridable
57
-
58
- # Example:
59
- #
60
- # When it is 10 minutes later
61
- # When it is a few hours earlier
62
- When /^it is (\d+|a|some|a few) (seconds?|minutes?|hours?|days?|weeks?|months?|years?) (later|earlier)$/ do |amount, unit, direction|
63
- amount = case amount
64
- when 'a'
65
- 1
66
- when 'some', 'a few'
67
- 10
68
- else
69
- amount.to_i
70
- end
71
- amount = -amount if direction == 'earlier'
72
- Timecop.travel(current_time + amount.send(unit))
73
- end.overridable
74
-
75
- After do
76
- Timecop.return
77
- end
78
-
79
- end
9
+ require 'spreewald/time_steps'
@@ -35,7 +35,7 @@ require 'uri'
35
35
  require 'cgi'
36
36
 
37
37
 
38
- # You can append `within [selector]` to any other web step.
38
+ # You can append `within [selector]` to any other web step, even multiple times.
39
39
  # Be aware that within will only look at the first element that matches.
40
40
  # If this is a problem for you following links, you might want to have a look
41
41
  # at the 'When I follow "..." inside any "..."'-step.
@@ -322,7 +322,7 @@ Then /^I should( not)? see a link labeled "([^"]*)"$/ do |negate, label|
322
322
  expectation = negate ? :not_to : :to
323
323
  link = page.first('a', :text => label, minimum: 0) || page.first(%(a[title="#{label}"]), minimum: 0)
324
324
  expect(link).send(expectation, be_present)
325
- end
325
+ end.overridable
326
326
 
327
327
  # Checks that an input field contains some value (allowing * as wildcard character)
328
328
  Then /^the "([^"]*)" field should (not )?contain "([^"]*)"$/ do |label, negate, expected_string|
@@ -463,7 +463,7 @@ end.overridable
463
463
  #
464
464
  # Attention: Doesn't work with Selenium, see https://github.com/jnicklas/capybara#gotchas
465
465
  Then /^I should get a download with filename "([^\"]*)"$/ do |filename|
466
- expect(page.response_headers['Content-Disposition']).to match /filename="#{Regexp.escape(filename)}"$/
466
+ expect(page.response_headers['Content-Disposition']).to match /filename="#{Regexp.escape(filename)}"(;|$)/
467
467
  end.overridable
468
468
 
469
469
  # Checks that a certain option is selected for a text field
@@ -641,32 +641,24 @@ end.overridable
641
641
 
642
642
  When /^I confirm the browser dialog$/ do
643
643
  patiently do
644
- page.driver.browser.switch_to.alert.accept
644
+ browser.switch_to.alert.accept
645
645
  end
646
646
  end.overridable
647
647
 
648
648
  When /^I cancel the browser dialog$/ do
649
649
  patiently do
650
- page.driver.browser.switch_to.alert.dismiss
650
+ browser.switch_to.alert.dismiss
651
651
  end
652
652
  end.overridable
653
653
 
654
654
  When /^I enter "([^"]*)" into the browser dialog$/ do |text|
655
655
  patiently do
656
- alert = page.driver.browser.switch_to.alert
656
+ alert = browser.switch_to.alert
657
657
  alert.send_keys(text)
658
658
  alert.accept
659
659
  end
660
660
  end.overridable
661
661
 
662
- When /^I switch to the new tab$/ do
663
- if javascript_capable?
664
- page.driver.browser.switch_to.window(page.driver.browser.window_handles.last)
665
- else
666
- raise("This step works only with selenium")
667
- end
668
- end.overridable
669
-
670
662
  # Tests that an input, button or checkbox with the given label is disabled.
671
663
  Then /^the "([^\"]*)" (field|button|checkbox) should( not)? be disabled$/ do |label, kind, negate|
672
664
  if Spreewald::Comparison.compare_versions(Capybara::VERSION, :<, "2.1")
@@ -728,7 +720,7 @@ When /^I perform basic authentication as "([^\"]*)\/([^\"]*)" and go to (.*)$/ d
728
720
  visit("http://#{user}:#{password}@#{server.host}:#{server.port}#{path}")
729
721
  else
730
722
  authorizers = [
731
- (page.driver.browser if page.driver.respond_to?(:browser)),
723
+ (browser),
732
724
  (self),
733
725
  (page.driver)
734
726
  ].compact