capybara 3.30.0 → 3.33.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (96) hide show
  1. checksums.yaml +4 -4
  2. data/History.md +72 -0
  3. data/README.md +10 -3
  4. data/lib/capybara.rb +17 -7
  5. data/lib/capybara/cucumber.rb +1 -1
  6. data/lib/capybara/dsl.rb +10 -2
  7. data/lib/capybara/minitest.rb +232 -144
  8. data/lib/capybara/minitest/spec.rb +153 -97
  9. data/lib/capybara/node/actions.rb +16 -20
  10. data/lib/capybara/node/element.rb +13 -8
  11. data/lib/capybara/node/finders.rb +5 -1
  12. data/lib/capybara/node/matchers.rb +28 -21
  13. data/lib/capybara/node/simple.rb +1 -1
  14. data/lib/capybara/queries/base_query.rb +2 -1
  15. data/lib/capybara/queries/selector_query.rb +8 -1
  16. data/lib/capybara/queries/style_query.rb +1 -1
  17. data/lib/capybara/queries/text_query.rb +6 -0
  18. data/lib/capybara/rack_test/browser.rb +3 -1
  19. data/lib/capybara/rack_test/node.rb +34 -9
  20. data/lib/capybara/registration_container.rb +44 -0
  21. data/lib/capybara/registrations/servers.rb +1 -1
  22. data/lib/capybara/result.rb +29 -5
  23. data/lib/capybara/rspec/matcher_proxies.rb +4 -4
  24. data/lib/capybara/rspec/matchers.rb +27 -27
  25. data/lib/capybara/rspec/matchers/base.rb +12 -6
  26. data/lib/capybara/rspec/matchers/count_sugar.rb +2 -1
  27. data/lib/capybara/rspec/matchers/have_ancestor.rb +4 -3
  28. data/lib/capybara/rspec/matchers/have_current_path.rb +2 -2
  29. data/lib/capybara/rspec/matchers/have_selector.rb +15 -7
  30. data/lib/capybara/rspec/matchers/have_sibling.rb +3 -3
  31. data/lib/capybara/rspec/matchers/have_text.rb +3 -3
  32. data/lib/capybara/rspec/matchers/have_title.rb +2 -2
  33. data/lib/capybara/rspec/matchers/match_selector.rb +3 -3
  34. data/lib/capybara/rspec/matchers/match_style.rb +2 -2
  35. data/lib/capybara/rspec/matchers/spatial_sugar.rb +2 -1
  36. data/lib/capybara/selector.rb +12 -1
  37. data/lib/capybara/selector/definition.rb +5 -4
  38. data/lib/capybara/selector/definition/button.rb +1 -0
  39. data/lib/capybara/selector/definition/fillable_field.rb +1 -1
  40. data/lib/capybara/selector/definition/label.rb +1 -1
  41. data/lib/capybara/selector/definition/link.rb +8 -0
  42. data/lib/capybara/selector/definition/select.rb +31 -12
  43. data/lib/capybara/selector/definition/table.rb +1 -1
  44. data/lib/capybara/selector/selector.rb +4 -0
  45. data/lib/capybara/selenium/atoms/getAttribute.min.js +1 -1
  46. data/lib/capybara/selenium/atoms/src/getAttribute.js +1 -1
  47. data/lib/capybara/selenium/driver.rb +7 -4
  48. data/lib/capybara/selenium/driver_specializations/chrome_driver.rb +8 -10
  49. data/lib/capybara/selenium/driver_specializations/edge_driver.rb +7 -9
  50. data/lib/capybara/selenium/driver_specializations/firefox_driver.rb +2 -2
  51. data/lib/capybara/selenium/extensions/html5_drag.rb +24 -8
  52. data/lib/capybara/selenium/node.rb +92 -15
  53. data/lib/capybara/selenium/nodes/chrome_node.rb +4 -11
  54. data/lib/capybara/selenium/nodes/edge_node.rb +1 -1
  55. data/lib/capybara/selenium/nodes/firefox_node.rb +3 -3
  56. data/lib/capybara/selenium/patches/action_pauser.rb +26 -0
  57. data/lib/capybara/selenium/patches/logs.rb +3 -5
  58. data/lib/capybara/session.rb +33 -18
  59. data/lib/capybara/session/config.rb +3 -1
  60. data/lib/capybara/spec/public/test.js +58 -6
  61. data/lib/capybara/spec/session/all_spec.rb +45 -5
  62. data/lib/capybara/spec/session/assert_text_spec.rb +5 -5
  63. data/lib/capybara/spec/session/click_button_spec.rb +11 -0
  64. data/lib/capybara/spec/session/fill_in_spec.rb +29 -0
  65. data/lib/capybara/spec/session/find_spec.rb +11 -8
  66. data/lib/capybara/spec/session/has_button_spec.rb +16 -0
  67. data/lib/capybara/spec/session/has_css_spec.rb +12 -9
  68. data/lib/capybara/spec/session/has_current_path_spec.rb +2 -2
  69. data/lib/capybara/spec/session/has_field_spec.rb +16 -0
  70. data/lib/capybara/spec/session/has_select_spec.rb +32 -4
  71. data/lib/capybara/spec/session/has_selector_spec.rb +4 -4
  72. data/lib/capybara/spec/session/has_text_spec.rb +5 -1
  73. data/lib/capybara/spec/session/node_spec.rb +146 -30
  74. data/lib/capybara/spec/session/window/window_spec.rb +7 -7
  75. data/lib/capybara/spec/spec_helper.rb +2 -2
  76. data/lib/capybara/spec/test_app.rb +14 -18
  77. data/lib/capybara/spec/views/form.erb +13 -2
  78. data/lib/capybara/spec/views/with_dragula.erb +3 -1
  79. data/lib/capybara/spec/views/with_html.erb +2 -2
  80. data/lib/capybara/spec/views/with_js.erb +1 -0
  81. data/lib/capybara/version.rb +1 -1
  82. data/spec/capybara_spec.rb +1 -1
  83. data/spec/dsl_spec.rb +14 -1
  84. data/spec/minitest_spec.rb +1 -1
  85. data/spec/rack_test_spec.rb +13 -1
  86. data/spec/regexp_dissassembler_spec.rb +0 -4
  87. data/spec/result_spec.rb +40 -29
  88. data/spec/rspec/shared_spec_matchers.rb +65 -53
  89. data/spec/selector_spec.rb +1 -1
  90. data/spec/selenium_spec_chrome.rb +6 -3
  91. data/spec/selenium_spec_chrome_remote.rb +2 -0
  92. data/spec/server_spec.rb +41 -49
  93. data/spec/shared_selenium_node.rb +18 -0
  94. data/spec/shared_selenium_session.rb +25 -7
  95. data/spec/spec_helper.rb +1 -1
  96. metadata +5 -3
@@ -141,12 +141,12 @@ Capybara::SpecHelper.spec Capybara::Window, requires: [:windows] do
141
141
  end
142
142
 
143
143
  describe '#maximize' do
144
- before do
145
- @initial_size = @session.current_window.size
144
+ let! :initial_size do
145
+ @session.current_window.size
146
146
  end
147
147
 
148
148
  after do
149
- @session.current_window.resize_to(*@initial_size)
149
+ @session.current_window.resize_to(*initial_size)
150
150
  sleep 0.5
151
151
  end
152
152
 
@@ -176,7 +176,7 @@ Capybara::SpecHelper.spec Capybara::Window, requires: [:windows] do
176
176
 
177
177
  expect(@session.current_window).to eq(orig_window)
178
178
  # Maximizing the browser affects all tabs so this may not be valid in real browsers
179
- # expect(@session.current_window.size).to eq(@initial_size)
179
+ # expect(@session.current_window.size).to eq(initial_size)
180
180
 
181
181
  ow_width, ow_height = other_window.size
182
182
  expect(ow_width).to be > 400
@@ -185,12 +185,12 @@ Capybara::SpecHelper.spec Capybara::Window, requires: [:windows] do
185
185
  end
186
186
 
187
187
  describe '#fullscreen' do
188
- before do
189
- @initial_size = @session.current_window.size
188
+ let! :initial_size do
189
+ @session.current_window.size
190
190
  end
191
191
 
192
192
  after do
193
- @session.current_window.resize_to(*@initial_size)
193
+ @session.current_window.resize_to(*initial_size)
194
194
  sleep 1
195
195
  end
196
196
 
@@ -30,6 +30,7 @@ module Capybara
30
30
  Capybara.visible_text_only = false
31
31
  Capybara.match = :smart
32
32
  Capybara.enable_aria_label = false
33
+ Capybara.enable_aria_role = false
33
34
  Capybara.default_set_options = {}
34
35
  Capybara.disable_animation = false
35
36
  Capybara.test_id = nil
@@ -60,7 +61,7 @@ module Capybara
60
61
  RSpec.describe Capybara::Session, name, options do # rubocop:disable RSpec/EmptyExampleGroup
61
62
  include Capybara::SpecHelper
62
63
  include Capybara::RSpecMatchers
63
- # rubocop:disable RSpec/ScatteredSetup
64
+
64
65
  before do |example|
65
66
  @session = session
66
67
  instance_exec(example, &filter_block) if filter_block
@@ -81,7 +82,6 @@ module Capybara
81
82
  before :each, :exact_false do
82
83
  Capybara.exact = false
83
84
  end
84
- # rubocop:enable RSpec/ScatteredSetup
85
85
 
86
86
  specs.each do |spec_name, spec_options, block|
87
87
  describe spec_name, *spec_options do # rubocop:disable RSpec/EmptyExampleGroup
@@ -188,28 +188,24 @@ class TestApp < Sinatra::Base
188
188
  end
189
189
 
190
190
  post '/upload' do
191
- begin
192
- buffer = []
193
- buffer << "Content-type: #{params.dig(:form, :document, :type)}"
194
- buffer << "File content: #{params.dig(:form, :document, :tempfile).read}"
195
- buffer.join(' | ')
196
- rescue StandardError
197
- 'No file uploaded'
198
- end
191
+ buffer = []
192
+ buffer << "Content-type: #{params.dig(:form, :document, :type)}"
193
+ buffer << "File content: #{params.dig(:form, :document, :tempfile).read}"
194
+ buffer.join(' | ')
195
+ rescue StandardError
196
+ 'No file uploaded'
199
197
  end
200
198
 
201
199
  post '/upload_multiple' do
202
- begin
203
- docs = params.dig(:form, :multiple_documents)
204
- buffer = [docs.size.to_s]
205
- docs.each do |doc|
206
- buffer << "Content-type: #{doc[:type]}"
207
- buffer << "File content: #{doc[:tempfile].read}"
208
- end
209
- buffer.join(' | ')
210
- rescue StandardError
211
- 'No files uploaded'
200
+ docs = params.dig(:form, :multiple_documents)
201
+ buffer = [docs.size.to_s]
202
+ docs.each do |doc|
203
+ buffer << "Content-type: #{doc[:type]}"
204
+ buffer << "File content: #{doc[:tempfile].read}"
212
205
  end
206
+ buffer.join(' | ')
207
+ rescue StandardError
208
+ 'No files uploaded'
213
209
  end
214
210
 
215
211
  get '/apple-touch-icon-precomposed.png' do
@@ -11,7 +11,7 @@
11
11
  <option>Miss</option>
12
12
  <option disabled="disabled">Other</option>
13
13
  </select>
14
- </p>
14
+ </p>
15
15
 
16
16
  <p>
17
17
  <label for="customer_name">Customer Name
@@ -62,6 +62,11 @@
62
62
  <input type="text" name="form[name]" value="John Smith" id="form_name"/>
63
63
  </p>
64
64
 
65
+ <p>
66
+ <label for="form_age">Age</label>
67
+ <input type="range" name="form[age]" value="18" min="13" max="100" step="0.5" id="form_age"/>
68
+ </p>
69
+
65
70
  <p>
66
71
  <label for="form_schmooo">Schmooo</label>
67
72
  <input type="schmooo" name="form[schmooo]" value="This is Schmooo!" id="form_schmooo"/>
@@ -135,7 +140,11 @@
135
140
 
136
141
  <p>
137
142
  <label for="form_zipcode">Zipcode</label>
138
- <input type="text" maxlength="5" name="form[zipcode]" id="form_zipcode" />
143
+ <input type="text" maxlength="5" name="form[zipcode]" id="form_zipcode" pattern="[0-9]{5,9}" />
144
+ </p>
145
+
146
+ <p>
147
+ <input maxlength="35" id="long_length" />
139
148
  </p>
140
149
 
141
150
  <p>
@@ -448,6 +457,7 @@ New line after and before textarea tag
448
457
  <button id="no_type">No Type!</button>
449
458
  <button><img alt="A horse eating hay"/></button>
450
459
  <input type="button" disabled="disabled" value="Disabled button"/>
460
+ <span role="button">ARIA button</span>
451
461
  </p>
452
462
 
453
463
  <p>
@@ -512,6 +522,7 @@ New line after and before textarea tag
512
522
 
513
523
  <p>
514
524
  <input type="submit" name="form[mediocre]" id="mediocre" value="med" aria-label="Mediocre Button"/>
525
+ <input type="submit" formaction="/form/get?bar=foo" id="mediocre2" value="med2"/>
515
526
  <p>
516
527
  </form>
517
528
 
@@ -15,7 +15,9 @@
15
15
  </div>
16
16
  <script src="https://cdnjs.cloudflare.com/ajax/libs/dragula/3.7.2/dragula.js" type="text/javascript"></script>
17
17
  <script>
18
- dragula([document.getElementById("sortable")]);
18
+ let container = document.getElementById("sortable");
19
+ dragula([container]);
20
+ container.className = "ready"
19
21
  </script>
20
22
  </body>
21
23
  </html>
@@ -36,8 +36,8 @@
36
36
  </p>
37
37
 
38
38
  <p>
39
- <input type="text" id="test_field" data-test-id="test_id" value="monkey"/>
40
- <input type="text" readonly="readonly" value="should not change" />
39
+ <input type="text" id="test_field" spellcheck="TRUE" data-test-id="test_id" value="monkey"/>
40
+ <input type="text" readonly="readonly" spellcheck="FALSE" value="should not change" />
41
41
  <textarea id="normal" data-other-test-id="test_id">
42
42
  banana</textarea>
43
43
  <textarea id="additional_newline">
@@ -35,6 +35,7 @@
35
35
 
36
36
  <p><a href="#" id="clickable">Click me</a></p>
37
37
  <p><a href="#" id="slow-click">Slowly</a></p>
38
+ <p><span id="aria-button" role="button">ARIA button</span></p>
38
39
 
39
40
  <p>
40
41
  <select id="waiter">
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Capybara
4
- VERSION = '3.30.0'
4
+ VERSION = '3.33.0'
5
5
  end
@@ -32,7 +32,7 @@ RSpec.describe Capybara do
32
32
  # do nothing
33
33
  end
34
34
 
35
- expect(described_class.servers).to have_key(:blob)
35
+ expect(described_class.servers[:blob]).to be_truthy
36
36
  end
37
37
  end
38
38
 
@@ -8,7 +8,7 @@ class TestClass
8
8
  end
9
9
 
10
10
  Capybara::SpecHelper.run_specs TestClass.new, 'DSL', capybara_skip: %i[
11
- js modals screenshot frames windows send_keys server hover about_scheme psc download css driver scroll spatial
11
+ js modals screenshot frames windows send_keys server hover about_scheme psc download css driver scroll spatial html_validation
12
12
  ] do |example|
13
13
  case example.metadata[:full_description]
14
14
  when /has_css\? should support case insensitive :class and :id options/
@@ -19,6 +19,10 @@ Capybara::SpecHelper.run_specs TestClass.new, 'DSL', capybara_skip: %i[
19
19
  end
20
20
 
21
21
  RSpec.describe Capybara::DSL do
22
+ before do
23
+ Capybara.use_default_driver
24
+ end
25
+
22
26
  after do
23
27
  Capybara.session_name = nil
24
28
  Capybara.default_driver = nil
@@ -238,6 +242,15 @@ RSpec.describe Capybara::DSL do
238
242
  end
239
243
  expect(Capybara.current_session).to eq(original_session)
240
244
  end
245
+
246
+ it 'should pass the new session if block accepts' do
247
+ original_session = Capybara.current_session
248
+ Capybara.using_session(:administrator) do |admin_session, prev_session|
249
+ expect(admin_session).to be(Capybara.current_session)
250
+ expect(prev_session).to be(original_session)
251
+ expect(prev_session).not_to be(admin_session)
252
+ end
253
+ end
241
254
  end
242
255
 
243
256
  describe '#session_name' do
@@ -16,7 +16,7 @@ class MinitestTest < Minitest::Test
16
16
  end
17
17
 
18
18
  def test_assert_text
19
- assert_text('Form')
19
+ assert_text('Form', normalize_ws: false)
20
20
  assert_no_text('Not on the page')
21
21
  refute_text('Also Not on the page')
22
22
  end
@@ -26,6 +26,7 @@ skipped_tests = %i[
26
26
  css
27
27
  scroll
28
28
  spatial
29
+ html_validation
29
30
  ]
30
31
  Capybara::SpecHelper.run_specs TestSessions::RackTest, 'RackTest', capybara_skip: skipped_tests do |example|
31
32
  case example.metadata[:full_description]
@@ -82,7 +83,6 @@ RSpec.describe Capybara::Session do # rubocop:disable RSpec/MultipleDescribes
82
83
  describe '#fill_in' do
83
84
  it 'should warn that :fill_options are not supported' do
84
85
  session.visit '/with_html'
85
-
86
86
  expect { session.fill_in 'test_field', with: 'not_monkey', fill_options: { random: true } }.to \
87
87
  output(/^Options passed to Node#set but the RackTest driver doesn't support any - ignoring/).to_stderr
88
88
  expect(session).to have_field('test_field', with: 'not_monkey')
@@ -128,6 +128,18 @@ RSpec.describe Capybara::Session do # rubocop:disable RSpec/MultipleDescribes
128
128
  session.find(:label, 'Female').click
129
129
  expect(session).to have_unchecked_field('gender_male')
130
130
  end
131
+
132
+ it 'should rewrite the forms action query for get submission' do
133
+ session.visit('/form')
134
+ session.click_button('mediocre')
135
+ expect(session).not_to have_current_path(/foo|bar/)
136
+ end
137
+
138
+ it 'should rewrite the submit buttons formaction query for get submission' do
139
+ session.visit('/form')
140
+ session.click_button('mediocre2')
141
+ expect(session).not_to have_current_path(/foo|bar/)
142
+ end
131
143
  end
132
144
  end
133
145
 
@@ -49,7 +49,6 @@ RSpec.describe Capybara::Selector::RegexpDisassembler, :aggregate_failures do
49
49
  end
50
50
 
51
51
  it 'handles optional characters for #alternated_substrings' do
52
- # rubocop:disable Style/BracesAroundHashParameters
53
52
  verify_alternated_strings(
54
53
  {
55
54
  /abc*def/ => [%w[ab def]],
@@ -62,7 +61,6 @@ RSpec.describe Capybara::Selector::RegexpDisassembler, :aggregate_failures do
62
61
  /d?/ => []
63
62
  }
64
63
  )
65
- # rubocop:enable Style/BracesAroundHashParameters
66
64
  end
67
65
 
68
66
  it 'handles character classes' do
@@ -140,7 +138,6 @@ RSpec.describe Capybara::Selector::RegexpDisassembler, :aggregate_failures do
140
138
  end
141
139
 
142
140
  it 'handles alternation for #alternated_substrings' do
143
- # rubocop:disable Style/BracesAroundHashParameters
144
141
  verify_alternated_strings(
145
142
  {
146
143
  /abc|def/ => [%w[abc], %w[def]],
@@ -173,7 +170,6 @@ RSpec.describe Capybara::Selector::RegexpDisassembler, :aggregate_failures do
173
170
  /ab\\?cd/ => [%w[abcd], %w[ab\cd]]
174
171
  }
175
172
  )
176
- # rubocop:enable Style/BracesAroundHashParameters
177
173
  end
178
174
 
179
175
  it 'handles grouping' do
@@ -65,20 +65,47 @@ RSpec.describe Capybara::Result do
65
65
  end).to eq(2)
66
66
  end
67
67
 
68
+ def recalc_result
69
+ string.all '//li', minimum: 0 # pass minimum: 0 so lazy evaluation doesn't get triggered yet
70
+ end
71
+
68
72
  it 'supports all modes of []' do
69
- expect(result[1].text).to eq 'Beta'
70
- expect(result[0, 2].map(&:text)).to eq %w[Alpha Beta]
71
- expect(result[1..3].map(&:text)).to eq %w[Beta Gamma Delta]
72
- expect(result[-1].text).to eq 'Delta'
73
- expect(result[-2, 3].map(&:text)).to eq %w[Gamma Delta]
74
- expect(result[1..7].map(&:text)).to eq %w[Beta Gamma Delta]
75
- expect(result[1...3].map(&:text)).to eq %w[Beta Gamma]
76
- expect(result[2..-1].map(&:text)).to eq %w[Gamma Delta]
77
- expect(result[2...-1].map(&:text)).to eq %w[Gamma]
78
- eval <<~TEST, binding, __FILE__, __LINE__ + 1 if RUBY_VERSION.to_f > 2.5
73
+ expect(recalc_result[1].text).to eq 'Beta'
74
+ expect(recalc_result[0, 2].map(&:text)).to eq %w[Alpha Beta]
75
+ expect(recalc_result[1..3].map(&:text)).to eq %w[Beta Gamma Delta]
76
+ expect(recalc_result[-1].text).to eq 'Delta'
77
+ expect(recalc_result[-2, 3].map(&:text)).to eq %w[Gamma Delta]
78
+ expect(recalc_result[1...3].map(&:text)).to eq %w[Beta Gamma]
79
+ expect(recalc_result[1..7].map(&:text)).to eq %w[Beta Gamma Delta]
80
+ expect(recalc_result[2...-1].map(&:text)).to eq %w[Gamma]
81
+ expect(recalc_result[2..-1].map(&:text)).to eq %w[Gamma Delta]
82
+ end
83
+
84
+ eval <<~TEST, binding, __FILE__, __LINE__ + 1 if RUBY_VERSION.to_f > 2.5
85
+ it 'supports endless ranges' do
79
86
  expect(result[2..].map(&:text)).to eq %w[Gamma Delta]
80
- TEST
81
- end
87
+ end
88
+ TEST
89
+
90
+ eval <<~TEST, binding, __FILE__, __LINE__ + 1 if RUBY_VERSION.to_f > 2.6
91
+ it 'supports inclusive positive beginless ranges' do
92
+ expect(result[..2].map(&:text)).to eq %w[Alpha Beta Gamma]
93
+ end
94
+
95
+ it 'supports inclusive negative beginless ranges' do
96
+ expect(result[..-2].map(&:text)).to eq %w[Alpha Beta Gamma]
97
+ expect(result[..-1].map(&:text)).to eq %w[Alpha Beta Gamma Delta]
98
+ end
99
+
100
+ it 'supports exclusive positive beginless ranges' do
101
+ expect(result[...2].map(&:text)).to eq %w[Alpha Beta]
102
+ end
103
+
104
+ it 'supports exclusive negative beginless ranges' do
105
+ expect(result[...-2].map(&:text)).to eq %w[Alpha Beta]
106
+ expect(result[...-1].map(&:text)).to eq %w[Alpha Beta Gamma]
107
+ end
108
+ TEST
82
109
 
83
110
  it 'works with filter blocks' do
84
111
  result = string.all('//li') { |node| node.text == 'Alpha' }
@@ -163,23 +190,7 @@ RSpec.describe Capybara::Result do
163
190
  end
164
191
  end
165
192
 
166
- context 'lazy select' do
167
- it 'is compatible' do
168
- # This test will let us know when JRuby fixes lazy select so we can re-enable it in Result
169
- pending 'JRuby < 9.2.8.0 has an issue with lazy enumberator evaluation' if jruby_lazy_enumerator_workaround?
170
- eval_count = 0
171
- enum = %w[Text1 Text2 Text3].lazy.select do
172
- eval_count += 1
173
- true
174
- end
175
- expect(eval_count).to eq 0
176
- enum.next
177
- sleep 1
178
- expect(eval_count).to eq 1
179
- end
180
- end
181
-
182
193
  def jruby_lazy_enumerator_workaround?
183
- (RUBY_PLATFORM == 'java') && (Gem::Version.new(JRUBY_VERSION) < Gem::Version.new('9.2.8.0'))
194
+ RUBY_PLATFORM == 'java'
184
195
  end
185
196
  end
@@ -89,29 +89,29 @@ RSpec.shared_examples Capybara::RSpecMatchers do |session, _mode|
89
89
 
90
90
  context 'on a page or node' do
91
91
  before do
92
- visit('/with_html')
92
+ session.visit('/with_html')
93
93
  end
94
94
 
95
95
  context 'with should' do
96
96
  it 'passes if has_css? returns true' do
97
- expect(page).to have_css('h1')
97
+ expect(session).to have_css('h1')
98
98
  end
99
99
 
100
100
  it 'fails if has_css? returns false' do
101
101
  expect do
102
- expect(page).to have_css('h1#doesnotexist')
102
+ expect(session).to have_css('h1#doesnotexist')
103
103
  end.to raise_error(/expected to find css "h1#doesnotexist" but there were no matches/)
104
104
  end
105
105
  end
106
106
 
107
107
  context 'with should_not' do
108
108
  it 'passes if has_no_css? returns true' do
109
- expect(page).not_to have_css('h1#doesnotexist')
109
+ expect(session).not_to have_css('h1#doesnotexist')
110
110
  end
111
111
 
112
112
  it 'fails if has_no_css? returns false' do
113
113
  expect do
114
- expect(page).not_to have_css('h1')
114
+ expect(session).not_to have_css('h1')
115
115
  end.to raise_error(/expected not to find visible css "h1"/)
116
116
  end
117
117
  end
@@ -158,29 +158,29 @@ RSpec.shared_examples Capybara::RSpecMatchers do |session, _mode|
158
158
 
159
159
  context 'on a page or node' do
160
160
  before do
161
- visit('/with_html')
161
+ session.visit('/with_html')
162
162
  end
163
163
 
164
164
  context 'with should' do
165
165
  it 'passes if has_xpath? returns true' do
166
- expect(page).to have_xpath('//h1')
166
+ expect(session).to have_xpath('//h1')
167
167
  end
168
168
 
169
169
  it 'fails if has_xpath? returns false' do
170
170
  expect do
171
- expect(page).to have_xpath("//h1[@id='doesnotexist']")
171
+ expect(session).to have_xpath("//h1[@id='doesnotexist']")
172
172
  end.to raise_error(%r{expected to find xpath "//h1\[@id='doesnotexist'\]" but there were no matches})
173
173
  end
174
174
  end
175
175
 
176
176
  context 'with should_not' do
177
177
  it 'passes if has_no_xpath? returns true' do
178
- expect(page).not_to have_xpath('//h1[@id="doesnotexist"]')
178
+ expect(session).not_to have_xpath('//h1[@id="doesnotexist"]')
179
179
  end
180
180
 
181
181
  it 'fails if has_no_xpath? returns false' do
182
182
  expect do
183
- expect(page).not_to have_xpath('//h1')
183
+ expect(session).not_to have_xpath('//h1')
184
184
  end.to raise_error(%r{expected not to find visible xpath "//h1"})
185
185
  end
186
186
  end
@@ -222,35 +222,35 @@ RSpec.shared_examples Capybara::RSpecMatchers do |session, _mode|
222
222
 
223
223
  context 'on a page or node' do
224
224
  before do
225
- visit('/with_html')
225
+ session.visit('/with_html')
226
226
  end
227
227
 
228
228
  context 'with should' do
229
229
  it 'passes if has_selector? returns true' do
230
- expect(page).to have_selector('//h1', text: 'test')
230
+ expect(session).to have_selector('//h1', text: 'test')
231
231
  end
232
232
 
233
233
  it 'fails if has_selector? returns false' do
234
234
  expect do
235
- expect(page).to have_selector("//h1[@id='doesnotexist']")
235
+ expect(session).to have_selector("//h1[@id='doesnotexist']")
236
236
  end.to raise_error(%r{expected to find xpath "//h1\[@id='doesnotexist'\]" but there were no matches})
237
237
  end
238
238
 
239
239
  it 'includes text in error message' do
240
240
  expect do
241
- expect(page).to have_selector('//h1', text: 'wrong text')
241
+ expect(session).to have_selector('//h1', text: 'wrong text')
242
242
  end.to raise_error(%r{expected to find visible xpath "//h1" with text "wrong text" but there were no matches})
243
243
  end
244
244
  end
245
245
 
246
246
  context 'with should_not' do
247
247
  it 'passes if has_no_css? returns true' do
248
- expect(page).not_to have_selector(:css, 'h1#doesnotexist')
248
+ expect(session).not_to have_selector(:css, 'h1#doesnotexist')
249
249
  end
250
250
 
251
251
  it 'fails if has_no_selector? returns false' do
252
252
  expect do
253
- expect(page).not_to have_selector(:css, 'h1', text: 'test')
253
+ expect(session).not_to have_selector(:css, 'h1', text: 'test')
254
254
  end.to raise_error(/expected not to find visible css "h1" with text "test"/)
255
255
  end
256
256
  end
@@ -265,7 +265,7 @@ RSpec.shared_examples Capybara::RSpecMatchers do |session, _mode|
265
265
 
266
266
  describe 'have_content matcher' do
267
267
  it 'gives proper description' do
268
- expect(have_content('Text').description).to eq('text "Text"')
268
+ expect(have_content('Text').description).to eq('have text "Text"')
269
269
  end
270
270
 
271
271
  context 'on a string' do
@@ -304,21 +304,21 @@ RSpec.shared_examples Capybara::RSpecMatchers do |session, _mode|
304
304
 
305
305
  context 'on a page or node' do
306
306
  before do
307
- visit('/with_html')
307
+ session.visit('/with_html')
308
308
  end
309
309
 
310
310
  context 'with should' do
311
311
  it 'passes if has_content? returns true' do
312
- expect(page).to have_content('This is a test')
312
+ expect(session).to have_content('This is a test')
313
313
  end
314
314
 
315
315
  it 'passes if has_content? returns true using regexp' do
316
- expect(page).to have_content(/test/)
316
+ expect(session).to have_content(/test/)
317
317
  end
318
318
 
319
319
  it 'fails if has_content? returns false' do
320
320
  expect do
321
- expect(page).to have_content('No such Text')
321
+ expect(session).to have_content('No such Text')
322
322
  end.to raise_error(/expected to find text "No such Text" in "(.*)This is a test(.*)"/)
323
323
  end
324
324
 
@@ -329,7 +329,7 @@ RSpec.shared_examples Capybara::RSpecMatchers do |session, _mode|
329
329
 
330
330
  it 'fails if has_content? returns false' do
331
331
  expect do
332
- expect(page).to have_content('No such Text')
332
+ expect(session).to have_content('No such Text')
333
333
  end.to raise_error(/expected to find text "No such Text" in "(.*)This is a test(.*)"/)
334
334
  end
335
335
  end
@@ -337,14 +337,26 @@ RSpec.shared_examples Capybara::RSpecMatchers do |session, _mode|
337
337
 
338
338
  context 'with should_not' do
339
339
  it 'passes if has_no_content? returns true' do
340
- expect(page).not_to have_content('No such Text')
340
+ expect(session).not_to have_content('No such Text')
341
341
  end
342
342
 
343
343
  it 'fails if has_no_content? returns false' do
344
344
  expect do
345
- expect(page).not_to have_content('This is a test')
345
+ expect(session).not_to have_content('This is a test')
346
346
  end.to raise_error(/expected not to find text "This is a test"/)
347
347
  end
348
+
349
+ it 'not_to have_content behaves the same as to have_no_content' do
350
+ Capybara.using_wait_time(5) do
351
+ expect(session).to have_content('This is a test')
352
+ start = Time.now
353
+ expect(session).to have_no_content('No such Text')
354
+ to_time = Time.now
355
+ expect(session).not_to have_content('No such Text')
356
+ not_to_time = Time.now
357
+ expect(not_to_time - to_time).to be_within(0.5).of(to_time - start)
358
+ end
359
+ end
348
360
  end
349
361
  end
350
362
 
@@ -357,7 +369,7 @@ RSpec.shared_examples Capybara::RSpecMatchers do |session, _mode|
357
369
 
358
370
  describe 'have_text matcher' do
359
371
  it 'gives proper description' do
360
- expect(have_text('Text').description).to eq('text "Text"')
372
+ expect(have_text('Text').description).to eq('have text "Text"')
361
373
  end
362
374
 
363
375
  context 'on a string' do
@@ -432,30 +444,30 @@ RSpec.shared_examples Capybara::RSpecMatchers do |session, _mode|
432
444
 
433
445
  context 'on a page or node' do
434
446
  before do
435
- visit('/with_html')
447
+ session.visit('/with_html')
436
448
  end
437
449
 
438
450
  context 'with should' do
439
451
  it 'passes if has_text? returns true' do
440
- expect(page).to have_text('This is a test')
452
+ expect(session).to have_text('This is a test')
441
453
  end
442
454
 
443
455
  it 'passes if has_text? returns true using regexp' do
444
- expect(page).to have_text(/test/)
456
+ expect(session).to have_text(/test/)
445
457
  end
446
458
 
447
459
  it 'can check for all text' do
448
- expect(page).to have_text(:all, 'Some of this text is hidden!')
460
+ expect(session).to have_text(:all, 'Some of this text is hidden!')
449
461
  end
450
462
 
451
463
  it 'can check for visible text' do
452
- expect(page).to have_text(:visible, 'Some of this text is')
453
- expect(page).not_to have_text(:visible, 'Some of this text is hidden!')
464
+ expect(session).to have_text(:visible, 'Some of this text is')
465
+ expect(session).not_to have_text(:visible, 'Some of this text is hidden!')
454
466
  end
455
467
 
456
468
  it 'fails if has_text? returns false' do
457
469
  expect do
458
- expect(page).to have_text('No such Text')
470
+ expect(session).to have_text('No such Text')
459
471
  end.to raise_error(/expected to find text "No such Text" in "(.*)This is a test(.*)"/)
460
472
  end
461
473
 
@@ -466,7 +478,7 @@ RSpec.shared_examples Capybara::RSpecMatchers do |session, _mode|
466
478
 
467
479
  it 'fails if has_text? returns false' do
468
480
  expect do
469
- expect(page).to have_text('No such Text')
481
+ expect(session).to have_text('No such Text')
470
482
  end.to raise_error(/expected to find text "No such Text" in "(.*)This is a test(.*)"/)
471
483
  end
472
484
  end
@@ -474,12 +486,12 @@ RSpec.shared_examples Capybara::RSpecMatchers do |session, _mode|
474
486
 
475
487
  context 'with should_not' do
476
488
  it 'passes if has_no_text? returns true' do
477
- expect(page).not_to have_text('No such Text')
489
+ expect(session).not_to have_text('No such Text')
478
490
  end
479
491
 
480
492
  it 'fails if has_no_text? returns false' do
481
493
  expect do
482
- expect(page).not_to have_text('This is a test')
494
+ expect(session).not_to have_text('This is a test')
483
495
  end.to raise_error(/expected not to find text "This is a test"/)
484
496
  end
485
497
  end
@@ -542,15 +554,15 @@ RSpec.shared_examples Capybara::RSpecMatchers do |session, _mode|
542
554
 
543
555
  context 'on a page or node' do
544
556
  it 'passes if there is such a title' do
545
- visit('/with_js')
546
- expect(page).to have_title('with_js')
557
+ session.visit('/with_js')
558
+ expect(session).to have_title('with_js')
547
559
  end
548
560
 
549
561
  it 'fails if there is no such title' do
550
- visit('/with_js')
562
+ session.visit('/with_js')
551
563
  expect do
552
- expect(page).to have_title('No such title')
553
- end.to raise_error('expected "with_js" to include "No such title"')
564
+ expect(session).to have_title('No such title')
565
+ end.to raise_error(/ to include "No such title"/)
554
566
  end
555
567
 
556
568
  context 'with wait' do
@@ -560,14 +572,14 @@ RSpec.shared_examples Capybara::RSpecMatchers do |session, _mode|
560
572
 
561
573
  it 'waits if wait time is more than timeout' do
562
574
  session.click_link('Change title')
563
- using_wait_time 0 do
575
+ session.using_wait_time 0 do
564
576
  expect(session).to have_title('changed title', wait: 2)
565
577
  end
566
578
  end
567
579
 
568
580
  it "doesn't wait if wait time is less than timeout" do
569
581
  session.click_link('Change title')
570
- using_wait_time 3 do
582
+ session.using_wait_time 3 do
571
583
  expect(session).not_to have_title('changed title', wait: 0)
572
584
  end
573
585
  end
@@ -586,15 +598,15 @@ RSpec.shared_examples Capybara::RSpecMatchers do |session, _mode|
586
598
 
587
599
  context 'on a page or node' do
588
600
  it 'passes if there is such a current path' do
589
- visit('/with_js')
590
- expect(page).to have_current_path('/with_js')
601
+ session.visit('/with_js')
602
+ expect(session).to have_current_path('/with_js')
591
603
  end
592
604
 
593
605
  it 'fails if there is no such current_path' do
594
606
  visit('/with_js')
595
607
  expect do
596
- expect(page).to have_current_path('/not_with_js')
597
- end.to raise_error('expected "/with_js" to equal "/not_with_js"')
608
+ expect(session).to have_current_path('/not_with_js')
609
+ end.to raise_error(%r{to equal "/not_with_js"})
598
610
  end
599
611
 
600
612
  context 'with wait' do
@@ -604,14 +616,14 @@ RSpec.shared_examples Capybara::RSpecMatchers do |session, _mode|
604
616
 
605
617
  it 'waits if wait time is more than timeout' do
606
618
  session.click_link('Change page')
607
- using_wait_time 0 do
619
+ session.using_wait_time 0 do
608
620
  expect(session).to have_current_path('/with_html', wait: 2)
609
621
  end
610
622
  end
611
623
 
612
624
  it "doesn't wait if wait time is less than timeout" do
613
625
  session.click_link('Change page')
614
- using_wait_time 0 do
626
+ session.using_wait_time 0 do
615
627
  expect(session).not_to have_current_path('/with_html')
616
628
  end
617
629
  end
@@ -619,8 +631,8 @@ RSpec.shared_examples Capybara::RSpecMatchers do |session, _mode|
619
631
  end
620
632
 
621
633
  it 'supports compounding' do
622
- visit('/with_html')
623
- expect(page).to have_current_path('/not_with_html').or have_current_path('/with_html')
634
+ session.visit('/with_html')
635
+ expect(session).to have_current_path('/not_with_html').or have_current_path('/with_html')
624
636
  end
625
637
  end
626
638
 
@@ -828,10 +840,10 @@ RSpec.shared_examples Capybara::RSpecMatchers do |session, _mode|
828
840
  end
829
841
 
830
842
  it 'gives proper description when :visible option passed' do
831
- expect(have_table('Lovely table', visible: true).description).to eq('have visible table "Lovely table"')
843
+ expect(have_table('Lovely table', visible: true).description).to eq('have visible table "Lovely table"') # rubocop:disable Capybara/VisibilityMatcher
832
844
  expect(have_table('Lovely table', visible: :hidden).description).to eq('have non-visible table "Lovely table"')
833
845
  expect(have_table('Lovely table', visible: :all).description).to eq('have table "Lovely table"')
834
- expect(have_table('Lovely table', visible: false).description).to eq('have table "Lovely table"')
846
+ expect(have_table('Lovely table', visible: false).description).to eq('have table "Lovely table"') # rubocop:disable Capybara/VisibilityMatcher
835
847
  end
836
848
 
837
849
  it 'passes if there is such a table' do
@@ -859,7 +871,7 @@ RSpec.shared_examples Capybara::RSpecMatchers do |session, _mode|
859
871
 
860
872
  describe '#and' do
861
873
  it "should run 'concurrently'" do
862
- Capybara.using_wait_time(2) do
874
+ session.using_wait_time(2) do
863
875
  matcher = have_text('this is not there').and have_text('neither is this')
864
876
  expect(Benchmark.realtime do
865
877
  expect do