capybara 3.29.0 → 3.37.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (204) hide show
  1. checksums.yaml +4 -4
  2. data/History.md +229 -15
  3. data/README.md +13 -4
  4. data/lib/capybara/config.rb +24 -10
  5. data/lib/capybara/cucumber.rb +1 -1
  6. data/lib/capybara/driver/base.rb +8 -0
  7. data/lib/capybara/driver/node.rb +5 -1
  8. data/lib/capybara/dsl.rb +5 -3
  9. data/lib/capybara/helpers.rb +19 -2
  10. data/lib/capybara/minitest/spec.rb +156 -97
  11. data/lib/capybara/minitest.rb +232 -144
  12. data/lib/capybara/node/actions.rb +41 -37
  13. data/lib/capybara/node/base.rb +6 -6
  14. data/lib/capybara/node/document.rb +2 -2
  15. data/lib/capybara/node/document_matchers.rb +3 -3
  16. data/lib/capybara/node/element.rb +35 -21
  17. data/lib/capybara/node/finders.rb +33 -19
  18. data/lib/capybara/node/matchers.rb +72 -57
  19. data/lib/capybara/node/simple.rb +13 -3
  20. data/lib/capybara/queries/active_element_query.rb +18 -0
  21. data/lib/capybara/queries/ancestor_query.rb +4 -3
  22. data/lib/capybara/queries/base_query.rb +2 -1
  23. data/lib/capybara/queries/current_path_query.rb +14 -4
  24. data/lib/capybara/queries/selector_query.rb +91 -30
  25. data/lib/capybara/queries/sibling_query.rb +4 -3
  26. data/lib/capybara/queries/style_query.rb +1 -1
  27. data/lib/capybara/queries/text_query.rb +7 -1
  28. data/lib/capybara/rack_test/browser.rb +68 -10
  29. data/lib/capybara/rack_test/driver.rb +6 -5
  30. data/lib/capybara/rack_test/form.rb +2 -2
  31. data/lib/capybara/rack_test/node.rb +44 -16
  32. data/lib/capybara/registration_container.rb +41 -0
  33. data/lib/capybara/registrations/drivers.rb +18 -12
  34. data/lib/capybara/registrations/patches/puma_ssl.rb +3 -1
  35. data/lib/capybara/registrations/servers.rb +3 -2
  36. data/lib/capybara/result.rb +35 -15
  37. data/lib/capybara/rspec/matcher_proxies.rb +8 -8
  38. data/lib/capybara/rspec/matchers/base.rb +12 -6
  39. data/lib/capybara/rspec/matchers/count_sugar.rb +2 -1
  40. data/lib/capybara/rspec/matchers/have_ancestor.rb +4 -3
  41. data/lib/capybara/rspec/matchers/have_current_path.rb +2 -2
  42. data/lib/capybara/rspec/matchers/have_selector.rb +16 -8
  43. data/lib/capybara/rspec/matchers/have_sibling.rb +3 -3
  44. data/lib/capybara/rspec/matchers/have_text.rb +3 -3
  45. data/lib/capybara/rspec/matchers/have_title.rb +2 -2
  46. data/lib/capybara/rspec/matchers/match_selector.rb +3 -3
  47. data/lib/capybara/rspec/matchers/match_style.rb +7 -2
  48. data/lib/capybara/rspec/matchers/spatial_sugar.rb +2 -1
  49. data/lib/capybara/rspec/matchers.rb +33 -32
  50. data/lib/capybara/rspec.rb +2 -0
  51. data/lib/capybara/selector/builders/css_builder.rb +2 -2
  52. data/lib/capybara/selector/builders/xpath_builder.rb +4 -2
  53. data/lib/capybara/selector/css.rb +2 -2
  54. data/lib/capybara/selector/definition/button.rb +35 -13
  55. data/lib/capybara/selector/definition/checkbox.rb +3 -3
  56. data/lib/capybara/selector/definition/css.rb +3 -1
  57. data/lib/capybara/selector/definition/datalist_input.rb +2 -2
  58. data/lib/capybara/selector/definition/datalist_option.rb +1 -1
  59. data/lib/capybara/selector/definition/element.rb +3 -2
  60. data/lib/capybara/selector/definition/field.rb +1 -1
  61. data/lib/capybara/selector/definition/file_field.rb +2 -2
  62. data/lib/capybara/selector/definition/fillable_field.rb +3 -3
  63. data/lib/capybara/selector/definition/label.rb +5 -3
  64. data/lib/capybara/selector/definition/link.rb +8 -0
  65. data/lib/capybara/selector/definition/radio_button.rb +3 -3
  66. data/lib/capybara/selector/definition/select.rb +33 -14
  67. data/lib/capybara/selector/definition/table.rb +6 -3
  68. data/lib/capybara/selector/definition/table_row.rb +2 -2
  69. data/lib/capybara/selector/definition.rb +15 -11
  70. data/lib/capybara/selector/filter_set.rb +17 -17
  71. data/lib/capybara/selector/filters/base.rb +6 -1
  72. data/lib/capybara/selector/filters/locator_filter.rb +1 -1
  73. data/lib/capybara/selector/selector.rb +17 -3
  74. data/lib/capybara/selector.rb +37 -19
  75. data/lib/capybara/selenium/atoms/getAttribute.min.js +1 -1
  76. data/lib/capybara/selenium/atoms/src/getAttribute.js +1 -1
  77. data/lib/capybara/selenium/atoms/src/isDisplayed.js +1 -1
  78. data/lib/capybara/selenium/driver.rb +84 -17
  79. data/lib/capybara/selenium/driver_specializations/chrome_driver.rb +11 -13
  80. data/lib/capybara/selenium/driver_specializations/edge_driver.rb +10 -12
  81. data/lib/capybara/selenium/driver_specializations/firefox_driver.rb +4 -4
  82. data/lib/capybara/selenium/extensions/find.rb +4 -4
  83. data/lib/capybara/selenium/extensions/html5_drag.rb +30 -13
  84. data/lib/capybara/selenium/extensions/scroll.rb +8 -10
  85. data/lib/capybara/selenium/logger_suppressor.rb +8 -2
  86. data/lib/capybara/selenium/node.rb +122 -26
  87. data/lib/capybara/selenium/nodes/chrome_node.rb +34 -19
  88. data/lib/capybara/selenium/nodes/edge_node.rb +5 -3
  89. data/lib/capybara/selenium/nodes/firefox_node.rb +11 -6
  90. data/lib/capybara/selenium/nodes/safari_node.rb +3 -3
  91. data/lib/capybara/selenium/patches/action_pauser.rb +26 -0
  92. data/lib/capybara/selenium/patches/atoms.rb +4 -4
  93. data/lib/capybara/selenium/patches/logs.rb +7 -9
  94. data/lib/capybara/server/animation_disabler.rb +38 -15
  95. data/lib/capybara/server/checker.rb +1 -1
  96. data/lib/capybara/server/middleware.rb +22 -10
  97. data/lib/capybara/server.rb +15 -3
  98. data/lib/capybara/session/config.rb +10 -4
  99. data/lib/capybara/session/matchers.rb +11 -11
  100. data/lib/capybara/session.rb +62 -39
  101. data/lib/capybara/spec/public/test.js +75 -7
  102. data/lib/capybara/spec/session/accept_alert_spec.rb +1 -1
  103. data/lib/capybara/spec/session/active_element_spec.rb +31 -0
  104. data/lib/capybara/spec/session/all_spec.rb +63 -12
  105. data/lib/capybara/spec/session/ancestor_spec.rb +5 -0
  106. data/lib/capybara/spec/session/assert_text_spec.rb +26 -22
  107. data/lib/capybara/spec/session/check_spec.rb +15 -0
  108. data/lib/capybara/spec/session/choose_spec.rb +6 -0
  109. data/lib/capybara/spec/session/click_button_spec.rb +16 -0
  110. data/lib/capybara/spec/session/click_link_or_button_spec.rb +9 -0
  111. data/lib/capybara/spec/session/current_url_spec.rb +11 -1
  112. data/lib/capybara/spec/session/fill_in_spec.rb +29 -0
  113. data/lib/capybara/spec/session/find_spec.rb +37 -8
  114. data/lib/capybara/spec/session/has_any_selectors_spec.rb +4 -0
  115. data/lib/capybara/spec/session/has_button_spec.rb +75 -0
  116. data/lib/capybara/spec/session/has_css_spec.rb +14 -10
  117. data/lib/capybara/spec/session/has_current_path_spec.rb +17 -4
  118. data/lib/capybara/spec/session/has_field_spec.rb +41 -1
  119. data/lib/capybara/spec/session/has_link_spec.rb +30 -0
  120. data/lib/capybara/spec/session/has_select_spec.rb +36 -8
  121. data/lib/capybara/spec/session/has_selector_spec.rb +19 -4
  122. data/lib/capybara/spec/session/has_table_spec.rb +51 -5
  123. data/lib/capybara/spec/session/has_text_spec.rb +21 -1
  124. data/lib/capybara/spec/session/html_spec.rb +1 -1
  125. data/lib/capybara/spec/session/matches_style_spec.rb +2 -2
  126. data/lib/capybara/spec/session/node_spec.rb +226 -33
  127. data/lib/capybara/spec/session/refresh_spec.rb +2 -1
  128. data/lib/capybara/spec/session/save_and_open_screenshot_spec.rb +2 -2
  129. data/lib/capybara/spec/session/save_page_spec.rb +4 -4
  130. data/lib/capybara/spec/session/save_screenshot_spec.rb +4 -4
  131. data/lib/capybara/spec/session/scroll_spec.rb +4 -4
  132. data/lib/capybara/spec/session/selectors_spec.rb +15 -2
  133. data/lib/capybara/spec/session/visit_spec.rb +20 -0
  134. data/lib/capybara/spec/session/window/switch_to_window_spec.rb +1 -1
  135. data/lib/capybara/spec/session/window/window_opened_by_spec.rb +1 -1
  136. data/lib/capybara/spec/session/window/window_spec.rb +9 -9
  137. data/lib/capybara/spec/session/window/windows_spec.rb +1 -1
  138. data/lib/capybara/spec/spec_helper.rb +17 -17
  139. data/lib/capybara/spec/test_app.rb +89 -29
  140. data/lib/capybara/spec/views/animated.erb +1 -1
  141. data/lib/capybara/spec/views/form.erb +52 -6
  142. data/lib/capybara/spec/views/frame_child.erb +1 -1
  143. data/lib/capybara/spec/views/frame_one.erb +1 -1
  144. data/lib/capybara/spec/views/frame_parent.erb +1 -1
  145. data/lib/capybara/spec/views/frame_two.erb +1 -1
  146. data/lib/capybara/spec/views/initial_alert.erb +2 -1
  147. data/lib/capybara/spec/views/layout.erb +10 -0
  148. data/lib/capybara/spec/views/obscured.erb +1 -1
  149. data/lib/capybara/spec/views/offset.erb +2 -1
  150. data/lib/capybara/spec/views/path.erb +2 -2
  151. data/lib/capybara/spec/views/popup_one.erb +1 -1
  152. data/lib/capybara/spec/views/popup_two.erb +1 -1
  153. data/lib/capybara/spec/views/react.erb +2 -2
  154. data/lib/capybara/spec/views/scroll.erb +2 -1
  155. data/lib/capybara/spec/views/spatial.erb +1 -1
  156. data/lib/capybara/spec/views/with_animation.erb +10 -3
  157. data/lib/capybara/spec/views/with_base_tag.erb +2 -2
  158. data/lib/capybara/spec/views/with_dragula.erb +5 -3
  159. data/lib/capybara/spec/views/with_fixed_header_footer.erb +2 -1
  160. data/lib/capybara/spec/views/with_hover.erb +2 -2
  161. data/lib/capybara/spec/views/with_html.erb +3 -3
  162. data/lib/capybara/spec/views/with_jquery_animation.erb +24 -0
  163. data/lib/capybara/spec/views/with_js.erb +5 -3
  164. data/lib/capybara/spec/views/with_jstree.erb +1 -1
  165. data/lib/capybara/spec/views/with_namespace.erb +1 -0
  166. data/lib/capybara/spec/views/with_shadow.erb +31 -0
  167. data/lib/capybara/spec/views/with_slow_unload.erb +2 -1
  168. data/lib/capybara/spec/views/with_sortable_js.erb +3 -3
  169. data/lib/capybara/spec/views/with_unload_alert.erb +1 -0
  170. data/lib/capybara/spec/views/with_windows.erb +1 -1
  171. data/lib/capybara/spec/views/within_frames.erb +1 -1
  172. data/lib/capybara/version.rb +1 -1
  173. data/lib/capybara/window.rb +4 -8
  174. data/lib/capybara.rb +36 -29
  175. data/spec/basic_node_spec.rb +25 -11
  176. data/spec/capybara_spec.rb +1 -1
  177. data/spec/dsl_spec.rb +18 -5
  178. data/spec/fixtures/selenium_driver_rspec_failure.rb +2 -2
  179. data/spec/fixtures/selenium_driver_rspec_success.rb +3 -3
  180. data/spec/minitest_spec.rb +3 -2
  181. data/spec/minitest_spec_spec.rb +46 -46
  182. data/spec/rack_test_spec.rb +43 -11
  183. data/spec/regexp_dissassembler_spec.rb +40 -36
  184. data/spec/result_spec.rb +53 -45
  185. data/spec/rspec/features_spec.rb +7 -4
  186. data/spec/rspec/scenarios_spec.rb +5 -1
  187. data/spec/rspec/shared_spec_matchers.rb +68 -56
  188. data/spec/rspec_spec.rb +8 -4
  189. data/spec/sauce_spec_chrome.rb +3 -3
  190. data/spec/selector_spec.rb +19 -4
  191. data/spec/selenium_spec_chrome.rb +49 -26
  192. data/spec/selenium_spec_chrome_remote.rb +13 -6
  193. data/spec/selenium_spec_firefox.rb +29 -17
  194. data/spec/selenium_spec_firefox_remote.rb +2 -2
  195. data/spec/selenium_spec_ie.rb +3 -6
  196. data/spec/selenium_spec_safari.rb +31 -19
  197. data/spec/server_spec.rb +88 -35
  198. data/spec/session_spec.rb +1 -1
  199. data/spec/shared_selenium_node.rb +21 -7
  200. data/spec/shared_selenium_session.rb +123 -21
  201. data/spec/spec_helper.rb +2 -2
  202. metadata +80 -21
  203. data/lib/capybara/spec/session/source_spec.rb +0 -0
  204. data/lib/capybara/spec/views/with_title.erb +0 -5
@@ -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
 
@@ -1,12 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'spec_helper'
4
- nokogumbo_required = begin
5
- require 'nokogumbo'
6
- true
7
- rescue LoadError
8
- false
9
- end
10
4
 
11
5
  module TestSessions
12
6
  RackTest = Capybara::Session.new(:rack_test, TestApp)
@@ -26,6 +20,9 @@ skipped_tests = %i[
26
20
  css
27
21
  scroll
28
22
  spatial
23
+ html_validation
24
+ shadow_dom
25
+ active_element
29
26
  ]
30
27
  Capybara::SpecHelper.run_specs TestSessions::RackTest, 'RackTest', capybara_skip: skipped_tests do |example|
31
28
  case example.metadata[:full_description]
@@ -37,6 +34,7 @@ Capybara::SpecHelper.run_specs TestSessions::RackTest, 'RackTest', capybara_skip
37
34
  end
38
35
 
39
36
  RSpec.describe Capybara::Session do # rubocop:disable RSpec/MultipleDescribes
37
+ include Capybara::RSpecMatchers
40
38
  context 'with rack test driver' do
41
39
  let(:session) { TestSessions::RackTest }
42
40
 
@@ -82,7 +80,6 @@ RSpec.describe Capybara::Session do # rubocop:disable RSpec/MultipleDescribes
82
80
  describe '#fill_in' do
83
81
  it 'should warn that :fill_options are not supported' do
84
82
  session.visit '/with_html'
85
-
86
83
  expect { session.fill_in 'test_field', with: 'not_monkey', fill_options: { random: true } }.to \
87
84
  output(/^Options passed to Node#set but the RackTest driver doesn't support any - ignoring/).to_stderr
88
85
  expect(session).to have_field('test_field', with: 'not_monkey')
@@ -128,6 +125,34 @@ RSpec.describe Capybara::Session do # rubocop:disable RSpec/MultipleDescribes
128
125
  session.find(:label, 'Female').click
129
126
  expect(session).to have_unchecked_field('gender_male')
130
127
  end
128
+
129
+ it 'should rewrite the forms action query for get submission' do
130
+ session.visit('/form')
131
+ session.click_button('mediocre')
132
+ expect(session).not_to have_current_path(/foo|bar/)
133
+ end
134
+
135
+ it 'should rewrite the submit buttons formaction query for get submission' do
136
+ session.visit('/form')
137
+ session.click_button('mediocre2')
138
+ expect(session).not_to have_current_path(/foo|bar/)
139
+ end
140
+ end
141
+ end
142
+
143
+ describe '#send_keys' do
144
+ it 'raises an UnsupportedMethodError' do
145
+ session.visit('/form')
146
+
147
+ expect { session.send_keys(:tab) }.to raise_error(Capybara::NotSupportedByDriverError)
148
+ end
149
+ end
150
+
151
+ describe '#active_element' do
152
+ it 'raises an UnsupportedMethodError' do
153
+ session.visit('/form')
154
+
155
+ expect { session.active_element }.to raise_error(Capybara::NotSupportedByDriverError)
131
156
  end
132
157
  end
133
158
 
@@ -191,6 +216,12 @@ RSpec.describe Capybara::RackTest::Driver do
191
216
  expect(driver.current_url).to match %r{/landed$}
192
217
  end
193
218
 
219
+ it 'should not include fragments in the referer header' do
220
+ driver.visit('/header_links#an-anchor')
221
+ driver.find_xpath('.//input').first.click
222
+ expect(driver.request.get_header('HTTP_REFERER')).to eq('http://www.example.com/header_links')
223
+ end
224
+
194
225
  it 'is possible to not follow redirects' do
195
226
  driver = described_class.new(TestApp, follow_redirects: false)
196
227
 
@@ -234,11 +265,12 @@ RSpec.describe Capybara::RackTest::Driver do
234
265
  end
235
266
 
236
267
  RSpec.describe 'Capybara::String' do
237
- it 'should use gumbo' do
238
- skip 'Only valid if gumbo is included' unless nokogumbo_required
239
- allow(Nokogiri).to receive(:HTML5).and_call_original
268
+ it 'should use HTML5 parsing' do
269
+ skip 'Only valid if Nokogiri >= 1.12.0 or gumbo is included' unless defined? Nokogiri::HTML5
270
+ Capybara.use_html5_parsing = true
271
+ allow(Nokogiri::HTML5).to receive(:parse).and_call_original
240
272
  Capybara.string('<div id=test_div></div>')
241
- expect(Nokogiri).to have_received(:HTML5)
273
+ expect(Nokogiri::HTML5).to have_received(:parse)
242
274
  end
243
275
  end
244
276
 
@@ -50,14 +50,16 @@ RSpec.describe Capybara::Selector::RegexpDisassembler, :aggregate_failures do
50
50
 
51
51
  it 'handles optional characters for #alternated_substrings' do
52
52
  verify_alternated_strings(
53
- /abc*def/ => [%w[ab def]],
54
- /abc*/ => [%w[ab]],
55
- /c*/ => [],
56
- /abc?def/ => [%w[abdef], %w[abcdef]],
57
- /abc?/ => [%w[ab]],
58
- /abc?def?/ => [%w[abde], %w[abcde]],
59
- /abc?def?g/ => [%w[abdeg], %w[abdefg], %w[abcdeg], %w[abcdefg]],
60
- /d?/ => []
53
+ {
54
+ /abc*def/ => [%w[ab def]],
55
+ /abc*/ => [%w[ab]],
56
+ /c*/ => [],
57
+ /abc?def/ => [%w[abdef], %w[abcdef]],
58
+ /abc?/ => [%w[ab]],
59
+ /abc?def?/ => [%w[abde], %w[abcde]],
60
+ /abc?def?g/ => [%w[abdeg], %w[abdefg], %w[abcdeg], %w[abcdefg]],
61
+ /d?/ => []
62
+ }
61
63
  )
62
64
  end
63
65
 
@@ -137,34 +139,36 @@ RSpec.describe Capybara::Selector::RegexpDisassembler, :aggregate_failures do
137
139
 
138
140
  it 'handles alternation for #alternated_substrings' do
139
141
  verify_alternated_strings(
140
- /abc|def/ => [%w[abc], %w[def]],
141
- /ab(?:c|d)/ => [%w[abc], %w[abd]],
142
- /ab(c|d|e)fg/ => [%w[abcfg], %w[abdfg], %w[abefg]],
143
- /ab?(c|d)fg/ => [%w[acfg], %w[adfg], %w[abcfg], %w[abdfg]],
144
- /ab(c|d)ef/ => [%w[abcef], %w[abdef]],
145
- /ab(cd?|ef)g/ => [%w[abcg], %w[abcdg], %w[abefg]],
146
- /ab(cd|ef*)g/ => [%w[abcdg], %w[abe g]],
147
- /ab|cd*/ => [%w[ab], %w[c]],
148
- /cd(?:ef|gh)|xyz/ => [%w[cdef], %w[cdgh], %w[xyz]],
149
- /(cd(?:ef|gh)|xyz)/ => [%w[cdef], %w[cdgh], %w[xyz]],
150
- /cd(ef|gh)+/ => [%w[cdef], %w[cdgh]],
151
- /cd(ef|gh)?/ => [%w[cd]],
152
- /cd(ef|gh)?ij/ => [%w[cdij], %w[cdefij], %w[cdghij]],
153
- /cd(ef|gh)+ij/ => [%w[cdef ij], %w[cdgh ij]],
154
- /cd(ef|gh){2}ij/ => [%w[cdefefij], %w[cdefghij], %w[cdghefij], %w[cdghghij]],
155
- /(cd(ef|g*))/ => [%w[cd]],
156
- /a|b*/ => [],
157
- /ab(?:c|d?)/ => [%w[ab]],
158
- /ab(c|d)|a*/ => [],
159
- /(abc)?(d|e)/ => [%w[d], %w[e]],
160
- /(abc*de)?(d|e)/ => [%w[d], %w[e]],
161
- /(abc*de)?(d|e?)/ => [],
162
- /(abc)?(d|e?)/ => [],
163
- /ab(cd){0,2}ef/ => [%w[ab ef]],
164
- /ab(cd){0,1}ef/ => [%w[abef], %w[abcdef]],
165
- /ab(cd|cd)ef/ => [%w[abcdef]],
166
- /ab(cd|cd)?ef/ => [%w[abef], %w[abcdef]],
167
- /ab\\?cd/ => [%w[abcd], %w[ab\cd]]
142
+ {
143
+ /abc|def/ => [%w[abc], %w[def]],
144
+ /ab(?:c|d)/ => [%w[abc], %w[abd]],
145
+ /ab(c|d|e)fg/ => [%w[abcfg], %w[abdfg], %w[abefg]],
146
+ /ab?(c|d)fg/ => [%w[acfg], %w[adfg], %w[abcfg], %w[abdfg]],
147
+ /ab(c|d)ef/ => [%w[abcef], %w[abdef]],
148
+ /ab(cd?|ef)g/ => [%w[abcg], %w[abcdg], %w[abefg]],
149
+ /ab(cd|ef*)g/ => [%w[abcdg], %w[abe g]],
150
+ /ab|cd*/ => [%w[ab], %w[c]],
151
+ /cd(?:ef|gh)|xyz/ => [%w[cdef], %w[cdgh], %w[xyz]],
152
+ /(cd(?:ef|gh)|xyz)/ => [%w[cdef], %w[cdgh], %w[xyz]],
153
+ /cd(ef|gh)+/ => [%w[cdef], %w[cdgh]],
154
+ /cd(ef|gh)?/ => [%w[cd]],
155
+ /cd(ef|gh)?ij/ => [%w[cdij], %w[cdefij], %w[cdghij]],
156
+ /cd(ef|gh)+ij/ => [%w[cdef ij], %w[cdgh ij]],
157
+ /cd(ef|gh){2}ij/ => [%w[cdefefij], %w[cdefghij], %w[cdghefij], %w[cdghghij]],
158
+ /(cd(ef|g*))/ => [%w[cd]],
159
+ /a|b*/ => [],
160
+ /ab(?:c|d?)/ => [%w[ab]],
161
+ /ab(c|d)|a*/ => [],
162
+ /(abc)?(d|e)/ => [%w[d], %w[e]],
163
+ /(abc*de)?(d|e)/ => [%w[d], %w[e]],
164
+ /(abc*de)?(d|e?)/ => [],
165
+ /(abc)?(d|e?)/ => [],
166
+ /ab(cd){0,2}ef/ => [%w[ab ef]],
167
+ /ab(cd){0,1}ef/ => [%w[abef], %w[abcdef]],
168
+ /ab(cd|cd)ef/ => [%w[abcdef]],
169
+ /ab(cd|cd)?ef/ => [%w[abef], %w[abcdef]],
170
+ /ab\\?cd/ => [%w[abcd], %w[ab\cd]]
171
+ }
168
172
  )
169
173
  end
170
174
 
data/spec/result_spec.rb CHANGED
@@ -44,9 +44,9 @@ RSpec.describe Capybara::Result do
44
44
  end
45
45
 
46
46
  it 'can be selected' do
47
- expect(result.select do |element|
47
+ expect(result.count do |element|
48
48
  element.text.include? 't'
49
- end.length).to eq(2)
49
+ end).to eq(2)
50
50
  end
51
51
 
52
52
  it 'can be reduced' do
@@ -65,19 +65,43 @@ 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
79
- expect(result[2..].map(&:text)).to eq %w[Gamma Delta]
80
- TEST
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] # rubocop:disable Style/SlicingWithRange
82
+ expect(recalc_result[2..].map(&:text)).to eq %w[Gamma Delta]
83
+ end
84
+
85
+ it 'supports endless ranges' do
86
+ expect(result[2..].map(&:text)).to eq %w[Gamma Delta]
87
+ end
88
+
89
+ it 'supports inclusive positive beginless ranges' do
90
+ expect(result[..2].map(&:text)).to eq %w[Alpha Beta Gamma]
91
+ end
92
+
93
+ it 'supports inclusive negative beginless ranges' do
94
+ expect(result[..-2].map(&:text)).to eq %w[Alpha Beta Gamma]
95
+ expect(result[..-1].map(&:text)).to eq %w[Alpha Beta Gamma Delta]
96
+ end
97
+
98
+ it 'supports exclusive positive beginless ranges' do
99
+ expect(result[...2].map(&:text)).to eq %w[Alpha Beta]
100
+ end
101
+
102
+ it 'supports exclusive negative beginless ranges' do
103
+ expect(result[...-2].map(&:text)).to eq %w[Alpha Beta]
104
+ expect(result[...-1].map(&:text)).to eq %w[Alpha Beta Gamma]
81
105
  end
82
106
 
83
107
  it 'works with filter blocks' do
@@ -89,61 +113,61 @@ RSpec.describe Capybara::Result do
89
113
  it 'should evaluate filters lazily for idx' do
90
114
  skip 'JRuby has an issue with lazy enumerator evaluation' if jruby_lazy_enumerator_workaround?
91
115
  # Not processed until accessed
92
- expect(result.instance_variable_get('@result_cache').size).to be 0
116
+ expect(result.instance_variable_get(:@result_cache).size).to be 0
93
117
 
94
118
  # Only one retrieved when needed
95
119
  result.first
96
- expect(result.instance_variable_get('@result_cache').size).to be 1
120
+ expect(result.instance_variable_get(:@result_cache).size).to be 1
97
121
 
98
122
  # works for indexed access
99
123
  result[0]
100
- expect(result.instance_variable_get('@result_cache').size).to be 1
124
+ expect(result.instance_variable_get(:@result_cache).size).to be 1
101
125
 
102
126
  result[2]
103
- expect(result.instance_variable_get('@result_cache').size).to be 3
127
+ expect(result.instance_variable_get(:@result_cache).size).to be 3
104
128
 
105
129
  # All cached when converted to array
106
130
  result.to_a
107
- expect(result.instance_variable_get('@result_cache').size).to eq 4
131
+ expect(result.instance_variable_get(:@result_cache).size).to eq 4
108
132
  end
109
133
 
110
134
  it 'should evaluate filters lazily for range' do
111
135
  skip 'JRuby has an issue with lazy enumerator evaluation' if jruby_lazy_enumerator_workaround?
112
136
  result[0..1]
113
- expect(result.instance_variable_get('@result_cache').size).to be 2
137
+ expect(result.instance_variable_get(:@result_cache).size).to be 2
114
138
 
115
139
  expect(result[0..7].size).to eq 4
116
- expect(result.instance_variable_get('@result_cache').size).to be 4
140
+ expect(result.instance_variable_get(:@result_cache).size).to be 4
117
141
  end
118
142
 
119
143
  it 'should evaluate filters lazily for idx and length' do
120
144
  skip 'JRuby has an issue with lazy enumerator evaluation' if jruby_lazy_enumerator_workaround?
121
145
  result[1, 2]
122
- expect(result.instance_variable_get('@result_cache').size).to be 3
146
+ expect(result.instance_variable_get(:@result_cache).size).to be 3
123
147
 
124
148
  expect(result[2, 5].size).to eq 2
125
- expect(result.instance_variable_get('@result_cache').size).to be 4
149
+ expect(result.instance_variable_get(:@result_cache).size).to be 4
126
150
  end
127
151
 
128
152
  it 'should only need to evaluate one result for any?' do
129
153
  skip 'JRuby has an issue with lazy enumerator evaluation' if jruby_lazy_enumerator_workaround?
130
154
  result.any?
131
- expect(result.instance_variable_get('@result_cache').size).to be 1
155
+ expect(result.instance_variable_get(:@result_cache).size).to be 1
132
156
  end
133
157
 
134
158
  it 'should evaluate all elements when #to_a called' do
135
159
  # All cached when converted to array
136
160
  result.to_a
137
- expect(result.instance_variable_get('@result_cache').size).to eq 4
161
+ expect(result.instance_variable_get(:@result_cache).size).to eq 4
138
162
  end
139
163
 
140
- context '#each' do
164
+ describe '#each' do
141
165
  it 'lazily evaluates' do
142
166
  skip 'JRuby has an issue with lazy enumerator evaluation' if jruby_lazy_enumerator_workaround?
143
167
  results = []
144
168
  result.each do |el|
145
169
  results << el
146
- expect(result.instance_variable_get('@result_cache').size).to eq results.size
170
+ expect(result.instance_variable_get(:@result_cache).size).to eq results.size
147
171
  end
148
172
 
149
173
  expect(results.size).to eq 4
@@ -157,29 +181,13 @@ RSpec.describe Capybara::Result do
157
181
  it 'lazily evaluates' do
158
182
  skip 'JRuby has an issue with lazy enumerator evaluation' if jruby_lazy_enumerator_workaround?
159
183
  result.each.with_index do |_el, idx|
160
- expect(result.instance_variable_get('@result_cache').size).to eq(idx + 1) # 0 indexing
184
+ expect(result.instance_variable_get(:@result_cache).size).to eq(idx + 1) # 0 indexing
161
185
  end
162
186
  end
163
187
  end
164
188
  end
165
189
 
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
190
  def jruby_lazy_enumerator_workaround?
183
- (RUBY_PLATFORM == 'java') && (Gem::Version.new(JRUBY_VERSION) < Gem::Version.new('9.2.8.0'))
191
+ RUBY_PLATFORM == 'java'
184
192
  end
185
193
  end
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ # rubocop:disable RSpec/MultipleDescribes
4
+
3
5
  require 'spec_helper'
4
6
  require 'capybara/rspec'
5
7
 
@@ -81,6 +83,7 @@ xfeature 'if xfeature aliases to pending then' do
81
83
  scenario "this should be 'temporarily disabled with xfeature'" do
82
84
  # dummy
83
85
  end
86
+
84
87
  scenario "this also should be 'temporarily disabled with xfeature'" do
85
88
  # dummy
86
89
  end
@@ -88,11 +91,11 @@ end
88
91
 
89
92
  ffeature 'if ffeature aliases focused tag then' do # rubocop:disable RSpec/Focus
90
93
  scenario 'scenario inside this feature has metatag focus tag' do |example|
91
- expect(example.metadata[:focus]).to eq true
94
+ expect(example.metadata[:focus]).to be true
92
95
  end
93
96
 
94
- scenario 'other scenarios also has metatag focus tag ' do |example|
95
- expect(example.metadata[:focus]).to eq true
97
+ scenario 'other scenarios also has metatag focus tag' do |example|
98
+ expect(example.metadata[:focus]).to be true
96
99
  end
97
100
  end
98
- # rubocop:enable RSpec/RepeatedExample
101
+ # rubocop:enable RSpec/RepeatedExample, RSpec/MultipleDescribes
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ # rubocop:disable RSpec/MultipleDescribes
4
+
3
5
  require 'spec_helper'
4
6
  require 'capybara/rspec'
5
7
 
@@ -9,7 +11,7 @@ end
9
11
 
10
12
  feature 'if fscenario aliases focused tag then' do
11
13
  fscenario 'scenario should have focused meta tag' do |example| # rubocop:disable RSpec/Focus
12
- expect(example.metadata[:focus]).to eq true
14
+ expect(example.metadata[:focus]).to be true
13
15
  end
14
16
  end
15
17
 
@@ -17,3 +19,5 @@ feature 'if xscenario aliases to pending then' do
17
19
  xscenario "this test should be 'temporarily disabled with xscenario'" do
18
20
  end
19
21
  end
22
+
23
+ # rubocop:enable RSpec/MultipleDescribes