capybara 3.29.0 → 3.33.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (130) hide show
  1. checksums.yaml +4 -4
  2. data/History.md +91 -1
  3. data/README.md +10 -3
  4. data/lib/capybara.rb +17 -7
  5. data/lib/capybara/config.rb +7 -3
  6. data/lib/capybara/cucumber.rb +1 -1
  7. data/lib/capybara/dsl.rb +10 -2
  8. data/lib/capybara/helpers.rb +3 -1
  9. data/lib/capybara/minitest.rb +232 -144
  10. data/lib/capybara/minitest/spec.rb +153 -97
  11. data/lib/capybara/node/actions.rb +35 -35
  12. data/lib/capybara/node/document.rb +2 -2
  13. data/lib/capybara/node/document_matchers.rb +3 -3
  14. data/lib/capybara/node/element.rb +23 -16
  15. data/lib/capybara/node/finders.rb +17 -11
  16. data/lib/capybara/node/matchers.rb +64 -51
  17. data/lib/capybara/node/simple.rb +4 -2
  18. data/lib/capybara/queries/ancestor_query.rb +1 -1
  19. data/lib/capybara/queries/base_query.rb +2 -1
  20. data/lib/capybara/queries/selector_query.rb +25 -5
  21. data/lib/capybara/queries/sibling_query.rb +1 -1
  22. data/lib/capybara/queries/style_query.rb +1 -1
  23. data/lib/capybara/queries/text_query.rb +6 -0
  24. data/lib/capybara/rack_test/browser.rb +7 -2
  25. data/lib/capybara/rack_test/driver.rb +1 -1
  26. data/lib/capybara/rack_test/form.rb +1 -1
  27. data/lib/capybara/rack_test/node.rb +34 -9
  28. data/lib/capybara/registration_container.rb +44 -0
  29. data/lib/capybara/registrations/servers.rb +1 -1
  30. data/lib/capybara/result.rb +29 -5
  31. data/lib/capybara/rspec/matcher_proxies.rb +4 -4
  32. data/lib/capybara/rspec/matchers.rb +27 -27
  33. data/lib/capybara/rspec/matchers/base.rb +12 -6
  34. data/lib/capybara/rspec/matchers/count_sugar.rb +2 -1
  35. data/lib/capybara/rspec/matchers/have_ancestor.rb +4 -3
  36. data/lib/capybara/rspec/matchers/have_current_path.rb +2 -2
  37. data/lib/capybara/rspec/matchers/have_selector.rb +15 -7
  38. data/lib/capybara/rspec/matchers/have_sibling.rb +3 -3
  39. data/lib/capybara/rspec/matchers/have_text.rb +3 -3
  40. data/lib/capybara/rspec/matchers/have_title.rb +2 -2
  41. data/lib/capybara/rspec/matchers/match_selector.rb +3 -3
  42. data/lib/capybara/rspec/matchers/match_style.rb +2 -2
  43. data/lib/capybara/rspec/matchers/spatial_sugar.rb +2 -1
  44. data/lib/capybara/selector.rb +34 -17
  45. data/lib/capybara/selector/css.rb +1 -1
  46. data/lib/capybara/selector/definition.rb +7 -6
  47. data/lib/capybara/selector/definition/button.rb +8 -2
  48. data/lib/capybara/selector/definition/checkbox.rb +2 -2
  49. data/lib/capybara/selector/definition/css.rb +3 -1
  50. data/lib/capybara/selector/definition/datalist_input.rb +1 -1
  51. data/lib/capybara/selector/definition/datalist_option.rb +1 -1
  52. data/lib/capybara/selector/definition/element.rb +1 -1
  53. data/lib/capybara/selector/definition/field.rb +1 -1
  54. data/lib/capybara/selector/definition/file_field.rb +1 -1
  55. data/lib/capybara/selector/definition/fillable_field.rb +2 -2
  56. data/lib/capybara/selector/definition/label.rb +4 -2
  57. data/lib/capybara/selector/definition/link.rb +8 -0
  58. data/lib/capybara/selector/definition/radio_button.rb +2 -2
  59. data/lib/capybara/selector/definition/select.rb +32 -13
  60. data/lib/capybara/selector/definition/table.rb +6 -3
  61. data/lib/capybara/selector/filter_set.rb +11 -9
  62. data/lib/capybara/selector/filters/base.rb +6 -1
  63. data/lib/capybara/selector/filters/locator_filter.rb +1 -1
  64. data/lib/capybara/selector/selector.rb +8 -2
  65. data/lib/capybara/selenium/atoms/getAttribute.min.js +1 -1
  66. data/lib/capybara/selenium/atoms/src/getAttribute.js +1 -1
  67. data/lib/capybara/selenium/driver.rb +22 -11
  68. data/lib/capybara/selenium/driver_specializations/chrome_driver.rb +8 -10
  69. data/lib/capybara/selenium/driver_specializations/edge_driver.rb +7 -9
  70. data/lib/capybara/selenium/driver_specializations/firefox_driver.rb +2 -2
  71. data/lib/capybara/selenium/extensions/html5_drag.rb +30 -13
  72. data/lib/capybara/selenium/node.rb +97 -18
  73. data/lib/capybara/selenium/nodes/chrome_node.rb +11 -14
  74. data/lib/capybara/selenium/nodes/edge_node.rb +4 -2
  75. data/lib/capybara/selenium/nodes/firefox_node.rb +4 -4
  76. data/lib/capybara/selenium/patches/action_pauser.rb +26 -0
  77. data/lib/capybara/selenium/patches/logs.rb +3 -5
  78. data/lib/capybara/server.rb +15 -3
  79. data/lib/capybara/server/checker.rb +1 -1
  80. data/lib/capybara/server/middleware.rb +20 -10
  81. data/lib/capybara/session.rb +43 -26
  82. data/lib/capybara/session/config.rb +9 -3
  83. data/lib/capybara/session/matchers.rb +6 -6
  84. data/lib/capybara/spec/public/test.js +69 -6
  85. data/lib/capybara/spec/session/all_spec.rb +60 -5
  86. data/lib/capybara/spec/session/ancestor_spec.rb +5 -0
  87. data/lib/capybara/spec/session/assert_text_spec.rb +9 -5
  88. data/lib/capybara/spec/session/click_button_spec.rb +16 -0
  89. data/lib/capybara/spec/session/fill_in_spec.rb +29 -0
  90. data/lib/capybara/spec/session/find_spec.rb +31 -8
  91. data/lib/capybara/spec/session/has_button_spec.rb +16 -0
  92. data/lib/capybara/spec/session/has_css_spec.rb +12 -9
  93. data/lib/capybara/spec/session/has_current_path_spec.rb +2 -2
  94. data/lib/capybara/spec/session/has_field_spec.rb +16 -0
  95. data/lib/capybara/spec/session/has_select_spec.rb +32 -4
  96. data/lib/capybara/spec/session/has_selector_spec.rb +4 -4
  97. data/lib/capybara/spec/session/has_table_spec.rb +51 -5
  98. data/lib/capybara/spec/session/has_text_spec.rb +35 -0
  99. data/lib/capybara/spec/session/node_spec.rb +160 -29
  100. data/lib/capybara/spec/session/save_and_open_screenshot_spec.rb +2 -2
  101. data/lib/capybara/spec/session/save_screenshot_spec.rb +4 -4
  102. data/lib/capybara/spec/session/selectors_spec.rb +15 -2
  103. data/lib/capybara/spec/session/window/window_spec.rb +7 -7
  104. data/lib/capybara/spec/spec_helper.rb +2 -2
  105. data/lib/capybara/spec/test_app.rb +14 -18
  106. data/lib/capybara/spec/views/form.erb +18 -2
  107. data/lib/capybara/spec/views/with_dragula.erb +3 -1
  108. data/lib/capybara/spec/views/with_html.erb +2 -2
  109. data/lib/capybara/spec/views/with_js.erb +1 -0
  110. data/lib/capybara/version.rb +1 -1
  111. data/spec/capybara_spec.rb +1 -1
  112. data/spec/dsl_spec.rb +16 -3
  113. data/spec/minitest_spec.rb +1 -1
  114. data/spec/minitest_spec_spec.rb +46 -46
  115. data/spec/rack_test_spec.rb +13 -1
  116. data/spec/regexp_dissassembler_spec.rb +40 -36
  117. data/spec/result_spec.rb +43 -32
  118. data/spec/rspec/features_spec.rb +1 -0
  119. data/spec/rspec/shared_spec_matchers.rb +68 -56
  120. data/spec/rspec_spec.rb +4 -4
  121. data/spec/selector_spec.rb +1 -1
  122. data/spec/selenium_spec_chrome.rb +9 -6
  123. data/spec/selenium_spec_chrome_remote.rb +2 -0
  124. data/spec/selenium_spec_firefox.rb +7 -2
  125. data/spec/server_spec.rb +65 -31
  126. data/spec/session_spec.rb +1 -1
  127. data/spec/shared_selenium_node.rb +21 -3
  128. data/spec/shared_selenium_session.rb +33 -14
  129. data/spec/spec_helper.rb +1 -1
  130. metadata +6 -4
@@ -15,7 +15,7 @@ Capybara::SpecHelper.spec '#save_and_open_screenshot' do
15
15
  @session.save_and_open_screenshot
16
16
 
17
17
  expect(@session.driver).to have_received(:save_screenshot)
18
- .with(expected_file_regex, {})
18
+ .with(expected_file_regex, any_args)
19
19
  expect(Launchy).to have_received(:open).with(expected_file_regex)
20
20
  end
21
21
 
@@ -27,7 +27,7 @@ Capybara::SpecHelper.spec '#save_and_open_screenshot' do
27
27
  @session.save_and_open_screenshot(custom_path)
28
28
 
29
29
  expect(@session.driver).to have_received(:save_screenshot)
30
- .with(/#{custom_path}$/, {})
30
+ .with(/#{custom_path}$/, any_args)
31
31
  expect(Launchy).to have_received(:open).with(/#{custom_path}$/)
32
32
  end
33
33
 
@@ -19,7 +19,7 @@ Capybara::SpecHelper.spec '#save_screenshot', requires: [:screenshot] do
19
19
  @session.save_screenshot
20
20
 
21
21
  regexp = Regexp.new(File.join(Dir.pwd, 'capybara-\d+\.png'))
22
- expect(@session.driver).to have_received(:save_screenshot).with(regexp, {})
22
+ expect(@session.driver).to have_received(:save_screenshot).with(regexp, any_args)
23
23
  end
24
24
 
25
25
  it 'allows to specify another path' do
@@ -28,7 +28,7 @@ Capybara::SpecHelper.spec '#save_screenshot', requires: [:screenshot] do
28
28
  custom_path = 'screenshots/1.png'
29
29
  @session.save_screenshot(custom_path)
30
30
 
31
- expect(@session.driver).to have_received(:save_screenshot).with(/#{custom_path}$/, {})
31
+ expect(@session.driver).to have_received(:save_screenshot).with(/#{custom_path}$/, any_args)
32
32
  end
33
33
 
34
34
  context 'with Capybara.save_path' do
@@ -39,7 +39,7 @@ Capybara::SpecHelper.spec '#save_screenshot', requires: [:screenshot] do
39
39
  @session.save_screenshot
40
40
 
41
41
  regexp = Regexp.new(File.join(alternative_path, 'capybara-\d+\.png'))
42
- expect(@session.driver).to have_received(:save_screenshot).with(regexp, {})
42
+ expect(@session.driver).to have_received(:save_screenshot).with(regexp, any_args)
43
43
  end
44
44
 
45
45
  it 'relative paths are relative to save_path' do
@@ -49,7 +49,7 @@ Capybara::SpecHelper.spec '#save_screenshot', requires: [:screenshot] do
49
49
  custom_path = 'screenshots/2.png'
50
50
  @session.save_screenshot(custom_path)
51
51
 
52
- expect(@session.driver).to have_received(:save_screenshot).with(File.expand_path(custom_path, alternative_path), {})
52
+ expect(@session.driver).to have_received(:save_screenshot).with(File.expand_path(custom_path, alternative_path), any_args)
53
53
  end
54
54
  end
55
55
  end
@@ -31,6 +31,11 @@ Capybara::SpecHelper.spec Capybara::Selector do
31
31
  expect(@session.find(:label, for: input).text).to eq 'Nested Label'
32
32
  end
33
33
 
34
+ it 'finds a label from nested input using :for filter with element when no id on label' do
35
+ input = @session.find(:css, '#wrapper_label').find(:css, 'input')
36
+ expect(@session.find(:label, for: input).text).to eq 'Wrapper Label'
37
+ end
38
+
34
39
  it 'finds the label for an non-nested element when using :for filter' do
35
40
  select = @session.find(:id, 'form_other_title')
36
41
  expect(@session.find(:label, for: select)['for']).to eq 'form_other_title'
@@ -62,14 +67,22 @@ Capybara::SpecHelper.spec Capybara::Selector do
62
67
  end
63
68
  end
64
69
 
65
- it 'can find specifically by name' do
70
+ it 'can find specifically by name string' do
66
71
  expect(@session.find(:field, name: 'form[other_title]')['id']).to eq 'form_other_title'
67
72
  end
68
73
 
69
- it 'can find specifically by placeholder' do
74
+ it 'can find specifically by name regex' do
75
+ expect(@session.find(:field, name: /form\[other_.*\]/)['id']).to eq 'form_other_title'
76
+ end
77
+
78
+ it 'can find specifically by placeholder string' do
70
79
  expect(@session.find(:field, placeholder: 'FirstName')['id']).to eq 'form_first_name'
71
80
  end
72
81
 
82
+ it 'can find specifically by placeholder regex' do
83
+ expect(@session.find(:field, placeholder: /FirstN.*/)['id']).to eq 'form_first_name'
84
+ end
85
+
73
86
  it 'can find by type' do
74
87
  expect(@session.find(:field, 'Confusion', type: 'checkbox')['id']).to eq 'confusion_checkbox'
75
88
  expect(@session.find(:field, 'Confusion', type: 'text')['id']).to eq 'confusion_text'
@@ -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>
@@ -474,6 +484,11 @@ New line after and before textarea tag
474
484
  <input type="text" name="nested_label" id="nested_label"/>
475
485
  </label>
476
486
 
487
+ <label id="wrapper_label">
488
+ Wrapper Label
489
+ <input type="checkbox"/>
490
+ </label>
491
+
477
492
  <form id="form1" action="/form" method="post">
478
493
  <input type="text" name="form[which_form]" value="form1" id="form_which_form"/>
479
494
  <input type="text" name="form[for_form2]" value="for_form2" form="form2"/>
@@ -507,6 +522,7 @@ New line after and before textarea tag
507
522
 
508
523
  <p>
509
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"/>
510
526
  <p>
511
527
  </form>
512
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.29.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
@@ -92,7 +96,7 @@ RSpec.describe Capybara::DSL do
92
96
  driver_before_block = Capybara.current_driver
93
97
  begin
94
98
  Capybara.using_driver(:selenium) { raise 'ohnoes!' }
95
- rescue Exception # rubocop:disable Lint/RescueException,Lint/HandleExceptions
99
+ rescue Exception # rubocop:disable Lint/RescueException,Lint/SuppressedException
96
100
  end
97
101
  expect(Capybara.current_driver).to eq(driver_before_block)
98
102
  end
@@ -208,7 +212,7 @@ RSpec.describe Capybara::DSL do
208
212
  Capybara.using_session(:raise) do
209
213
  raise
210
214
  end
211
- rescue Exception # rubocop:disable Lint/RescueException,Lint/HandleExceptions
215
+ rescue Exception # rubocop:disable Lint/RescueException,Lint/SuppressedException
212
216
  end
213
217
  expect(Capybara.session_name).to eq(:default)
214
218
  end
@@ -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
@@ -17,125 +17,125 @@ class MinitestSpecTest < Minitest::Spec
17
17
  end
18
18
 
19
19
  it 'supports text expectations' do
20
- page.must_have_text('Form', minimum: 1)
21
- page.wont_have_text('Not a form')
20
+ _(page).must_have_text('Form', minimum: 1)
21
+ _(page).wont_have_text('Not a form')
22
22
  form = find(:css, 'form', text: 'Title')
23
- form.must_have_text('Customer Email')
24
- form.wont_have_text('Some other email')
23
+ _(form).must_have_text('Customer Email')
24
+ _(form).wont_have_text('Some other email')
25
25
  end
26
26
 
27
27
  it 'supports current_path expectations' do
28
- page.must_have_current_path('/form')
29
- page.wont_have_current_path('/form2')
28
+ _(page).must_have_current_path('/form')
29
+ _(page).wont_have_current_path('/form2')
30
30
  end
31
31
 
32
32
  it 'supports title expectations' do
33
33
  visit('/with_title')
34
- page.must_have_title('Test Title')
35
- page.wont_have_title('Not the title')
34
+ _(page).must_have_title('Test Title')
35
+ _(page).wont_have_title('Not the title')
36
36
  end
37
37
 
38
38
  it 'supports xpath expectations' do
39
- page.must_have_xpath('.//input[@id="customer_email"]')
40
- page.wont_have_xpath('.//select[@id="not_form_title"]')
41
- page.wont_have_xpath('.//input[@id="customer_email"]') { |el| el[:id] == 'not_customer_email' }
39
+ _(page).must_have_xpath('.//input[@id="customer_email"]')
40
+ _(page).wont_have_xpath('.//select[@id="not_form_title"]')
41
+ _(page).wont_have_xpath('.//input[@id="customer_email"]') { |el| el[:id] == 'not_customer_email' }
42
42
  select = find(:select, 'form_title')
43
- select.must_have_xpath('.//option[@class="title"]')
44
- select.must_have_xpath('.//option', count: 1) { |option| option[:class] != 'title' && !option.disabled? }
45
- select.wont_have_xpath('.//input[@id="customer_email"]')
43
+ _(select).must_have_xpath('.//option[@class="title"]')
44
+ _(select).must_have_xpath('.//option', count: 1) { |option| option[:class] != 'title' && !option.disabled? }
45
+ _(select).wont_have_xpath('.//input[@id="customer_email"]')
46
46
  end
47
47
 
48
48
  it 'support css expectations' do
49
- page.must_have_css('input#customer_email')
50
- page.wont_have_css('select#not_form_title')
49
+ _(page).must_have_css('input#customer_email')
50
+ _(page).wont_have_css('select#not_form_title')
51
51
  el = find(:select, 'form_title')
52
- el.must_have_css('option.title')
53
- el.wont_have_css('input#customer_email')
52
+ _(el).must_have_css('option.title')
53
+ _(el).wont_have_css('input#customer_email')
54
54
  end
55
55
 
56
56
  it 'supports link expectations' do
57
57
  visit('/with_html')
58
- page.must_have_link('A link')
59
- page.wont_have_link('Not on page')
58
+ _(page).must_have_link('A link')
59
+ _(page).wont_have_link('Not on page')
60
60
  end
61
61
 
62
62
  it 'supports button expectations' do
63
- page.must_have_button('fresh_btn')
64
- page.wont_have_button('not_btn')
63
+ _(page).must_have_button('fresh_btn')
64
+ _(page).wont_have_button('not_btn')
65
65
  end
66
66
 
67
67
  it 'supports field expectations' do
68
- page.must_have_field('customer_email')
69
- page.wont_have_field('not_on_the_form')
68
+ _(page).must_have_field('customer_email')
69
+ _(page).wont_have_field('not_on_the_form')
70
70
  end
71
71
 
72
72
  it 'supports select expectations' do
73
- page.must_have_select('form_title')
74
- page.wont_have_select('not_form_title')
73
+ _(page).must_have_select('form_title')
74
+ _(page).wont_have_select('not_form_title')
75
75
  end
76
76
 
77
77
  it 'supports checked_field expectations' do
78
- page.must_have_checked_field('form_pets_dog')
79
- page.wont_have_checked_field('form_pets_cat')
78
+ _(page).must_have_checked_field('form_pets_dog')
79
+ _(page).wont_have_checked_field('form_pets_cat')
80
80
  end
81
81
 
82
82
  it 'supports unchecked_field expectations' do
83
- page.must_have_unchecked_field('form_pets_cat')
84
- page.wont_have_unchecked_field('form_pets_dog')
83
+ _(page).must_have_unchecked_field('form_pets_cat')
84
+ _(page).wont_have_unchecked_field('form_pets_dog')
85
85
  end
86
86
 
87
87
  it 'supports table expectations' do
88
88
  visit('/tables')
89
- page.must_have_table('agent_table')
90
- page.wont_have_table('not_on_form')
89
+ _(page).must_have_table('agent_table')
90
+ _(page).wont_have_table('not_on_form')
91
91
  end
92
92
 
93
93
  it 'supports all_of_selectors expectations' do
94
- page.must_have_all_of_selectors(:css, 'select#form_other_title', 'input#form_last_name')
94
+ _(page).must_have_all_of_selectors(:css, 'select#form_other_title', 'input#form_last_name')
95
95
  end
96
96
 
97
97
  it 'supports none_of_selectors expectations' do
98
- page.must_have_none_of_selectors(:css, 'input#not_on_page', 'input#also_not_on_page')
98
+ _(page).must_have_none_of_selectors(:css, 'input#not_on_page', 'input#also_not_on_page')
99
99
  end
100
100
 
101
101
  it 'supports any_of_selectors expectations' do
102
- page.must_have_any_of_selectors(:css, 'select#form_other_title', 'input#not_on_page')
102
+ _(page).must_have_any_of_selectors(:css, 'select#form_other_title', 'input#not_on_page')
103
103
  end
104
104
 
105
105
  it 'supports match_selector expectations' do
106
- find(:field, 'customer_email').must_match_selector(:field, 'customer_email')
107
- find(:select, 'form_title').wont_match_selector(:field, 'customer_email')
106
+ _(find(:field, 'customer_email')).must_match_selector(:field, 'customer_email')
107
+ _(find(:select, 'form_title')).wont_match_selector(:field, 'customer_email')
108
108
  end
109
109
 
110
110
  it 'supports match_css expectations' do
111
- find(:select, 'form_title').must_match_css('select#form_title')
112
- find(:select, 'form_title').wont_match_css('select#form_other_title')
111
+ _(find(:select, 'form_title')).must_match_css('select#form_title')
112
+ _(find(:select, 'form_title')).wont_match_css('select#form_other_title')
113
113
  end
114
114
 
115
115
  it 'supports match_xpath expectations' do
116
- find(:select, 'form_title').must_match_xpath('.//select[@id="form_title"]')
117
- find(:select, 'form_title').wont_match_xpath('.//select[@id="not_on_page"]')
116
+ _(find(:select, 'form_title')).must_match_xpath('.//select[@id="form_title"]')
117
+ _(find(:select, 'form_title')).wont_match_xpath('.//select[@id="not_on_page"]')
118
118
  end
119
119
 
120
120
  it 'handles failures' do
121
- page.must_have_select('non_existing_form_title')
121
+ _(page).must_have_select('non_existing_form_title')
122
122
  end
123
123
 
124
124
  it 'supports style expectations' do
125
125
  skip "Rack test doesn't support style" if Capybara.current_driver == :rack_test
126
126
  visit('/with_html')
127
- find(:css, '#second').must_have_style('display' => 'inline') # deprecated
128
- find(:css, '#second').must_match_style('display' => 'inline')
127
+ _(find(:css, '#second')).must_have_style('display' => 'inline') # deprecated
128
+ _(find(:css, '#second')).must_match_style('display' => 'inline')
129
129
  end
130
130
 
131
131
  it 'supports ancestor expectations' do
132
132
  option = find(:option, 'Finnish')
133
- option.must_have_ancestor(:css, '#form_locale')
133
+ _(option).must_have_ancestor(:css, '#form_locale')
134
134
  end
135
135
 
136
136
  it 'supports sibling expectations' do
137
137
  option = find(:css, '#form_title').find(:option, 'Mrs')
138
- option.must_have_sibling(:option, 'Mr')
138
+ _(option).must_have_sibling(:option, 'Mr')
139
139
  end
140
140
  end
141
141