capybara 3.26.0 → 3.27.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. checksums.yaml +4 -4
  2. data/History.md +18 -0
  3. data/README.md +1 -2
  4. data/lib/capybara/minitest.rb +29 -29
  5. data/lib/capybara/node/element.rb +2 -1
  6. data/lib/capybara/node/matchers.rb +6 -6
  7. data/lib/capybara/node/simple.rb +2 -1
  8. data/lib/capybara/queries/ancestor_query.rb +5 -9
  9. data/lib/capybara/queries/selector_query.rb +2 -2
  10. data/lib/capybara/queries/sibling_query.rb +4 -10
  11. data/lib/capybara/registrations/servers.rb +4 -1
  12. data/lib/capybara/selector/regexp_disassembler.rb +7 -0
  13. data/lib/capybara/selenium/atoms/isDisplayed.min.js +1 -1
  14. data/lib/capybara/selenium/atoms/src/isDisplayed.js +9 -9
  15. data/lib/capybara/selenium/driver.rb +2 -1
  16. data/lib/capybara/selenium/driver_specializations/chrome_driver.rb +9 -4
  17. data/lib/capybara/selenium/driver_specializations/edge_driver.rb +8 -6
  18. data/lib/capybara/selenium/driver_specializations/firefox_driver.rb +9 -0
  19. data/lib/capybara/selenium/nodes/chrome_node.rb +41 -5
  20. data/lib/capybara/selenium/nodes/firefox_node.rb +16 -0
  21. data/lib/capybara/selenium/patches/is_displayed.rb +16 -0
  22. data/lib/capybara/spec/session/node_spec.rb +40 -3
  23. data/lib/capybara/spec/views/with_html.erb +10 -0
  24. data/lib/capybara/version.rb +1 -1
  25. data/spec/basic_node_spec.rb +6 -6
  26. data/spec/capybara_spec.rb +28 -28
  27. data/spec/filter_set_spec.rb +5 -5
  28. data/spec/fixtures/selenium_driver_rspec_failure.rb +1 -1
  29. data/spec/fixtures/selenium_driver_rspec_success.rb +1 -1
  30. data/spec/rack_test_spec.rb +9 -9
  31. data/spec/regexp_dissassembler_spec.rb +12 -2
  32. data/spec/rspec/shared_spec_matchers.rb +2 -2
  33. data/spec/rspec_spec.rb +1 -1
  34. data/spec/selector_spec.rb +15 -15
  35. data/spec/selenium_spec_chrome.rb +38 -0
  36. data/spec/selenium_spec_firefox.rb +1 -1
  37. data/spec/server_spec.rb +18 -18
  38. data/spec/session_spec.rb +4 -4
  39. data/spec/shared_selenium_node.rb +36 -0
  40. metadata +3 -2
@@ -4,11 +4,11 @@ require 'spec_helper'
4
4
 
5
5
  RSpec.describe Capybara::Selector::FilterSet do
6
6
  after do
7
- Capybara::Selector::FilterSet.remove(:test)
7
+ described_class.remove(:test)
8
8
  end
9
9
 
10
10
  it 'allows node filters' do
11
- fs = Capybara::Selector::FilterSet.add(:test) do
11
+ fs = described_class.add(:test) do
12
12
  node_filter(:node_test, :boolean) { |_node, _value| true }
13
13
  expression_filter(:expression_test, :boolean) { |_expr, _value| true }
14
14
  end
@@ -18,7 +18,7 @@ RSpec.describe Capybara::Selector::FilterSet do
18
18
  end
19
19
 
20
20
  it 'allows expression filters' do
21
- fs = Capybara::Selector::FilterSet.add(:test) do
21
+ fs = described_class.add(:test) do
22
22
  node_filter(:node_test, :boolean) { |_node, _value| true }
23
23
  expression_filter(:expression_test, :boolean) { |_expr, _value| true }
24
24
  end
@@ -28,7 +28,7 @@ RSpec.describe Capybara::Selector::FilterSet do
28
28
  end
29
29
 
30
30
  it 'allows node filter and expression filter with the same name' do
31
- fs = Capybara::Selector::FilterSet.add(:test) do
31
+ fs = described_class.add(:test) do
32
32
  node_filter(:test, :boolean) { |_node, _value| true }
33
33
  expression_filter(:test, :boolean) { |_expr, _value| true }
34
34
  end
@@ -37,7 +37,7 @@ RSpec.describe Capybara::Selector::FilterSet do
37
37
  end
38
38
 
39
39
  it 'allows `filter` as an alias of `node_filter`' do
40
- fs = Capybara::Selector::FilterSet.add(:test) do
40
+ fs = described_class.add(:test) do
41
41
  filter(:node_test, :boolean) { |_node, _value| true }
42
42
  end
43
43
 
@@ -6,7 +6,7 @@ require 'selenium-webdriver'
6
6
  RSpec.describe Capybara::Selenium::Driver do
7
7
  it 'should exit with a non-zero exit status' do
8
8
  options = { browser: (ENV['SELENIUM_BROWSER'] || :firefox).to_sym }
9
- browser = Capybara::Selenium::Driver.new(TestApp, options).browser
9
+ browser = described_class.new(TestApp, options).browser
10
10
  expect(browser).to be_truthy
11
11
  expect(true).to eq(false) # rubocop:disable RSpec/ExpectActual
12
12
  end
@@ -6,7 +6,7 @@ require 'selenium-webdriver'
6
6
  RSpec.describe Capybara::Selenium::Driver do
7
7
  it 'should exit with a zero exit status' do
8
8
  options = { browser: (ENV['SELENIUM_BROWSER'] || :firefox).to_sym }
9
- browser = Capybara::Selenium::Driver.new(TestApp, options).browser
9
+ browser = described_class.new(TestApp, options).browser
10
10
  expect(browser).to be_truthy
11
11
  expect(true).to eq(true) # rubocop:disable RSpec/ExpectActual
12
12
  end
@@ -155,27 +155,27 @@ RSpec.describe Capybara::RackTest::Driver do
155
155
 
156
156
  describe ':headers option' do
157
157
  it 'should always set headers' do
158
- driver = Capybara::RackTest::Driver.new(TestApp, headers: { 'HTTP_FOO' => 'foobar' })
158
+ driver = described_class.new(TestApp, headers: { 'HTTP_FOO' => 'foobar' })
159
159
  driver.visit('/get_header')
160
160
  expect(driver.html).to include('foobar')
161
161
  end
162
162
 
163
163
  it 'should keep headers on link clicks' do
164
- driver = Capybara::RackTest::Driver.new(TestApp, headers: { 'HTTP_FOO' => 'foobar' })
164
+ driver = described_class.new(TestApp, headers: { 'HTTP_FOO' => 'foobar' })
165
165
  driver.visit('/header_links')
166
166
  driver.find_xpath('.//a').first.click
167
167
  expect(driver.html).to include('foobar')
168
168
  end
169
169
 
170
170
  it 'should keep headers on form submit' do
171
- driver = Capybara::RackTest::Driver.new(TestApp, headers: { 'HTTP_FOO' => 'foobar' })
171
+ driver = described_class.new(TestApp, headers: { 'HTTP_FOO' => 'foobar' })
172
172
  driver.visit('/header_links')
173
173
  driver.find_xpath('.//input').first.click
174
174
  expect(driver.html).to include('foobar')
175
175
  end
176
176
 
177
177
  it 'should keep headers on redirects' do
178
- driver = Capybara::RackTest::Driver.new(TestApp, headers: { 'HTTP_FOO' => 'foobar' })
178
+ driver = described_class.new(TestApp, headers: { 'HTTP_FOO' => 'foobar' })
179
179
  driver.visit('/get_header_via_redirect')
180
180
  expect(driver.html).to include('foobar')
181
181
  end
@@ -183,7 +183,7 @@ RSpec.describe Capybara::RackTest::Driver do
183
183
 
184
184
  describe ':follow_redirects option' do
185
185
  it 'defaults to following redirects' do
186
- driver = Capybara::RackTest::Driver.new(TestApp)
186
+ driver = described_class.new(TestApp)
187
187
 
188
188
  driver.visit('/redirect')
189
189
  expect(driver.response.header['Location']).to be_nil
@@ -191,7 +191,7 @@ RSpec.describe Capybara::RackTest::Driver do
191
191
  end
192
192
 
193
193
  it 'is possible to not follow redirects' do
194
- driver = Capybara::RackTest::Driver.new(TestApp, follow_redirects: false)
194
+ driver = described_class.new(TestApp, follow_redirects: false)
195
195
 
196
196
  driver.visit('/redirect')
197
197
  expect(driver.response.header['Location']).to match %r{/redirect_again$}
@@ -201,7 +201,7 @@ RSpec.describe Capybara::RackTest::Driver do
201
201
 
202
202
  describe ':redirect_limit option' do
203
203
  context 'with default redirect limit' do
204
- let(:driver) { Capybara::RackTest::Driver.new(TestApp) }
204
+ let(:driver) { described_class.new(TestApp) }
205
205
 
206
206
  it 'should follow 5 redirects' do
207
207
  driver.visit('/redirect/5/times')
@@ -216,7 +216,7 @@ RSpec.describe Capybara::RackTest::Driver do
216
216
  end
217
217
 
218
218
  context 'with 21 redirect limit' do
219
- let(:driver) { Capybara::RackTest::Driver.new(TestApp, redirect_limit: 21) }
219
+ let(:driver) { described_class.new(TestApp, redirect_limit: 21) }
220
220
 
221
221
  it 'should follow 21 redirects' do
222
222
  driver.visit('/redirect/21/times')
@@ -251,6 +251,6 @@ RSpec.describe Capybara::RackTest::CSSHandlers do
251
251
  include CSSHandlerIncludeTester
252
252
 
253
253
  it 'should not be extended by global includes' do
254
- expect(Capybara::RackTest::CSSHandlers.new).not_to respond_to(:dont_extend_css_handler)
254
+ expect(described_class.new).not_to respond_to(:dont_extend_css_handler)
255
255
  end
256
256
  end
@@ -44,7 +44,7 @@ RSpec.describe Capybara::Selector::RegexpDisassembler, :aggregate_failures do
44
44
  /abc?def?g/ => %w[ab de g],
45
45
  /d?/ => []
46
46
  }.each do |regexp, expected|
47
- expect(Capybara::Selector::RegexpDisassembler.new(regexp).substrings).to eq expected
47
+ expect(described_class.new(regexp).substrings).to eq expected
48
48
  end
49
49
  end
50
50
 
@@ -131,7 +131,7 @@ RSpec.describe Capybara::Selector::RegexpDisassembler, :aggregate_failures do
131
131
  /ab(cd|cd)?ef/ => %w[ab ef],
132
132
  /ab\\?cd/ => %w[ab cd]
133
133
  }.each do |regexp, expected|
134
- expect(Capybara::Selector::RegexpDisassembler.new(regexp).substrings).to eq expected
134
+ expect(described_class.new(regexp).substrings).to eq expected
135
135
  end
136
136
  end
137
137
 
@@ -212,6 +212,16 @@ RSpec.describe Capybara::Selector::RegexpDisassembler, :aggregate_failures do
212
212
  )
213
213
  end
214
214
 
215
+ it 'ignores negative lookaheads' do
216
+ verify_strings(
217
+ /^(?!.*\bContributing Editor\b).*$/ => %w[],
218
+ /abc(?!.*def).*/ => %w[abc],
219
+ /(?!.*def)abc/ => %w[abc],
220
+ /abc(?!.*def.*).*ghi/ => %w[abc ghi],
221
+ /abc(?!.*bcd)def/ => %w[abcdef]
222
+ )
223
+ end
224
+
215
225
  it 'handles anchors' do
216
226
  verify_strings(
217
227
  /^abc/ => %w[abc],
@@ -682,12 +682,12 @@ RSpec.shared_examples Capybara::RSpecMatchers do |session, _mode|
682
682
  end
683
683
 
684
684
  it 'treats a given value as a string' do
685
- class Foo
685
+ foo = Class.new do
686
686
  def to_s
687
687
  'some value'
688
688
  end
689
689
  end
690
- expect(html).to have_field('Text field', with: Foo.new)
690
+ expect(html).to have_field('Text field', with: foo.new)
691
691
  end
692
692
 
693
693
  it 'supports compounding' do
@@ -76,7 +76,7 @@ RSpec.describe 'capybara/rspec' do
76
76
  context 'Type: Other', type: :other do
77
77
  context 'when RSpec::Matchers is included after Capybara::DSL' do
78
78
  let(:test_class_instance) do
79
- class DSLMatchersTest
79
+ Class.new do
80
80
  include Capybara::DSL
81
81
  include RSpec::Matchers
82
82
  end.new
@@ -5,7 +5,7 @@ require 'spec_helper'
5
5
  RSpec.describe Capybara do
6
6
  describe 'Selectors' do
7
7
  let :string do
8
- Capybara.string <<-STRING
8
+ described_class.string <<-STRING
9
9
  <html>
10
10
  <head>
11
11
  <title>selectors</title>
@@ -69,12 +69,12 @@ RSpec.describe Capybara do
69
69
  end
70
70
 
71
71
  before do
72
- Capybara.add_selector :custom_selector do
72
+ described_class.add_selector :custom_selector do
73
73
  css { |css_class| "div.#{css_class}" }
74
74
  node_filter(:not_empty, boolean: true, default: true, skip_if: :all) { |node, value| value ^ (node.text == '') }
75
75
  end
76
76
 
77
- Capybara.add_selector :custom_css_selector do
77
+ described_class.add_selector :custom_css_selector do
78
78
  css(:name, :other_name) do |selector, name: nil, **|
79
79
  selector ||= ''
80
80
  selector += "[name='#{name}']" if name
@@ -94,7 +94,7 @@ RSpec.describe Capybara do
94
94
  end
95
95
  end
96
96
 
97
- Capybara.add_selector :custom_xpath_selector do
97
+ described_class.add_selector :custom_xpath_selector do
98
98
  xpath(:valid1, :valid2) { |selector| selector }
99
99
  match { |value| value == 'match_me' }
100
100
  end
@@ -102,7 +102,7 @@ RSpec.describe Capybara do
102
102
 
103
103
  it 'supports `filter` as an alias for `node_filter`' do
104
104
  expect do
105
- Capybara.add_selector :filter_alias_selector do
105
+ described_class.add_selector :filter_alias_selector do
106
106
  css { |_unused| 'div' }
107
107
  filter(:something) { |_node, _value| true }
108
108
  end
@@ -111,7 +111,7 @@ RSpec.describe Capybara do
111
111
 
112
112
  describe 'adding a selector' do
113
113
  it 'can set default visiblity' do
114
- Capybara.add_selector :hidden_field do
114
+ described_class.add_selector :hidden_field do
115
115
  visible :hidden
116
116
  css { |_sel| 'input[type="hidden"]' }
117
117
  end
@@ -125,7 +125,7 @@ RSpec.describe Capybara do
125
125
  it 'allows modifying a selector' do
126
126
  el = string.find(:custom_selector, 'aa')
127
127
  expect(el.tag_name).to eq 'div'
128
- Capybara.modify_selector :custom_selector do
128
+ described_class.modify_selector :custom_selector do
129
129
  css { |css_class| "h1.#{css_class}" }
130
130
  end
131
131
  el = string.find(:custom_selector, 'aa')
@@ -133,7 +133,7 @@ RSpec.describe Capybara do
133
133
  end
134
134
 
135
135
  it "doesn't change existing filters" do
136
- Capybara.modify_selector :custom_selector do
136
+ described_class.modify_selector :custom_selector do
137
137
  css { |css_class| "p.#{css_class}" }
138
138
  end
139
139
  expect(string).to have_selector(:custom_selector, 'bb', count: 1)
@@ -164,7 +164,7 @@ RSpec.describe Capybara do
164
164
 
165
165
  describe 'xpath' do
166
166
  it 'uses filter names passed in' do
167
- Capybara.add_selector :test do
167
+ described_class.add_selector :test do
168
168
  xpath(:something, :other) { |_locator| XPath.descendant }
169
169
  end
170
170
  selector = Capybara::Selector.new :test, config: nil, format: nil
@@ -173,7 +173,7 @@ RSpec.describe Capybara do
173
173
  end
174
174
 
175
175
  it 'gets filter names from block if none passed to xpath method' do
176
- Capybara.add_selector :test do
176
+ described_class.add_selector :test do
177
177
  xpath { |_locator, valid3:, valid4: nil| "#{valid3} #{valid4}" }
178
178
  end
179
179
  selector = Capybara::Selector.new :test, config: nil, format: nil
@@ -182,7 +182,7 @@ RSpec.describe Capybara do
182
182
  end
183
183
 
184
184
  it 'ignores block parameters if names passed in' do
185
- Capybara.add_selector :test do
185
+ described_class.add_selector :test do
186
186
  xpath(:valid1) { |_locator, valid3:, valid4: nil| "#{valid3} #{valid4}" }
187
187
  end
188
188
  selector = Capybara::Selector.new :test, config: nil, format: nil
@@ -205,7 +205,7 @@ RSpec.describe Capybara do
205
205
  end
206
206
 
207
207
  it 'uses filter names passed in' do
208
- Capybara.add_selector :test do
208
+ described_class.add_selector :test do
209
209
  css(:name, :other_name) { |_locator| '' }
210
210
  end
211
211
  selector = Capybara::Selector.new :test, config: nil, format: nil
@@ -214,7 +214,7 @@ RSpec.describe Capybara do
214
214
  end
215
215
 
216
216
  it 'gets filter names from block if none passed to css method' do
217
- Capybara.add_selector :test do
217
+ described_class.add_selector :test do
218
218
  css { |_locator, valid3:, valid4: nil| "#{valid3} #{valid4}" }
219
219
  end
220
220
  selector = Capybara::Selector.new :test, config: nil, format: nil
@@ -223,7 +223,7 @@ RSpec.describe Capybara do
223
223
  end
224
224
 
225
225
  it 'ignores block parameters if names passed in' do
226
- Capybara.add_selector :test do
226
+ described_class.add_selector :test do
227
227
  css(:valid1) { |_locator, valid3:, valid4: nil| "#{valid3} #{valid4}" }
228
228
  end
229
229
  selector = Capybara::Selector.new :test, config: nil, format: nil
@@ -477,7 +477,7 @@ RSpec.describe Capybara do
477
477
 
478
478
  describe ':link_or_button selector' do
479
479
  around(:all) do |example|
480
- Capybara.modify_selector(:link_or_button) do
480
+ described_class.modify_selector(:link_or_button) do
481
481
  expression_filter(:random) { |xpath, _| xpath } # do nothing filter
482
482
  end
483
483
  example.run
@@ -28,6 +28,22 @@ Capybara.register_driver :selenium_chrome_not_clear_storage do |app|
28
28
  Capybara::Selenium::Driver.new(app, chrome_options.merge(clear_local_storage: false, clear_session_storage: false))
29
29
  end
30
30
 
31
+ Capybara.register_driver :selenium_chrome_not_clear_session_storage do |app|
32
+ chrome_options = {
33
+ browser: :chrome,
34
+ options: browser_options
35
+ }
36
+ Capybara::Selenium::Driver.new(app, chrome_options.merge(clear_session_storage: false))
37
+ end
38
+
39
+ Capybara.register_driver :selenium_chrome_not_clear_local_storage do |app|
40
+ chrome_options = {
41
+ browser: :chrome,
42
+ options: browser_options
43
+ }
44
+ Capybara::Selenium::Driver.new(app, chrome_options.merge(clear_local_storage: false))
45
+ end
46
+
31
47
  Capybara.register_driver :selenium_driver_subclass_with_chrome do |app|
32
48
  subclass = Class.new(Capybara::Selenium::Driver)
33
49
  subclass.new(app, browser: :chrome, options: browser_options, timeout: 30)
@@ -47,6 +63,8 @@ Capybara::SpecHelper.run_specs TestSessions::Chrome, CHROME_DRIVER.to_s, capybar
47
63
  skip 'Need to figure out testing of file downloading on windows platform' if Gem.win_platform?
48
64
  when /Capybara::Session selenium_chrome Capybara::Window#maximize/
49
65
  pending "Chrome headless doesn't support maximize" if ENV['HEADLESS']
66
+ when /details non-summary descendants should be non-visible/
67
+ pending 'Chromedriver built-in is_displayed is currently broken' if ENV['W3C'] == 'false'
50
68
  end
51
69
  end
52
70
 
@@ -77,6 +95,26 @@ RSpec.describe 'Capybara::Session with chrome' do
77
95
  expect(session.evaluate_script('Object.keys(localStorage)')).not_to be_empty
78
96
  expect(session.evaluate_script('Object.keys(sessionStorage)')).not_to be_empty
79
97
  end
98
+
99
+ it 'can not clear session storage' do
100
+ session = Capybara::Session.new(:selenium_chrome_not_clear_session_storage, TestApp)
101
+ session.visit('/with_js')
102
+ session.find(:css, '#set-storage').click
103
+ session.reset!
104
+ session.visit('/with_js')
105
+ expect(session.evaluate_script('Object.keys(localStorage)')).to be_empty
106
+ expect(session.evaluate_script('Object.keys(sessionStorage)')).not_to be_empty
107
+ end
108
+
109
+ it 'can not clear local storage' do
110
+ session = Capybara::Session.new(:selenium_chrome_not_clear_local_storage, TestApp)
111
+ session.visit('/with_js')
112
+ session.find(:css, '#set-storage').click
113
+ session.reset!
114
+ session.visit('/with_js')
115
+ expect(session.evaluate_script('Object.keys(localStorage)')).not_to be_empty
116
+ expect(session.evaluate_script('Object.keys(sessionStorage)')).to be_empty
117
+ end
80
118
  end
81
119
  end
82
120
 
@@ -106,7 +106,7 @@ RSpec.describe 'Capybara::Session with firefox' do # rubocop:disable RSpec/Multi
106
106
  end
107
107
 
108
108
  RSpec.describe Capybara::Selenium::Driver do
109
- let(:driver) { Capybara::Selenium::Driver.new(TestApp, browser: :firefox, options: browser_options) }
109
+ let(:driver) { described_class.new(TestApp, browser: :firefox, options: browser_options) }
110
110
 
111
111
  describe '#quit' do
112
112
  it 'should reset browser when quit' do
@@ -5,7 +5,7 @@ require 'spec_helper'
5
5
  RSpec.describe Capybara::Server do
6
6
  it 'should spool up a rack server' do
7
7
  app = proc { |_env| [200, {}, ['Hello Server!']] }
8
- server = Capybara::Server.new(app).boot
8
+ server = described_class.new(app).boot
9
9
 
10
10
  res = Net::HTTP.start(server.host, server.port) { |http| http.get('/') }
11
11
 
@@ -14,7 +14,7 @@ RSpec.describe Capybara::Server do
14
14
 
15
15
  it 'should do nothing when no server given' do
16
16
  expect do
17
- Capybara::Server.new(nil).boot
17
+ described_class.new(nil).boot
18
18
  end.not_to raise_error
19
19
  end
20
20
 
@@ -26,12 +26,12 @@ RSpec.describe Capybara::Server do
26
26
  app = proc { |_env| [200, {}, ['Hello Server!']] }
27
27
 
28
28
  Capybara.server_host = '127.0.0.1'
29
- server = Capybara::Server.new(app).boot
29
+ server = described_class.new(app).boot
30
30
  res = Net::HTTP.get(URI("http://127.0.0.1:#{server.port}"))
31
31
  expect(res).to eq('Hello Server!')
32
32
 
33
33
  Capybara.server_host = '0.0.0.0'
34
- server = Capybara::Server.new(app).boot
34
+ server = described_class.new(app).boot
35
35
  res = Net::HTTP.get(URI("http://127.0.0.1:#{server.port}"))
36
36
  expect(res).to eq('Hello Server!')
37
37
  ensure
@@ -43,7 +43,7 @@ RSpec.describe Capybara::Server do
43
43
  Capybara.server_port = 22789
44
44
 
45
45
  app = proc { |_env| [200, {}, ['Hello Server!']] }
46
- server = Capybara::Server.new(app).boot
46
+ server = described_class.new(app).boot
47
47
 
48
48
  res = Net::HTTP.start(server.host, 22789) { |http| http.get('/') }
49
49
  expect(res.body).to include('Hello Server')
@@ -53,7 +53,7 @@ RSpec.describe Capybara::Server do
53
53
 
54
54
  it 'should use given port' do
55
55
  app = proc { |_env| [200, {}, ['Hello Server!']] }
56
- server = Capybara::Server.new(app, port: 22790).boot
56
+ server = described_class.new(app, port: 22790).boot
57
57
 
58
58
  res = Net::HTTP.start(server.host, 22790) { |http| http.get('/') }
59
59
  expect(res.body).to include('Hello Server')
@@ -66,7 +66,7 @@ RSpec.describe Capybara::Server do
66
66
  apps = responses.map do |response|
67
67
  proc { |_env| [200, {}, [response]] }
68
68
  end
69
- servers = apps.map { |app| Capybara::Server.new(app).boot }
69
+ servers = apps.map { |app| described_class.new(app).boot }
70
70
 
71
71
  servers.each_with_index do |server, idx|
72
72
  result = Net::HTTP.start(server.host, server.port) { |http| http.get('/') }
@@ -76,7 +76,7 @@ RSpec.describe Capybara::Server do
76
76
 
77
77
  it 'should return its #base_url' do
78
78
  app = proc { |_env| [200, {}, ['Hello Server!']] }
79
- server = Capybara::Server.new(app).boot
79
+ server = described_class.new(app).boot
80
80
  uri = ::Addressable::URI.parse(server.base_url)
81
81
  expect(uri.to_hash).to include(scheme: 'http', host: server.host, port: server.port)
82
82
  end
@@ -87,7 +87,7 @@ RSpec.describe Capybara::Server do
87
87
  cert = File.join(Dir.pwd, 'spec', 'fixtures', 'certificate.pem')
88
88
  Capybara.server = :puma, { Host: "ssl://#{Capybara.server_host}?key=#{key}&cert=#{cert}" }
89
89
  app = proc { |_env| [200, {}, ['Hello SSL Server!']] }
90
- server = Capybara::Server.new(app).boot
90
+ server = described_class.new(app).boot
91
91
 
92
92
  expect do
93
93
  Net::HTTP.start(server.host, server.port, max_retries: 0) { |http| http.get('/__identify__') }
@@ -121,7 +121,7 @@ RSpec.describe Capybara::Server do
121
121
  it 'should use the existing server if it already running' do
122
122
  app = proc { |_env| [200, {}, ['Hello Server!']] }
123
123
 
124
- servers = Array.new(2) { Capybara::Server.new(app).boot }
124
+ servers = Array.new(2) { described_class.new(app).boot }
125
125
 
126
126
  servers.each do |server|
127
127
  res = Net::HTTP.start(server.host, server.port) { |http| http.get('/') }
@@ -141,8 +141,8 @@ RSpec.describe Capybara::Server do
141
141
  [200, {}, ['Hello Server!']]
142
142
  end
143
143
 
144
- server1 = Capybara::Server.new(app).boot
145
- server2 = Capybara::Server.new(app).boot
144
+ server1 = described_class.new(app).boot
145
+ server2 = described_class.new(app).boot
146
146
 
147
147
  expect do
148
148
  start_request(server1, 1.0)
@@ -166,7 +166,7 @@ RSpec.describe Capybara::Server do
166
166
  it 'should not reuse an already running server' do
167
167
  app = proc { |_env| [200, {}, ['Hello Server!']] }
168
168
 
169
- servers = Array.new(2) { Capybara::Server.new(app).boot }
169
+ servers = Array.new(2) { described_class.new(app).boot }
170
170
 
171
171
  servers.each do |server|
172
172
  res = Net::HTTP.start(server.host, server.port) { |http| http.get('/') }
@@ -186,8 +186,8 @@ RSpec.describe Capybara::Server do
186
186
  [200, {}, ['Hello Server!']]
187
187
  end
188
188
 
189
- server1 = Capybara::Server.new(app).boot
190
- server2 = Capybara::Server.new(app).boot
189
+ server1 = described_class.new(app).boot
190
+ server2 = described_class.new(app).boot
191
191
 
192
192
  expect do
193
193
  start_request(server1, 1.0)
@@ -210,7 +210,7 @@ RSpec.describe Capybara::Server do
210
210
  Capybara.server = :kaboom
211
211
 
212
212
  expect do
213
- Capybara::Server.new(proc { |e| }).boot
213
+ described_class.new(proc { |e| }).boot
214
214
  end.to raise_error(RuntimeError, 'kaboom')
215
215
  ensure
216
216
  Capybara.server = :default
@@ -219,7 +219,7 @@ RSpec.describe Capybara::Server do
219
219
 
220
220
  it 'is not #responsive? when Net::HTTP raises a SystemCallError' do
221
221
  app = -> { [200, {}, ['Hello, world']] }
222
- server = Capybara::Server.new(app)
222
+ server = described_class.new(app)
223
223
  allow(Net::HTTP).to receive(:start).and_raise(SystemCallError.allocate)
224
224
  expect(server.responsive?).to eq false
225
225
  end
@@ -234,7 +234,7 @@ RSpec.describe Capybara::Server do
234
234
  response = Net::HTTPSuccess.allocate
235
235
  allow(response).to receive(:body).and_return app.object_id.to_s
236
236
  allow(Net::HTTP).to receive(:start).with(anything, anything, hash_including(use_ssl: true)).and_return(response).once
237
- Capybara::Server.new(app).boot
237
+ described_class.new(app).boot
238
238
  expect(Net::HTTP).to have_received(:start).exactly(3).times
239
239
  end
240
240
  end