capybara 2.18.0 → 3.0.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (168) hide show
  1. checksums.yaml +4 -4
  2. data/History.md +26 -1
  3. data/README.md +12 -12
  4. data/lib/capybara.rb +13 -25
  5. data/lib/capybara/config.rb +11 -57
  6. data/lib/capybara/cucumber.rb +2 -3
  7. data/lib/capybara/driver/base.rb +5 -16
  8. data/lib/capybara/driver/node.rb +5 -4
  9. data/lib/capybara/dsl.rb +1 -0
  10. data/lib/capybara/helpers.rb +16 -28
  11. data/lib/capybara/minitest.rb +139 -138
  12. data/lib/capybara/minitest/spec.rb +15 -14
  13. data/lib/capybara/node/actions.rb +59 -81
  14. data/lib/capybara/node/base.rb +11 -18
  15. data/lib/capybara/node/document.rb +2 -2
  16. data/lib/capybara/node/document_matchers.rb +8 -8
  17. data/lib/capybara/node/element.rb +30 -40
  18. data/lib/capybara/node/finders.rb +62 -70
  19. data/lib/capybara/node/matchers.rb +48 -71
  20. data/lib/capybara/node/simple.rb +11 -17
  21. data/lib/capybara/queries/ancestor_query.rb +4 -6
  22. data/lib/capybara/queries/base_query.rb +18 -17
  23. data/lib/capybara/queries/current_path_query.rb +8 -24
  24. data/lib/capybara/queries/match_query.rb +3 -7
  25. data/lib/capybara/queries/selector_query.rb +92 -95
  26. data/lib/capybara/queries/sibling_query.rb +4 -4
  27. data/lib/capybara/queries/text_query.rb +37 -34
  28. data/lib/capybara/queries/title_query.rb +8 -11
  29. data/lib/capybara/rack_test/browser.rb +15 -18
  30. data/lib/capybara/rack_test/css_handlers.rb +6 -4
  31. data/lib/capybara/rack_test/driver.rb +6 -10
  32. data/lib/capybara/rack_test/form.rb +50 -40
  33. data/lib/capybara/rack_test/node.rb +70 -56
  34. data/lib/capybara/rails.rb +2 -6
  35. data/lib/capybara/result.rb +22 -22
  36. data/lib/capybara/rspec.rb +5 -10
  37. data/lib/capybara/rspec/compound.rb +5 -10
  38. data/lib/capybara/rspec/features.rb +17 -48
  39. data/lib/capybara/rspec/matcher_proxies.rb +31 -15
  40. data/lib/capybara/rspec/matchers.rb +70 -60
  41. data/lib/capybara/selector.rb +129 -117
  42. data/lib/capybara/selector/css.rb +6 -11
  43. data/lib/capybara/selector/filter.rb +1 -17
  44. data/lib/capybara/selector/filter_set.rb +17 -14
  45. data/lib/capybara/selector/filters/base.rb +7 -6
  46. data/lib/capybara/selector/filters/expression_filter.rb +6 -23
  47. data/lib/capybara/selector/filters/node_filter.rb +2 -12
  48. data/lib/capybara/selector/selector.rb +27 -33
  49. data/lib/capybara/selenium/driver.rb +113 -127
  50. data/lib/capybara/selenium/node.rb +148 -113
  51. data/lib/capybara/server.rb +3 -2
  52. data/lib/capybara/session.rb +137 -223
  53. data/lib/capybara/session/config.rb +47 -67
  54. data/lib/capybara/session/matchers.rb +8 -7
  55. data/lib/capybara/spec/public/test.js +26 -4
  56. data/lib/capybara/spec/session/accept_alert_spec.rb +1 -0
  57. data/lib/capybara/spec/session/accept_confirm_spec.rb +3 -2
  58. data/lib/capybara/spec/session/accept_prompt_spec.rb +1 -0
  59. data/lib/capybara/spec/session/all_spec.rb +31 -18
  60. data/lib/capybara/spec/session/ancestor_spec.rb +2 -4
  61. data/lib/capybara/spec/session/assert_all_of_selectors_spec.rb +6 -5
  62. data/lib/capybara/spec/session/assert_current_path.rb +12 -11
  63. data/lib/capybara/spec/session/assert_selector.rb +1 -0
  64. data/lib/capybara/spec/session/assert_text.rb +18 -17
  65. data/lib/capybara/spec/session/assert_title.rb +1 -0
  66. data/lib/capybara/spec/session/attach_file_spec.rb +14 -13
  67. data/lib/capybara/spec/session/body_spec.rb +1 -0
  68. data/lib/capybara/spec/session/check_spec.rb +7 -6
  69. data/lib/capybara/spec/session/choose_spec.rb +5 -4
  70. data/lib/capybara/spec/session/click_button_spec.rb +20 -28
  71. data/lib/capybara/spec/session/click_link_or_button_spec.rb +8 -7
  72. data/lib/capybara/spec/session/click_link_spec.rb +8 -7
  73. data/lib/capybara/spec/session/current_scope_spec.rb +4 -3
  74. data/lib/capybara/spec/session/current_url_spec.rb +7 -6
  75. data/lib/capybara/spec/session/dismiss_confirm_spec.rb +1 -1
  76. data/lib/capybara/spec/session/dismiss_prompt_spec.rb +1 -0
  77. data/lib/capybara/spec/session/element/assert_match_selector.rb +1 -1
  78. data/lib/capybara/spec/session/element/match_xpath_spec.rb +1 -1
  79. data/lib/capybara/spec/session/element/matches_selector_spec.rb +5 -5
  80. data/lib/capybara/spec/session/evaluate_async_script_spec.rb +3 -2
  81. data/lib/capybara/spec/session/evaluate_script_spec.rb +4 -3
  82. data/lib/capybara/spec/session/execute_script_spec.rb +4 -3
  83. data/lib/capybara/spec/session/fill_in_spec.rb +6 -5
  84. data/lib/capybara/spec/session/find_button_spec.rb +4 -3
  85. data/lib/capybara/spec/session/find_by_id_spec.rb +2 -1
  86. data/lib/capybara/spec/session/find_field_spec.rb +8 -14
  87. data/lib/capybara/spec/session/find_link_spec.rb +6 -5
  88. data/lib/capybara/spec/session/find_spec.rb +37 -31
  89. data/lib/capybara/spec/session/first_spec.rb +60 -33
  90. data/lib/capybara/spec/session/frame/switch_to_frame_spec.rb +2 -1
  91. data/lib/capybara/spec/session/frame/within_frame_spec.rb +9 -16
  92. data/lib/capybara/spec/session/go_back_spec.rb +1 -0
  93. data/lib/capybara/spec/session/go_forward_spec.rb +1 -0
  94. data/lib/capybara/spec/session/has_all_selectors_spec.rb +15 -15
  95. data/lib/capybara/spec/session/has_button_spec.rb +2 -1
  96. data/lib/capybara/spec/session/has_css_spec.rb +3 -2
  97. data/lib/capybara/spec/session/has_current_path_spec.rb +12 -28
  98. data/lib/capybara/spec/session/has_field_spec.rb +4 -3
  99. data/lib/capybara/spec/session/has_link_spec.rb +1 -0
  100. data/lib/capybara/spec/session/has_none_selectors_spec.rb +17 -17
  101. data/lib/capybara/spec/session/has_select_spec.rb +30 -29
  102. data/lib/capybara/spec/session/has_selector_spec.rb +5 -4
  103. data/lib/capybara/spec/session/has_table_spec.rb +2 -1
  104. data/lib/capybara/spec/session/has_text_spec.rb +6 -5
  105. data/lib/capybara/spec/session/has_title_spec.rb +1 -0
  106. data/lib/capybara/spec/session/has_xpath_spec.rb +1 -0
  107. data/lib/capybara/spec/session/headers.rb +2 -1
  108. data/lib/capybara/spec/session/html_spec.rb +1 -0
  109. data/lib/capybara/spec/session/node_spec.rb +91 -56
  110. data/lib/capybara/spec/session/node_wrapper_spec.rb +36 -0
  111. data/lib/capybara/spec/session/refresh_spec.rb +4 -2
  112. data/lib/capybara/spec/session/reset_session_spec.rb +1 -0
  113. data/lib/capybara/spec/session/response_code.rb +1 -0
  114. data/lib/capybara/spec/session/save_and_open_page_spec.rb +1 -0
  115. data/lib/capybara/spec/session/save_and_open_screenshot_spec.rb +6 -11
  116. data/lib/capybara/spec/session/save_page_spec.rb +1 -17
  117. data/lib/capybara/spec/session/save_screenshot_spec.rb +1 -1
  118. data/lib/capybara/spec/session/select_spec.rb +20 -20
  119. data/lib/capybara/spec/session/selectors_spec.rb +2 -2
  120. data/lib/capybara/spec/session/sibling_spec.rb +1 -1
  121. data/lib/capybara/spec/session/text_spec.rb +1 -0
  122. data/lib/capybara/spec/session/title_spec.rb +1 -1
  123. data/lib/capybara/spec/session/uncheck_spec.rb +4 -3
  124. data/lib/capybara/spec/session/unselect_spec.rb +6 -5
  125. data/lib/capybara/spec/session/visit_spec.rb +9 -3
  126. data/lib/capybara/spec/session/window/become_closed_spec.rb +2 -1
  127. data/lib/capybara/spec/session/window/current_window_spec.rb +1 -0
  128. data/lib/capybara/spec/session/window/open_new_window_spec.rb +1 -0
  129. data/lib/capybara/spec/session/window/switch_to_window_spec.rb +2 -1
  130. data/lib/capybara/spec/session/window/window_opened_by_spec.rb +2 -1
  131. data/lib/capybara/spec/session/window/window_spec.rb +12 -12
  132. data/lib/capybara/spec/session/window/windows_spec.rb +2 -3
  133. data/lib/capybara/spec/session/window/within_window_spec.rb +13 -68
  134. data/lib/capybara/spec/session/within_spec.rb +1 -0
  135. data/lib/capybara/spec/spec_helper.rb +26 -18
  136. data/lib/capybara/spec/test_app.rb +8 -9
  137. data/lib/capybara/spec/views/form.erb +1 -0
  138. data/lib/capybara/spec/views/with_html.erb +3 -1
  139. data/lib/capybara/spec/views/within_frames.erb +4 -1
  140. data/lib/capybara/version.rb +2 -1
  141. data/lib/capybara/window.rb +6 -10
  142. data/spec/basic_node_spec.rb +1 -0
  143. data/spec/capybara_spec.rb +9 -32
  144. data/spec/dsl_spec.rb +5 -13
  145. data/spec/filter_set_spec.rb +5 -4
  146. data/spec/fixtures/selenium_driver_rspec_failure.rb +2 -1
  147. data/spec/fixtures/selenium_driver_rspec_success.rb +3 -2
  148. data/spec/minitest_spec.rb +4 -3
  149. data/spec/minitest_spec_spec.rb +3 -2
  150. data/spec/per_session_config_spec.rb +9 -8
  151. data/spec/rack_test_spec.rb +21 -20
  152. data/spec/result_spec.rb +17 -16
  153. data/spec/rspec/features_spec.rb +17 -14
  154. data/spec/rspec/scenarios_spec.rb +5 -7
  155. data/spec/rspec/shared_spec_matchers.rb +96 -99
  156. data/spec/rspec/views_spec.rb +2 -1
  157. data/spec/rspec_matchers_spec.rb +19 -2
  158. data/spec/rspec_spec.rb +11 -15
  159. data/spec/selector_spec.rb +5 -6
  160. data/spec/selenium_spec_chrome.rb +7 -4
  161. data/spec/selenium_spec_marionette.rb +26 -12
  162. data/spec/server_spec.rb +33 -33
  163. data/spec/session_spec.rb +2 -1
  164. data/spec/shared_selenium_session.rb +27 -21
  165. data/spec/spec_helper.rb +2 -5
  166. metadata +66 -87
  167. data/lib/capybara/query.rb +0 -7
  168. data/spec/selenium_spec_firefox.rb +0 -68
@@ -1,7 +1,8 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require 'spec_helper'
3
4
 
4
- RSpec.describe 'capybara/rspec', :type => :feature do
5
+ RSpec.describe 'capybara/rspec', type: :feature do
5
6
  it "should include Capybara in rspec" do
6
7
  visit('/foo')
7
8
  expect(page.body).to include('Another World')
@@ -37,21 +38,20 @@ RSpec.describe 'capybara/rspec', :type => :feature do
37
38
  expect(Capybara.current_driver).to eq(Capybara.javascript_driver)
38
39
  end
39
40
 
40
- it "switches to the given driver when giving it as metadata", :driver => :culerity do
41
+ it "switches to the given driver when giving it as metadata", driver: :culerity do
41
42
  expect(Capybara.current_driver).to eq(:culerity)
42
43
  end
43
44
 
44
45
  context "#all" do
45
46
  it "allows access to the Capybara finder" do
46
47
  visit('/with_html')
47
- expect(all(:css, 'h2.head').size).to eq(5)
48
+ found = all(:css, 'h2') { |element| element[:class] == 'head' }
49
+ expect(found.size).to eq(5)
48
50
  end
49
51
 
50
52
  it "allows access to the RSpec matcher" do
51
- skip "RSpec < 3 doesn't have an `all` matcher" if rspec2?
52
-
53
53
  visit('/with_html')
54
- expect(["test1", "test2"]).to all(be_a(String))
54
+ expect(%w[test1 test2]).to all(be_a(String))
55
55
  end
56
56
  end
57
57
 
@@ -64,7 +64,6 @@ RSpec.describe 'capybara/rspec', :type => :feature do
64
64
  end
65
65
 
66
66
  it "allows access to the RSpec matcher" do
67
- skip "RSpec version doesn't have a 'within' matcher" unless ::RSpec::Matchers.instance_methods.include?(:within)
68
67
  visit('/with_html')
69
68
  # This reads terribly, but must call #within
70
69
  expect(find(:css, 'span.number').text.to_i).to within(1).of(41)
@@ -72,15 +71,15 @@ RSpec.describe 'capybara/rspec', :type => :feature do
72
71
  end
73
72
  end
74
73
 
75
- RSpec.describe 'capybara/rspec', :type => :other do
74
+ RSpec.describe 'capybara/rspec', type: :other do
76
75
  context "when RSpec::Matchers is included after Capybara::DSL" do
77
76
  before do
78
- class DSL_MatchersTest
77
+ class DSLMatchersTest
79
78
  include Capybara::DSL
80
79
  include RSpec::Matchers
81
80
  end
82
81
 
83
- @test_class_instance = DSL_MatchersTest.new
82
+ @test_class_instance = DSLMatchersTest.new
84
83
  end
85
84
 
86
85
  context "#all" do
@@ -90,10 +89,8 @@ RSpec.describe 'capybara/rspec', :type => :other do
90
89
  end
91
90
 
92
91
  it "allows access to the RSpec matcher" do
93
- skip "RSpec < 3 doesn't have an `all` matcher" if rspec2?
94
-
95
92
  @test_class_instance.visit('/with_html')
96
- expect(["test1", "test2"]).to @test_class_instance.all(be_a(String))
93
+ expect(%w[test1 test2]).to @test_class_instance.all(be_a(String))
97
94
  end
98
95
  end
99
96
 
@@ -106,7 +103,6 @@ RSpec.describe 'capybara/rspec', :type => :other do
106
103
  end
107
104
 
108
105
  it "allows access to the RSpec matcher" do
109
- skip "RSpec version doesn't have a 'within' matcher" unless ::RSpec::Matchers.instance_methods.include?(:within)
110
106
  @test_class_instance.visit('/with_html')
111
107
  # This reads terribly, but must call #within
112
108
  expect(@test_class_instance.find(:css, 'span.number').text.to_i).to @test_class_instance.within(1).of(41)
@@ -115,7 +111,7 @@ RSpec.describe 'capybara/rspec', :type => :other do
115
111
  end
116
112
  end
117
113
 
118
- RSpec.describe 'capybara/rspec', :type => :other do
114
+ RSpec.describe 'capybara/rspec', type: :other do
119
115
  it "should not include Capybara" do
120
116
  expect { visit('/') }.to raise_error(NoMethodError)
121
117
  end
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require 'spec_helper'
3
4
 
4
5
  RSpec.describe Capybara do
@@ -56,7 +57,7 @@ RSpec.describe Capybara do
56
57
  it "can set default visiblity" do
57
58
  Capybara.add_selector :hidden_field do
58
59
  visible :hidden
59
- css { |sel| 'input[type="hidden"]' }
60
+ css { |_sel| 'input[type="hidden"]' }
60
61
  end
61
62
 
62
63
  expect(string).to have_no_css('input[type="hidden"]')
@@ -77,7 +78,7 @@ RSpec.describe Capybara do
77
78
 
78
79
  it "doesn't change existing filters" do
79
80
  Capybara.modify_selector :custom_selector do
80
- css { |css_class| "p.#{css_class}"}
81
+ css { |css_class| "p.#{css_class}" }
81
82
  end
82
83
  expect(string).to have_selector(:custom_selector, 'b', count: 1)
83
84
  expect(string).to have_selector(:custom_selector, 'b', not_empty: false, count: 1)
@@ -92,7 +93,7 @@ RSpec.describe Capybara do
92
93
  field: ".//*[self::input | self::textarea | self::select][not(./@type = 'submit' or ./@type = 'image' or ./@type = 'hidden')]",
93
94
  fieldset: ".//fieldset",
94
95
  link: ".//a[./@href]",
95
- link_or_button: ".//a[./@href] | .//input[./@type = 'submit' or ./@type = 'reset' or ./@type = 'image' or ./@type = 'button'] | .//button" ,
96
+ link_or_button: ".//a[./@href] | .//input[./@type = 'submit' or ./@type = 'reset' or ./@type = 'image' or ./@type = 'button'] | .//button",
96
97
  fillable_field: ".//*[self::input | self::textarea][not(./@type = 'submit' or ./@type = 'image' or ./@type = 'radio' or ./@type = 'checkbox' or ./@type = 'hidden' or ./@type = 'file')]",
97
98
  radio_button: ".//input[./@type = 'radio']",
98
99
  checkbox: ".//input[./@type = 'checkbox']",
@@ -102,7 +103,7 @@ RSpec.describe Capybara do
102
103
  table: ".//table"
103
104
  }
104
105
  selectors.each do |selector, xpath|
105
- results = string.all(selector,nil).to_a.map(&:native)
106
+ results = string.all(selector, nil).to_a.map(&:native)
106
107
  expect(results.size).to be > 0
107
108
  expect(results).to eq string.all(:xpath, xpath).to_a.map(&:native)
108
109
  end
@@ -116,7 +117,6 @@ RSpec.describe Capybara do
116
117
  end
117
118
 
118
119
  it "works with 'special' characters" do
119
- skip "We support old Nokogiris but they have their limits" if Gem::Version.new(Nokogiri::VERSION) < Gem::Version.new('1.6.8')
120
120
  expect(string.find(:custom_css_selector, "div", id: "#special")[:id]).to eq '#special'
121
121
  expect(string.find(:custom_css_selector, "input", id: "2checkbox")[:id]).to eq '2checkbox'
122
122
  end
@@ -129,7 +129,6 @@ RSpec.describe Capybara do
129
129
  end
130
130
 
131
131
  it "works with 'special' characters" do
132
- skip "We support old Nokogiris but they have their limits" if Gem::Version.new(Nokogiri::VERSION) < Gem::Version.new('1.6.8')
133
132
  expect(string.find(:custom_css_selector, "input", class: ".special")[:id]).to eq 'file'
134
133
  expect(string.find(:custom_css_selector, "input", class: "2checkbox")[:id]).to eq '2checkbox'
135
134
  end
@@ -1,9 +1,11 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require 'spec_helper'
3
4
  require 'selenium-webdriver'
4
5
  require 'shared_selenium_session'
6
+ require 'rspec/shared_spec_matchers'
5
7
 
6
- CHROME_DRIVER = if ENV['HEADLESS'] then :selenium_chrome_headless else :selenium_chrome end
8
+ CHROME_DRIVER = ENV['HEADLESS'] ? :selenium_chrome_headless : :selenium_chrome
7
9
 
8
10
  # if ENV['HEADLESS'] && ENV['TRAVIS']
9
11
  # Selenium::WebDriver::Chrome.path='/usr/bin/google-chrome-beta'
@@ -12,7 +14,7 @@ CHROME_DRIVER = if ENV['HEADLESS'] then :selenium_chrome_headless else :selenium
12
14
  Capybara.register_driver :selenium_chrome_clear_storage do |app|
13
15
  chrome_options = {
14
16
  browser: :chrome,
15
- options: ::Selenium::WebDriver::Chrome::Options.new()
17
+ options: ::Selenium::WebDriver::Chrome::Options.new
16
18
  }
17
19
  chrome_options[:options].args << 'headless' if ENV['HEADLESS']
18
20
  Capybara::Selenium::Driver.new(app, chrome_options.merge(clear_local_storage: true, clear_session_storage: true))
@@ -22,15 +24,16 @@ module TestSessions
22
24
  Chrome = Capybara::Session.new(CHROME_DRIVER, TestApp)
23
25
  end
24
26
 
25
- skipped_tests = [:response_headers, :status_code, :trigger]
27
+ skipped_tests = %i[response_headers status_code trigger]
26
28
  # skip window tests when headless for now - closing a window not supported by chromedriver/chrome
27
- skipped_tests << :windows if ENV['TRAVIS'] && (ENV['SKIP_WINDOW'] || ENV['HEADLESS'])
29
+ skipped_tests << :windows if ENV['TRAVIS'] && (ENV['SKIP_WINDOW'] || ENV['HEADLESS'])
28
30
 
29
31
  Capybara::SpecHelper.run_specs TestSessions::Chrome, CHROME_DRIVER.to_s, capybara_skip: skipped_tests
30
32
 
31
33
  RSpec.describe "Capybara::Session with chrome" do
32
34
  include Capybara::SpecHelper
33
35
  include_examples "Capybara::Session", TestSessions::Chrome, CHROME_DRIVER
36
+ include_examples Capybara::RSpecMatchers, TestSessions::Chrome, CHROME_DRIVER
34
37
 
35
38
  context "storage" do
36
39
  describe "#reset!" do
@@ -1,10 +1,11 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require 'spec_helper'
3
4
  require "selenium-webdriver"
4
5
  require 'shared_selenium_session'
5
6
  require 'rspec/shared_spec_matchers'
6
7
 
7
- browser_options = ::Selenium::WebDriver::Firefox::Options.new()
8
+ browser_options = ::Selenium::WebDriver::Firefox::Options.new
8
9
  browser_options.args << '--headless' if ENV['HEADLESS']
9
10
  browser_options.add_preference 'dom.file.createInChild', true
10
11
  # browser_options.add_option("log", {"level": "trace"})
@@ -14,7 +15,7 @@ Capybara.register_driver :selenium_marionette do |app|
14
15
  Capybara::Selenium::Driver.new(
15
16
  app,
16
17
  browser: :firefox,
17
- desired_capabilities: {marionette: true, 'moz:webdriverClick': true},
18
+ desired_capabilities: { marionette: true, 'moz:webdriverClick': true },
18
19
  options: browser_options
19
20
  # Get a trace level log from geckodriver
20
21
  # :driver_opts => { args: ['-vv'] }
@@ -25,24 +26,18 @@ Capybara.register_driver :selenium_marionette_clear_storage do |app|
25
26
  Capybara::Selenium::Driver.new(
26
27
  app,
27
28
  browser: :firefox,
28
- desired_capabilities: {marionette: true},
29
+ desired_capabilities: { marionette: true },
29
30
  clear_local_storage: true,
30
31
  clear_session_storage: true,
31
32
  options: browser_options
32
33
  )
33
34
  end
34
35
 
35
-
36
-
37
36
  module TestSessions
38
37
  SeleniumMarionette = Capybara::Session.new(:selenium_marionette, TestApp)
39
38
  end
40
39
 
41
- skipped_tests = [
42
- :response_headers,
43
- :status_code,
44
- :trigger
45
- ]
40
+ skipped_tests = %i[response_headers status_code trigger]
46
41
  skipped_tests << :windows if ENV['TRAVIS'] && ENV['SKIP_WINDOW']
47
42
 
48
43
  Capybara::SpecHelper.run_specs TestSessions::SeleniumMarionette, "selenium", capybara_skip: skipped_tests
@@ -62,7 +57,7 @@ RSpec.describe Capybara::Selenium::Driver do
62
57
  it "should reset browser when quit" do
63
58
  expect(@driver.browser).to be
64
59
  @driver.quit
65
- #access instance variable directly so we don't create a new browser instance
60
+ # access instance variable directly so we don't create a new browser instance
66
61
  expect(@driver.instance_variable_get(:@browser)).to be_nil
67
62
  end
68
63
 
@@ -123,5 +118,24 @@ RSpec.describe Capybara::Selenium::Driver do
123
118
  end
124
119
  end
125
120
  end
126
- end
127
121
 
122
+ context "#refresh" do
123
+ def extract_results(session)
124
+ expect(session).to have_xpath("//pre[@id='results']")
125
+ YAML.load Nokogiri::HTML(session.body).xpath("//pre[@id='results']").first.inner_html.lstrip
126
+ end
127
+
128
+ it "can repost by accepting confirm" do
129
+ @session = TestSessions::SeleniumMarionette
130
+ @session.visit('/form')
131
+ @session.select('Sweden', from: 'form_region')
132
+ @session.click_button('awesome')
133
+ expect do
134
+ @session.accept_confirm(wait: 0.1) do
135
+ @session.refresh
136
+ sleep 2
137
+ end
138
+ end.to change { extract_results(@session)['post_count'] }.by(1)
139
+ end
140
+ end
141
+ end
@@ -1,10 +1,10 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require 'spec_helper'
3
4
 
4
5
  RSpec.describe Capybara::Server do
5
-
6
6
  it "should spool up a rack server" do
7
- @app = proc { |env| [200, {}, ["Hello Server!"]]}
7
+ @app = proc { |_env| [200, {}, ["Hello Server!"]] }
8
8
  @server = Capybara::Server.new(@app).boot
9
9
 
10
10
  @res = Net::HTTP.start(@server.host, @server.port) { |http| http.get('/') }
@@ -19,8 +19,9 @@ RSpec.describe Capybara::Server do
19
19
  end
20
20
 
21
21
  it "should bind to the specified host" do
22
+ # TODO: travis with jruby in container mode has an issue with this test
22
23
  begin
23
- app = proc { |env| [200, {}, ['Hello Server!']] }
24
+ app = proc { |_env| [200, {}, ['Hello Server!']] }
24
25
 
25
26
  Capybara.server_host = '127.0.0.1'
26
27
  server = Capybara::Server.new(app).boot
@@ -34,12 +35,12 @@ RSpec.describe Capybara::Server do
34
35
  ensure
35
36
  Capybara.server_host = nil
36
37
  end
37
- end unless ENV['TRAVIS'] and (RUBY_ENGINE == 'jruby') #TODO travis with jruby in container mode has an issue with this test
38
+ end unless ENV['TRAVIS'] and (RUBY_ENGINE == 'jruby')
38
39
 
39
40
  it "should use specified port" do
40
41
  Capybara.server_port = 22789
41
42
 
42
- @app = proc { |env| [200, {}, ["Hello Server!"]]}
43
+ @app = proc { |_env| [200, {}, ["Hello Server!"]] }
43
44
  @server = Capybara::Server.new(@app).boot
44
45
 
45
46
  @res = Net::HTTP.start(@server.host, 22789) { |http| http.get('/') }
@@ -49,7 +50,7 @@ RSpec.describe Capybara::Server do
49
50
  end
50
51
 
51
52
  it "should use given port" do
52
- @app = proc { |env| [200, {}, ["Hello Server!"]]}
53
+ @app = proc { |_env| [200, {}, ["Hello Server!"]] }
53
54
  @server = Capybara::Server.new(@app, 22790).boot
54
55
 
55
56
  @res = Net::HTTP.start(@server.host, 22790) { |http| http.get('/') }
@@ -59,8 +60,8 @@ RSpec.describe Capybara::Server do
59
60
  end
60
61
 
61
62
  it "should find an available port" do
62
- @app1 = proc { |env| [200, {}, ["Hello Server!"]]}
63
- @app2 = proc { |env| [200, {}, ["Hello Second Server!"]]}
63
+ @app1 = proc { |_env| [200, {}, ["Hello Server!"]] }
64
+ @app2 = proc { |_env| [200, {}, ["Hello Second Server!"]] }
64
65
 
65
66
  @server1 = Capybara::Server.new(@app1).boot
66
67
  @server2 = Capybara::Server.new(@app2).boot
@@ -83,7 +84,7 @@ RSpec.describe Capybara::Server do
83
84
  end
84
85
 
85
86
  it "should use the existing server if it already running" do
86
- @app = proc { |env| [200, {}, ["Hello Server!"]]}
87
+ @app = proc { |_env| [200, {}, ["Hello Server!"]] }
87
88
 
88
89
  @server1 = Capybara::Server.new(@app).boot
89
90
  @server2 = Capybara::Server.new(@app).boot
@@ -98,27 +99,25 @@ RSpec.describe Capybara::Server do
98
99
  end
99
100
 
100
101
  it "detects and waits for all reused server sessions pending requests" do
101
- done = false
102
+ done = 0
102
103
 
103
104
  app = proc do |env|
104
105
  request = Rack::Request.new(env)
105
106
  sleep request.params['wait_time'].to_f
106
- done = true
107
+ done += 1
107
108
  [200, {}, ["Hello Server!"]]
108
109
  end
109
110
 
110
111
  server1 = Capybara::Server.new(app).boot
111
112
  server2 = Capybara::Server.new(app).boot
112
113
 
113
- start_request(server1, 0.5)
114
- start_request(server2, 1.0)
115
-
116
- expect {
114
+ expect do
115
+ start_request(server1, 1.0)
116
+ start_request(server2, 3.0)
117
117
  server1.wait_for_pending_requests
118
- }.to change{done}.from(false).to(true)
118
+ end.to change { done }.from(0).to(2)
119
119
  expect(server2.send(:pending_requests?)).to eq(false)
120
120
  end
121
-
122
121
  end
123
122
 
124
123
  context "When Capybara.reuse_server is false" do
@@ -132,7 +131,7 @@ RSpec.describe Capybara::Server do
132
131
  end
133
132
 
134
133
  it "should not reuse an already running server" do
135
- @app = proc { |env| [200, {}, ["Hello Server!"]]}
134
+ @app = proc { |_env| [200, {}, ["Hello Server!"]] }
136
135
 
137
136
  @server1 = Capybara::Server.new(@app).boot
138
137
  @server2 = Capybara::Server.new(@app).boot
@@ -147,48 +146,48 @@ RSpec.describe Capybara::Server do
147
146
  end
148
147
 
149
148
  it "detects and waits for only one sessions pending requests" do
150
- done = false
149
+ done = 0
151
150
 
152
151
  app = proc do |env|
153
152
  request = Rack::Request.new(env)
154
153
  sleep request.params['wait_time'].to_f
155
- done = true
154
+ done += 1
156
155
  [200, {}, ["Hello Server!"]]
157
156
  end
158
157
 
159
158
  server1 = Capybara::Server.new(app).boot
160
159
  server2 = Capybara::Server.new(app).boot
161
160
 
162
- start_request(server1, 0.5)
163
- start_request(server2, 1.0)
164
-
165
- expect {
161
+ expect do
162
+ start_request(server1, 1.0)
163
+ start_request(server2, 3.0)
166
164
  server1.wait_for_pending_requests
167
- }.to change{done}.from(false).to(true)
165
+ end.to change { done }.from(0).to(1)
168
166
  expect(server2.send(:pending_requests?)).to eq(true)
167
+ expect do
168
+ server2.wait_for_pending_requests
169
+ end.to change { done }.from(1).to(2)
169
170
  end
170
-
171
171
  end
172
172
 
173
173
  it "should raise server errors when the server errors before the timeout" do
174
174
  begin
175
- Capybara.server do
175
+ Capybara.register_server :kaboom do
176
176
  sleep 0.1
177
177
  raise 'kaboom'
178
178
  end
179
+ Capybara.server = :kaboom
179
180
 
180
181
  expect do
181
- Capybara::Server.new(proc {|e|}).boot
182
+ Capybara::Server.new(proc { |e| }).boot
182
183
  end.to raise_error(RuntimeError, 'kaboom')
183
184
  ensure
184
- # TODO refactor out the defaults so it's reliant on unset state instead of
185
- # a one-time call in capybara.rb
186
- Capybara.server {|app, port| Capybara.run_default_server(app, port)}
185
+ Capybara.server = :default
187
186
  end
188
187
  end
189
188
 
190
189
  it "is not #responsive? when Net::HTTP raises a SystemCallError" do
191
- app = lambda { [200, {}, ['Hello, world']] }
190
+ app = -> { [200, {}, ['Hello, world']] }
192
191
  server = Capybara::Server.new(app)
193
192
  expect(Net::HTTP).to receive(:start).and_raise(SystemCallError.allocate)
194
193
  expect(server.responsive?).to eq false
@@ -197,7 +196,8 @@ RSpec.describe Capybara::Server do
197
196
  def start_request(server, wait_time)
198
197
  # Start request, but don't wait for it to finish
199
198
  socket = TCPSocket.new(server.host, server.port)
200
- socket.write "GET /?wait_time=#{wait_time.to_s} HTTP/1.0\r\n\r\n"
199
+ socket.write "GET /?wait_time=#{wait_time} HTTP/1.0\r\n\r\n"
200
+ sleep 0.1
201
201
  socket.close
202
202
  sleep 0.1
203
203
  end
@@ -1,10 +1,11 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require 'spec_helper'
3
4
 
4
5
  RSpec.describe Capybara::Session do
5
6
  it "verifies a passed app is a rack app" do
6
7
  expect do
7
- Capybara::Session.new(:unknown, { random: "hash"})
8
+ Capybara::Session.new(:unknown, random: "hash")
8
9
  end.to raise_error TypeError, "The second parameter to Session::new should be a rack app if passed."
9
10
  end
10
11