capybara 3.3.0 → 3.40.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (308) hide show
  1. checksums.yaml +4 -4
  2. data/.yardopts +1 -0
  3. data/History.md +803 -13
  4. data/License.txt +1 -1
  5. data/README.md +257 -84
  6. data/lib/capybara/config.rb +25 -9
  7. data/lib/capybara/cucumber.rb +1 -1
  8. data/lib/capybara/driver/base.rb +17 -3
  9. data/lib/capybara/driver/node.rb +31 -6
  10. data/lib/capybara/dsl.rb +9 -7
  11. data/lib/capybara/helpers.rb +31 -7
  12. data/lib/capybara/minitest/spec.rb +180 -88
  13. data/lib/capybara/minitest.rb +262 -149
  14. data/lib/capybara/node/actions.rb +202 -116
  15. data/lib/capybara/node/base.rb +34 -19
  16. data/lib/capybara/node/document.rb +14 -2
  17. data/lib/capybara/node/document_matchers.rb +10 -12
  18. data/lib/capybara/node/element.rb +269 -115
  19. data/lib/capybara/node/finders.rb +99 -77
  20. data/lib/capybara/node/matchers.rb +327 -151
  21. data/lib/capybara/node/simple.rb +48 -13
  22. data/lib/capybara/node/whitespace_normalizer.rb +81 -0
  23. data/lib/capybara/queries/active_element_query.rb +18 -0
  24. data/lib/capybara/queries/ancestor_query.rb +8 -9
  25. data/lib/capybara/queries/base_query.rb +23 -16
  26. data/lib/capybara/queries/current_path_query.rb +16 -6
  27. data/lib/capybara/queries/match_query.rb +1 -0
  28. data/lib/capybara/queries/selector_query.rb +587 -130
  29. data/lib/capybara/queries/sibling_query.rb +8 -6
  30. data/lib/capybara/queries/style_query.rb +6 -2
  31. data/lib/capybara/queries/text_query.rb +28 -14
  32. data/lib/capybara/queries/title_query.rb +2 -2
  33. data/lib/capybara/rack_test/browser.rb +92 -25
  34. data/lib/capybara/rack_test/driver.rb +16 -7
  35. data/lib/capybara/rack_test/errors.rb +6 -0
  36. data/lib/capybara/rack_test/form.rb +68 -41
  37. data/lib/capybara/rack_test/node.rb +106 -39
  38. data/lib/capybara/rails.rb +1 -1
  39. data/lib/capybara/registration_container.rb +41 -0
  40. data/lib/capybara/registrations/drivers.rb +42 -0
  41. data/lib/capybara/registrations/patches/puma_ssl.rb +29 -0
  42. data/lib/capybara/registrations/servers.rb +66 -0
  43. data/lib/capybara/result.rb +75 -52
  44. data/lib/capybara/rspec/features.rb +7 -7
  45. data/lib/capybara/rspec/matcher_proxies.rb +39 -18
  46. data/lib/capybara/rspec/matchers/base.rb +113 -0
  47. data/lib/capybara/rspec/matchers/become_closed.rb +33 -0
  48. data/lib/capybara/rspec/matchers/compound.rb +88 -0
  49. data/lib/capybara/rspec/matchers/count_sugar.rb +37 -0
  50. data/lib/capybara/rspec/matchers/have_ancestor.rb +28 -0
  51. data/lib/capybara/rspec/matchers/have_current_path.rb +29 -0
  52. data/lib/capybara/rspec/matchers/have_selector.rb +69 -0
  53. data/lib/capybara/rspec/matchers/have_sibling.rb +27 -0
  54. data/lib/capybara/rspec/matchers/have_text.rb +33 -0
  55. data/lib/capybara/rspec/matchers/have_title.rb +29 -0
  56. data/lib/capybara/rspec/matchers/match_selector.rb +27 -0
  57. data/lib/capybara/rspec/matchers/match_style.rb +43 -0
  58. data/lib/capybara/rspec/matchers/spatial_sugar.rb +39 -0
  59. data/lib/capybara/rspec/matchers.rb +141 -339
  60. data/lib/capybara/rspec.rb +2 -0
  61. data/lib/capybara/selector/builders/css_builder.rb +84 -0
  62. data/lib/capybara/selector/builders/xpath_builder.rb +71 -0
  63. data/lib/capybara/selector/css.rb +27 -25
  64. data/lib/capybara/selector/definition/button.rb +68 -0
  65. data/lib/capybara/selector/definition/checkbox.rb +26 -0
  66. data/lib/capybara/selector/definition/css.rb +10 -0
  67. data/lib/capybara/selector/definition/datalist_input.rb +35 -0
  68. data/lib/capybara/selector/definition/datalist_option.rb +25 -0
  69. data/lib/capybara/selector/definition/element.rb +28 -0
  70. data/lib/capybara/selector/definition/field.rb +40 -0
  71. data/lib/capybara/selector/definition/fieldset.rb +14 -0
  72. data/lib/capybara/selector/definition/file_field.rb +13 -0
  73. data/lib/capybara/selector/definition/fillable_field.rb +33 -0
  74. data/lib/capybara/selector/definition/frame.rb +17 -0
  75. data/lib/capybara/selector/definition/id.rb +6 -0
  76. data/lib/capybara/selector/definition/label.rb +62 -0
  77. data/lib/capybara/selector/definition/link.rb +55 -0
  78. data/lib/capybara/selector/definition/link_or_button.rb +16 -0
  79. data/lib/capybara/selector/definition/option.rb +27 -0
  80. data/lib/capybara/selector/definition/radio_button.rb +27 -0
  81. data/lib/capybara/selector/definition/select.rb +81 -0
  82. data/lib/capybara/selector/definition/table.rb +109 -0
  83. data/lib/capybara/selector/definition/table_row.rb +21 -0
  84. data/lib/capybara/selector/definition/xpath.rb +5 -0
  85. data/lib/capybara/selector/definition.rb +280 -0
  86. data/lib/capybara/selector/filter.rb +1 -0
  87. data/lib/capybara/selector/filter_set.rb +73 -25
  88. data/lib/capybara/selector/filters/base.rb +24 -5
  89. data/lib/capybara/selector/filters/expression_filter.rb +3 -3
  90. data/lib/capybara/selector/filters/locator_filter.rb +29 -0
  91. data/lib/capybara/selector/filters/node_filter.rb +16 -2
  92. data/lib/capybara/selector/regexp_disassembler.rb +211 -0
  93. data/lib/capybara/selector/selector.rb +85 -348
  94. data/lib/capybara/selector/xpath_extensions.rb +17 -0
  95. data/lib/capybara/selector.rb +474 -447
  96. data/lib/capybara/selenium/atoms/getAttribute.min.js +1 -0
  97. data/lib/capybara/selenium/atoms/isDisplayed.min.js +1 -0
  98. data/lib/capybara/selenium/atoms/src/getAttribute.js +161 -0
  99. data/lib/capybara/selenium/atoms/src/isDisplayed.js +454 -0
  100. data/lib/capybara/selenium/driver.rb +255 -143
  101. data/lib/capybara/selenium/driver_specializations/chrome_driver.rb +93 -11
  102. data/lib/capybara/selenium/driver_specializations/edge_driver.rb +128 -0
  103. data/lib/capybara/selenium/driver_specializations/firefox_driver.rb +84 -0
  104. data/lib/capybara/selenium/driver_specializations/internet_explorer_driver.rb +26 -0
  105. data/lib/capybara/selenium/driver_specializations/safari_driver.rb +24 -0
  106. data/lib/capybara/selenium/extensions/file_input_click_emulation.rb +34 -0
  107. data/lib/capybara/selenium/extensions/find.rb +110 -0
  108. data/lib/capybara/selenium/extensions/html5_drag.rb +229 -0
  109. data/lib/capybara/selenium/extensions/modifier_keys_stack.rb +28 -0
  110. data/lib/capybara/selenium/extensions/scroll.rb +76 -0
  111. data/lib/capybara/selenium/node.rb +436 -134
  112. data/lib/capybara/selenium/nodes/chrome_node.rb +125 -0
  113. data/lib/capybara/selenium/nodes/edge_node.rb +110 -0
  114. data/lib/capybara/selenium/nodes/firefox_node.rb +136 -0
  115. data/lib/capybara/selenium/nodes/ie_node.rb +22 -0
  116. data/lib/capybara/selenium/nodes/safari_node.rb +118 -0
  117. data/lib/capybara/selenium/patches/atoms.rb +18 -0
  118. data/lib/capybara/selenium/patches/is_displayed.rb +16 -0
  119. data/lib/capybara/selenium/patches/logs.rb +45 -0
  120. data/lib/capybara/selenium/patches/pause_duration_fix.rb +9 -0
  121. data/lib/capybara/selenium/patches/persistent_client.rb +20 -0
  122. data/lib/capybara/server/animation_disabler.rb +56 -19
  123. data/lib/capybara/server/checker.rb +9 -3
  124. data/lib/capybara/server/middleware.rb +28 -12
  125. data/lib/capybara/server.rb +33 -10
  126. data/lib/capybara/session/config.rb +34 -10
  127. data/lib/capybara/session/matchers.rb +23 -16
  128. data/lib/capybara/session.rb +230 -170
  129. data/lib/capybara/spec/public/jquery.js +5 -5
  130. data/lib/capybara/spec/public/offset.js +6 -0
  131. data/lib/capybara/spec/public/test.js +121 -8
  132. data/lib/capybara/spec/session/accept_alert_spec.rb +11 -11
  133. data/lib/capybara/spec/session/accept_confirm_spec.rb +3 -3
  134. data/lib/capybara/spec/session/accept_prompt_spec.rb +9 -10
  135. data/lib/capybara/spec/session/active_element_spec.rb +31 -0
  136. data/lib/capybara/spec/session/all_spec.rb +127 -40
  137. data/lib/capybara/spec/session/ancestor_spec.rb +24 -19
  138. data/lib/capybara/spec/session/assert_all_of_selectors_spec.rb +67 -38
  139. data/lib/capybara/spec/session/assert_current_path_spec.rb +21 -18
  140. data/lib/capybara/spec/session/assert_selector_spec.rb +52 -58
  141. data/lib/capybara/spec/session/assert_style_spec.rb +7 -7
  142. data/lib/capybara/spec/session/assert_text_spec.rb +74 -50
  143. data/lib/capybara/spec/session/assert_title_spec.rb +12 -12
  144. data/lib/capybara/spec/session/attach_file_spec.rb +126 -72
  145. data/lib/capybara/spec/session/body_spec.rb +6 -6
  146. data/lib/capybara/spec/session/check_spec.rb +102 -47
  147. data/lib/capybara/spec/session/choose_spec.rb +58 -32
  148. data/lib/capybara/spec/session/click_button_spec.rb +219 -163
  149. data/lib/capybara/spec/session/click_link_or_button_spec.rb +49 -23
  150. data/lib/capybara/spec/session/click_link_spec.rb +77 -54
  151. data/lib/capybara/spec/session/current_scope_spec.rb +8 -8
  152. data/lib/capybara/spec/session/current_url_spec.rb +38 -29
  153. data/lib/capybara/spec/session/dismiss_confirm_spec.rb +3 -3
  154. data/lib/capybara/spec/session/dismiss_prompt_spec.rb +2 -2
  155. data/lib/capybara/spec/session/element/assert_match_selector_spec.rb +8 -8
  156. data/lib/capybara/spec/session/element/match_css_spec.rb +16 -10
  157. data/lib/capybara/spec/session/element/match_xpath_spec.rb +6 -6
  158. data/lib/capybara/spec/session/element/matches_selector_spec.rb +68 -56
  159. data/lib/capybara/spec/session/evaluate_async_script_spec.rb +7 -7
  160. data/lib/capybara/spec/session/evaluate_script_spec.rb +28 -8
  161. data/lib/capybara/spec/session/execute_script_spec.rb +8 -7
  162. data/lib/capybara/spec/session/fill_in_spec.rb +101 -46
  163. data/lib/capybara/spec/session/find_button_spec.rb +23 -23
  164. data/lib/capybara/spec/session/find_by_id_spec.rb +7 -7
  165. data/lib/capybara/spec/session/find_field_spec.rb +32 -30
  166. data/lib/capybara/spec/session/find_link_spec.rb +31 -21
  167. data/lib/capybara/spec/session/find_spec.rb +244 -141
  168. data/lib/capybara/spec/session/first_spec.rb +43 -43
  169. data/lib/capybara/spec/session/frame/frame_title_spec.rb +5 -5
  170. data/lib/capybara/spec/session/frame/frame_url_spec.rb +5 -5
  171. data/lib/capybara/spec/session/frame/switch_to_frame_spec.rb +30 -18
  172. data/lib/capybara/spec/session/frame/within_frame_spec.rb +45 -18
  173. data/lib/capybara/spec/session/go_back_spec.rb +1 -1
  174. data/lib/capybara/spec/session/go_forward_spec.rb +1 -1
  175. data/lib/capybara/spec/session/has_all_selectors_spec.rb +23 -23
  176. data/lib/capybara/spec/session/has_ancestor_spec.rb +46 -0
  177. data/lib/capybara/spec/session/has_any_selectors_spec.rb +29 -0
  178. data/lib/capybara/spec/session/has_button_spec.rb +94 -13
  179. data/lib/capybara/spec/session/has_css_spec.rb +272 -132
  180. data/lib/capybara/spec/session/has_current_path_spec.rb +50 -35
  181. data/lib/capybara/spec/session/has_element_spec.rb +47 -0
  182. data/lib/capybara/spec/session/has_field_spec.rb +137 -58
  183. data/lib/capybara/spec/session/has_link_spec.rb +44 -4
  184. data/lib/capybara/spec/session/has_none_selectors_spec.rb +31 -31
  185. data/lib/capybara/spec/session/has_select_spec.rb +84 -50
  186. data/lib/capybara/spec/session/has_selector_spec.rb +111 -71
  187. data/lib/capybara/spec/session/has_sibling_spec.rb +50 -0
  188. data/lib/capybara/spec/session/has_table_spec.rb +181 -4
  189. data/lib/capybara/spec/session/has_text_spec.rb +101 -53
  190. data/lib/capybara/spec/session/has_title_spec.rb +19 -14
  191. data/lib/capybara/spec/session/has_xpath_spec.rb +56 -38
  192. data/lib/capybara/spec/session/headers_spec.rb +1 -1
  193. data/lib/capybara/spec/session/html_spec.rb +13 -6
  194. data/lib/capybara/spec/session/matches_style_spec.rb +37 -0
  195. data/lib/capybara/spec/session/node_spec.rb +894 -142
  196. data/lib/capybara/spec/session/node_wrapper_spec.rb +10 -7
  197. data/lib/capybara/spec/session/refresh_spec.rb +9 -7
  198. data/lib/capybara/spec/session/reset_session_spec.rb +63 -35
  199. data/lib/capybara/spec/session/response_code_spec.rb +1 -1
  200. data/lib/capybara/spec/session/save_and_open_page_spec.rb +2 -2
  201. data/lib/capybara/spec/session/save_and_open_screenshot_spec.rb +2 -2
  202. data/lib/capybara/spec/session/save_page_spec.rb +37 -37
  203. data/lib/capybara/spec/session/save_screenshot_spec.rb +10 -10
  204. data/lib/capybara/spec/session/screenshot_spec.rb +2 -2
  205. data/lib/capybara/spec/session/scroll_spec.rb +119 -0
  206. data/lib/capybara/spec/session/select_spec.rb +85 -85
  207. data/lib/capybara/spec/session/selectors_spec.rb +49 -18
  208. data/lib/capybara/spec/session/sibling_spec.rb +9 -9
  209. data/lib/capybara/spec/session/text_spec.rb +25 -24
  210. data/lib/capybara/spec/session/title_spec.rb +7 -6
  211. data/lib/capybara/spec/session/uncheck_spec.rb +33 -21
  212. data/lib/capybara/spec/session/unselect_spec.rb +37 -37
  213. data/lib/capybara/spec/session/visit_spec.rb +68 -49
  214. data/lib/capybara/spec/session/window/become_closed_spec.rb +20 -17
  215. data/lib/capybara/spec/session/window/current_window_spec.rb +1 -1
  216. data/lib/capybara/spec/session/window/switch_to_window_spec.rb +20 -16
  217. data/lib/capybara/spec/session/window/window_opened_by_spec.rb +6 -2
  218. data/lib/capybara/spec/session/window/window_spec.rb +62 -63
  219. data/lib/capybara/spec/session/window/windows_spec.rb +5 -1
  220. data/lib/capybara/spec/session/window/within_window_spec.rb +14 -14
  221. data/lib/capybara/spec/session/within_spec.rb +79 -42
  222. data/lib/capybara/spec/spec_helper.rb +41 -53
  223. data/lib/capybara/spec/test_app.rb +132 -43
  224. data/lib/capybara/spec/views/animated.erb +49 -0
  225. data/lib/capybara/spec/views/form.erb +139 -42
  226. data/lib/capybara/spec/views/frame_child.erb +4 -3
  227. data/lib/capybara/spec/views/frame_one.erb +2 -1
  228. data/lib/capybara/spec/views/frame_parent.erb +1 -1
  229. data/lib/capybara/spec/views/frame_two.erb +1 -1
  230. data/lib/capybara/spec/views/initial_alert.erb +2 -1
  231. data/lib/capybara/spec/views/layout.erb +10 -0
  232. data/lib/capybara/spec/views/obscured.erb +47 -0
  233. data/lib/capybara/spec/views/offset.erb +33 -0
  234. data/lib/capybara/spec/views/path.erb +2 -2
  235. data/lib/capybara/spec/views/popup_one.erb +1 -1
  236. data/lib/capybara/spec/views/popup_two.erb +1 -1
  237. data/lib/capybara/spec/views/react.erb +45 -0
  238. data/lib/capybara/spec/views/scroll.erb +21 -0
  239. data/lib/capybara/spec/views/spatial.erb +31 -0
  240. data/lib/capybara/spec/views/tables.erb +67 -0
  241. data/lib/capybara/spec/views/with_animation.erb +39 -4
  242. data/lib/capybara/spec/views/with_base_tag.erb +2 -2
  243. data/lib/capybara/spec/views/with_dragula.erb +24 -0
  244. data/lib/capybara/spec/views/with_fixed_header_footer.erb +2 -1
  245. data/lib/capybara/spec/views/with_hover.erb +3 -2
  246. data/lib/capybara/spec/views/with_hover1.erb +10 -0
  247. data/lib/capybara/spec/views/with_html.erb +37 -9
  248. data/lib/capybara/spec/views/with_html5_svg.erb +20 -0
  249. data/lib/capybara/spec/views/with_jquery_animation.erb +24 -0
  250. data/lib/capybara/spec/views/with_js.erb +26 -5
  251. data/lib/capybara/spec/views/with_jstree.erb +26 -0
  252. data/lib/capybara/spec/views/with_namespace.erb +1 -0
  253. data/lib/capybara/spec/views/with_scope.erb +2 -2
  254. data/lib/capybara/spec/views/with_scope_other.erb +6 -0
  255. data/lib/capybara/spec/views/with_shadow.erb +31 -0
  256. data/lib/capybara/spec/views/with_slow_unload.erb +2 -1
  257. data/lib/capybara/spec/views/with_sortable_js.erb +21 -0
  258. data/lib/capybara/spec/views/with_unload_alert.erb +1 -0
  259. data/lib/capybara/spec/views/with_windows.erb +1 -1
  260. data/lib/capybara/spec/views/within_frames.erb +1 -1
  261. data/lib/capybara/version.rb +1 -1
  262. data/lib/capybara/window.rb +19 -25
  263. data/lib/capybara.rb +126 -111
  264. data/spec/basic_node_spec.rb +59 -34
  265. data/spec/capybara_spec.rb +56 -44
  266. data/spec/counter_spec.rb +35 -0
  267. data/spec/css_builder_spec.rb +101 -0
  268. data/spec/css_splitter_spec.rb +8 -8
  269. data/spec/dsl_spec.rb +79 -52
  270. data/spec/filter_set_spec.rb +9 -9
  271. data/spec/fixtures/selenium_driver_rspec_failure.rb +4 -4
  272. data/spec/fixtures/selenium_driver_rspec_success.rb +4 -4
  273. data/spec/minitest_spec.rb +45 -7
  274. data/spec/minitest_spec_spec.rb +87 -64
  275. data/spec/per_session_config_spec.rb +6 -6
  276. data/spec/rack_test_spec.rb +172 -116
  277. data/spec/regexp_dissassembler_spec.rb +250 -0
  278. data/spec/result_spec.rb +80 -72
  279. data/spec/rspec/features_spec.rb +21 -16
  280. data/spec/rspec/scenarios_spec.rb +10 -6
  281. data/spec/rspec/shared_spec_matchers.rb +407 -365
  282. data/spec/rspec/views_spec.rb +3 -3
  283. data/spec/rspec_matchers_spec.rb +35 -10
  284. data/spec/rspec_spec.rb +63 -41
  285. data/spec/sauce_spec_chrome.rb +43 -0
  286. data/spec/selector_spec.rb +334 -89
  287. data/spec/selenium_spec_chrome.rb +176 -62
  288. data/spec/selenium_spec_chrome_remote.rb +54 -14
  289. data/spec/selenium_spec_edge.rb +41 -8
  290. data/spec/selenium_spec_firefox.rb +228 -0
  291. data/spec/selenium_spec_firefox_remote.rb +94 -0
  292. data/spec/selenium_spec_ie.rb +129 -11
  293. data/spec/selenium_spec_safari.rb +162 -0
  294. data/spec/server_spec.rb +171 -97
  295. data/spec/session_spec.rb +34 -18
  296. data/spec/shared_selenium_node.rb +79 -0
  297. data/spec/shared_selenium_session.rb +344 -80
  298. data/spec/spec_helper.rb +124 -2
  299. data/spec/whitespace_normalizer_spec.rb +54 -0
  300. data/spec/xpath_builder_spec.rb +93 -0
  301. metadata +326 -28
  302. data/lib/capybara/rspec/compound.rb +0 -94
  303. data/lib/capybara/selenium/driver_specializations/marionette_driver.rb +0 -31
  304. data/lib/capybara/selenium/nodes/marionette_node.rb +0 -31
  305. data/lib/capybara/spec/session/has_style_spec.rb +0 -25
  306. data/lib/capybara/spec/session/source_spec.rb +0 -0
  307. data/lib/capybara/spec/views/with_title.erb +0 -5
  308. data/spec/selenium_spec_marionette.rb +0 -167
@@ -3,19 +3,19 @@
3
3
  Capybara::SpecHelper.spec '#has_select?' do
4
4
  before { @session.visit('/form') }
5
5
 
6
- it "should be true if the field is on the page" do
6
+ it 'should be true if the field is on the page' do
7
7
  expect(@session).to have_select('Locale')
8
8
  expect(@session).to have_select('form_region')
9
9
  expect(@session).to have_select('Languages')
10
10
  expect(@session).to have_select(:Languages)
11
11
  end
12
12
 
13
- it "should be false if the field is not on the page" do
13
+ it 'should be false if the field is not on the page' do
14
14
  expect(@session).not_to have_select('Monkey')
15
15
  end
16
16
 
17
17
  context 'with selected value' do
18
- it "should be true if a field with the given value is on the page" do
18
+ it 'should be true if a field with the given value is on the page' do
19
19
  expect(@session).to have_select('form_locale', selected: 'English')
20
20
  expect(@session).to have_select('Region', selected: 'Norway')
21
21
  expect(@session).to have_select('Underwear', selected: [
@@ -23,7 +23,7 @@ Capybara::SpecHelper.spec '#has_select?' do
23
23
  ])
24
24
  end
25
25
 
26
- it "should be false if the given field is not on the page" do
26
+ it 'should be false if the given field is not on the page' do
27
27
  expect(@session).not_to have_select('Locale', selected: 'Swedish')
28
28
  expect(@session).not_to have_select('Does not exist', selected: 'John')
29
29
  expect(@session).not_to have_select('City', selected: 'Not there')
@@ -38,24 +38,24 @@ Capybara::SpecHelper.spec '#has_select?' do
38
38
  ])
39
39
  end
40
40
 
41
- it "should be true after the given value is selected" do
41
+ it 'should be true after the given value is selected' do
42
42
  @session.select('Swedish', from: 'Locale')
43
43
  expect(@session).to have_select('Locale', selected: 'Swedish')
44
44
  end
45
45
 
46
- it "should be false after a different value is selected" do
46
+ it 'should be false after a different value is selected' do
47
47
  @session.select('Swedish', from: 'Locale')
48
48
  expect(@session).not_to have_select('Locale', selected: 'English')
49
49
  end
50
50
 
51
- it "should be true after the given values are selected" do
51
+ it 'should be true after the given values are selected' do
52
52
  @session.select('Boxers', from: 'Underwear')
53
53
  expect(@session).to have_select('Underwear', selected: [
54
54
  'Boxerbriefs', 'Briefs', 'Boxers', 'Commando', "Frenchman's Pantalons", 'Long Johns'
55
55
  ])
56
56
  end
57
57
 
58
- it "should be false after one of the values is unselected" do
58
+ it 'should be false after one of the values is unselected' do
59
59
  @session.unselect('Briefs', from: 'Underwear')
60
60
  expect(@session).not_to have_select('Underwear', selected: [
61
61
  'Boxerbriefs', 'Briefs', 'Commando', "Frenchman's Pantalons", 'Long Johns'
@@ -63,48 +63,48 @@ Capybara::SpecHelper.spec '#has_select?' do
63
63
  end
64
64
 
65
65
  it "should be true even when the selected option invisible, regardless of the select's visibility" do
66
- expect(@session).to have_select('Icecream', visible: false, selected: 'Chocolate')
66
+ expect(@session).to have_select('Icecream', visible: :hidden, selected: 'Chocolate')
67
67
  expect(@session).to have_select('Sorbet', selected: 'Vanilla')
68
68
  end
69
69
  end
70
70
 
71
71
  context 'with partial select' do
72
- it "should be true if a field with the given partial values is on the page" do
72
+ it 'should be true if a field with the given partial values is on the page' do
73
73
  expect(@session).to have_select('Underwear', with_selected: %w[Boxerbriefs Briefs])
74
74
  end
75
75
 
76
- it "should be false if a field with the given partial values is not on the page" do
76
+ it 'should be false if a field with the given partial values is not on the page' do
77
77
  expect(@session).not_to have_select('Underwear', with_selected: %w[Boxerbriefs Boxers])
78
78
  end
79
79
 
80
- it "should be true after the given partial value is selected" do
80
+ it 'should be true after the given partial value is selected' do
81
81
  @session.select('Boxers', from: 'Underwear')
82
82
  expect(@session).to have_select('Underwear', with_selected: %w[Boxerbriefs Boxers])
83
83
  end
84
84
 
85
- it "should be false after one of the given partial values is unselected" do
85
+ it 'should be false after one of the given partial values is unselected' do
86
86
  @session.unselect('Briefs', from: 'Underwear')
87
87
  expect(@session).not_to have_select('Underwear', with_selected: %w[Boxerbriefs Briefs])
88
88
  end
89
89
 
90
90
  it "should be true even when the selected values are invisible, regardless of the select's visibility" do
91
- expect(@session).to have_select('Dessert', visible: false, with_options: %w[Pudding Tiramisu])
91
+ expect(@session).to have_select('Dessert', visible: :hidden, with_options: %w[Pudding Tiramisu])
92
92
  expect(@session).to have_select('Cake', with_selected: ['Chocolate Cake', 'Sponge Cake'])
93
93
  end
94
94
 
95
- it "should support non array partial values" do
95
+ it 'should support non array partial values' do
96
96
  expect(@session).to have_select('Underwear', with_selected: 'Briefs')
97
97
  expect(@session).not_to have_select('Underwear', with_selected: 'Boxers')
98
98
  end
99
99
  end
100
100
 
101
101
  context 'with exact options' do
102
- it "should be true if a field with the given options is on the page" do
102
+ it 'should be true if a field with the given options is on the page' do
103
103
  expect(@session).to have_select('Region', options: %w[Norway Sweden Finland])
104
104
  expect(@session).to have_select('Tendency', options: [])
105
105
  end
106
106
 
107
- it "should be false if the given field is not on the page" do
107
+ it 'should be false if the given field is not on the page' do
108
108
  expect(@session).not_to have_select('Locale', options: ['Swedish'])
109
109
  expect(@session).not_to have_select('Does not exist', options: ['John'])
110
110
  expect(@session).not_to have_select('City', options: ['London', 'Made up city'])
@@ -112,49 +112,83 @@ Capybara::SpecHelper.spec '#has_select?' do
112
112
  expect(@session).not_to have_select('Region', options: %w[Norway Norway Norway])
113
113
  end
114
114
 
115
- it "should be true even when the options are invisible, if the select itself is invisible" do
116
- expect(@session).to have_select("Icecream", visible: false, options: %w[Chocolate Vanilla Strawberry])
115
+ it 'should be true even when the options are invisible, if the select itself is invisible' do
116
+ expect(@session).to have_select('Icecream', visible: :hidden, options: %w[Chocolate Vanilla Strawberry])
117
+ end
118
+ end
119
+
120
+ context 'with enabled options' do
121
+ it 'should be true if the listed options exist and are enabled' do
122
+ expect(@session).to have_select('form_title', enabled_options: %w[Mr Mrs Miss])
123
+ end
124
+
125
+ it 'should be false if the listed options do not exist' do
126
+ expect(@session).not_to have_select('form_title', enabled_options: ['Not there'])
127
+ end
128
+
129
+ it 'should be false if the listed option exists but is not enabled' do
130
+ expect(@session).not_to have_select('form_title', enabled_options: %w[Mr Mrs Miss Other])
131
+ end
132
+ end
133
+
134
+ context 'with disabled options' do
135
+ it 'should be true if the listed options exist and are disabled' do
136
+ expect(@session).to have_select('form_title', disabled_options: ['Other'])
137
+ end
138
+
139
+ it 'should be false if the listed options do not exist' do
140
+ expect(@session).not_to have_select('form_title', disabled_options: ['Not there'])
141
+ end
142
+
143
+ it 'should be false if the listed option exists but is not disabled' do
144
+ expect(@session).not_to have_select('form_title', disabled_options: %w[Other Mrs])
117
145
  end
118
146
  end
119
147
 
120
148
  context 'with partial options' do
121
- it "should be true if a field with the given partial options is on the page" do
149
+ it 'should be true if a field with the given partial options is on the page' do
122
150
  expect(@session).to have_select('Region', with_options: %w[Norway Sweden])
123
151
  expect(@session).to have_select('City', with_options: ['London'])
124
152
  end
125
153
 
126
- it "should be false if a field with the given partial options is not on the page" do
154
+ it 'should be false if a field with the given partial options is not on the page' do
127
155
  expect(@session).not_to have_select('Locale', with_options: ['Uruguayan'])
128
156
  expect(@session).not_to have_select('Does not exist', with_options: ['John'])
129
157
  expect(@session).not_to have_select('Region', with_options: %w[Norway Sweden Finland Latvia])
130
158
  end
131
159
 
132
- it "should be true even when the options are invisible, if the select itself is invisible" do
133
- expect(@session).to have_select("Icecream", visible: false, with_options: %w[Vanilla Strawberry])
160
+ it 'should be true even when the options are invisible, if the select itself is invisible' do
161
+ expect(@session).to have_select('Icecream', visible: :hidden, with_options: %w[Vanilla Strawberry])
134
162
  end
135
163
  end
136
164
 
137
165
  context 'with multiple option' do
138
- it "should find multiple selects if true" do
166
+ it 'should find multiple selects if true' do
139
167
  expect(@session).to have_select('form_languages', multiple: true)
140
168
  expect(@session).not_to have_select('form_other_title', multiple: true)
141
169
  end
142
170
 
143
- it "should not find multiple selects if false" do
171
+ it 'should not find multiple selects if false' do
144
172
  expect(@session).not_to have_select('form_languages', multiple: false)
145
173
  expect(@session).to have_select('form_other_title', multiple: false)
146
174
  end
147
175
 
148
- it "should find both if not specified" do
176
+ it 'should find both if not specified' do
149
177
  expect(@session).to have_select('form_languages')
150
178
  expect(@session).to have_select('form_other_title')
151
179
  end
152
180
  end
153
181
 
154
- it "should support locator-less usage" do
155
- expect(@session.has_select?(with_options: %w[Norway Sweden])).to eq true
182
+ it 'should raise an error if an invalid option is passed' do
183
+ expect do
184
+ expect(@session).to have_select('form_languages', invalid: true)
185
+ end.to raise_error(ArgumentError, 'Invalid option(s) :invalid, should be one of :above, :below, :left_of, :right_of, :near, :count, :minimum, :maximum, :between, :text, :id, :class, :style, :visible, :obscured, :exact, :exact_text, :normalize_ws, :match, :wait, :filter_set, :focused, :disabled, :name, :placeholder, :options, :enabled_options, :disabled_options, :selected, :with_selected, :multiple, :with_options')
186
+ end
187
+
188
+ it 'should support locator-less usage' do
189
+ expect(@session.has_select?(with_options: %w[Norway Sweden])).to be true
156
190
  expect(@session).to have_select(with_options: ['London'])
157
- expect(@session.has_select?(with_selected: %w[Commando Boxerbriefs])).to eq true
191
+ expect(@session.has_select?(with_selected: %w[Commando Boxerbriefs])).to be true
158
192
  expect(@session).to have_select(with_selected: ['Briefs'])
159
193
  end
160
194
  end
@@ -162,18 +196,18 @@ end
162
196
  Capybara::SpecHelper.spec '#has_no_select?' do
163
197
  before { @session.visit('/form') }
164
198
 
165
- it "should be false if the field is on the page" do
199
+ it 'should be false if the field is on the page' do
166
200
  expect(@session).not_to have_no_select('Locale')
167
201
  expect(@session).not_to have_no_select('form_region')
168
202
  expect(@session).not_to have_no_select('Languages')
169
203
  end
170
204
 
171
- it "should be true if the field is not on the page" do
205
+ it 'should be true if the field is not on the page' do
172
206
  expect(@session).to have_no_select('Monkey')
173
207
  end
174
208
 
175
209
  context 'with selected value' do
176
- it "should be false if a field with the given value is on the page" do
210
+ it 'should be false if a field with the given value is on the page' do
177
211
  expect(@session).not_to have_no_select('form_locale', selected: 'English')
178
212
  expect(@session).not_to have_no_select('Region', selected: 'Norway')
179
213
  expect(@session).not_to have_no_select('Underwear', selected: [
@@ -181,7 +215,7 @@ Capybara::SpecHelper.spec '#has_no_select?' do
181
215
  ])
182
216
  end
183
217
 
184
- it "should be true if the given field is not on the page" do
218
+ it 'should be true if the given field is not on the page' do
185
219
  expect(@session).to have_no_select('Locale', selected: 'Swedish')
186
220
  expect(@session).to have_no_select('Does not exist', selected: 'John')
187
221
  expect(@session).to have_no_select('City', selected: 'Not there')
@@ -196,24 +230,24 @@ Capybara::SpecHelper.spec '#has_no_select?' do
196
230
  ])
197
231
  end
198
232
 
199
- it "should be false after the given value is selected" do
233
+ it 'should be false after the given value is selected' do
200
234
  @session.select('Swedish', from: 'Locale')
201
235
  expect(@session).not_to have_no_select('Locale', selected: 'Swedish')
202
236
  end
203
237
 
204
- it "should be true after a different value is selected" do
238
+ it 'should be true after a different value is selected' do
205
239
  @session.select('Swedish', from: 'Locale')
206
240
  expect(@session).to have_no_select('Locale', selected: 'English')
207
241
  end
208
242
 
209
- it "should be false after the given values are selected" do
243
+ it 'should be false after the given values are selected' do
210
244
  @session.select('Boxers', from: 'Underwear')
211
245
  expect(@session).not_to have_no_select('Underwear', selected: [
212
246
  'Boxerbriefs', 'Briefs', 'Boxers', 'Commando', "Frenchman's Pantalons", 'Long Johns'
213
247
  ])
214
248
  end
215
249
 
216
- it "should be true after one of the values is unselected" do
250
+ it 'should be true after one of the values is unselected' do
217
251
  @session.unselect('Briefs', from: 'Underwear')
218
252
  expect(@session).to have_no_select('Underwear', selected: [
219
253
  'Boxerbriefs', 'Briefs', 'Commando', "Frenchman's Pantalons", 'Long Johns'
@@ -222,36 +256,36 @@ Capybara::SpecHelper.spec '#has_no_select?' do
222
256
  end
223
257
 
224
258
  context 'with partial select' do
225
- it "should be false if a field with the given partial values is on the page" do
259
+ it 'should be false if a field with the given partial values is on the page' do
226
260
  expect(@session).not_to have_no_select('Underwear', with_selected: %w[Boxerbriefs Briefs])
227
261
  end
228
262
 
229
- it "should be true if a field with the given partial values is not on the page" do
263
+ it 'should be true if a field with the given partial values is not on the page' do
230
264
  expect(@session).to have_no_select('Underwear', with_selected: %w[Boxerbriefs Boxers])
231
265
  end
232
266
 
233
- it "should be false after the given partial value is selected" do
267
+ it 'should be false after the given partial value is selected' do
234
268
  @session.select('Boxers', from: 'Underwear')
235
269
  expect(@session).not_to have_no_select('Underwear', with_selected: %w[Boxerbriefs Boxers])
236
270
  end
237
271
 
238
- it "should be true after one of the given partial values is unselected" do
272
+ it 'should be true after one of the given partial values is unselected' do
239
273
  @session.unselect('Briefs', from: 'Underwear')
240
274
  expect(@session).to have_no_select('Underwear', with_selected: %w[Boxerbriefs Briefs])
241
275
  end
242
276
 
243
- it "should support non array partial values" do
277
+ it 'should support non array partial values' do
244
278
  expect(@session).not_to have_no_select('Underwear', with_selected: 'Briefs')
245
279
  expect(@session).to have_no_select('Underwear', with_selected: 'Boxers')
246
280
  end
247
281
  end
248
282
 
249
283
  context 'with exact options' do
250
- it "should be false if a field with the given options is on the page" do
284
+ it 'should be false if a field with the given options is on the page' do
251
285
  expect(@session).not_to have_no_select('Region', options: %w[Norway Sweden Finland])
252
286
  end
253
287
 
254
- it "should be true if the given field is not on the page" do
288
+ it 'should be true if the given field is not on the page' do
255
289
  expect(@session).to have_no_select('Locale', options: ['Swedish'])
256
290
  expect(@session).to have_no_select('Does not exist', options: ['John'])
257
291
  expect(@session).to have_no_select('City', options: ['London', 'Made up city'])
@@ -261,22 +295,22 @@ Capybara::SpecHelper.spec '#has_no_select?' do
261
295
  end
262
296
 
263
297
  context 'with partial options' do
264
- it "should be false if a field with the given partial options is on the page" do
298
+ it 'should be false if a field with the given partial options is on the page' do
265
299
  expect(@session).not_to have_no_select('Region', with_options: %w[Norway Sweden])
266
300
  expect(@session).not_to have_no_select('City', with_options: ['London'])
267
301
  end
268
302
 
269
- it "should be true if a field with the given partial options is not on the page" do
303
+ it 'should be true if a field with the given partial options is not on the page' do
270
304
  expect(@session).to have_no_select('Locale', with_options: ['Uruguayan'])
271
305
  expect(@session).to have_no_select('Does not exist', with_options: ['John'])
272
306
  expect(@session).to have_no_select('Region', with_options: %w[Norway Sweden Finland Latvia])
273
307
  end
274
308
  end
275
309
 
276
- it "should support locator-less usage" do
277
- expect(@session.has_no_select?(with_options: %w[Norway Sweden Finland Latvia])).to eq true
310
+ it 'should support locator-less usage' do
311
+ expect(@session.has_no_select?(with_options: %w[Norway Sweden Finland Latvia])).to be true
278
312
  expect(@session).to have_no_select(with_options: ['New London'])
279
- expect(@session.has_no_select?(with_selected: ['Boxers'])).to eq true
280
- expect(@session).to have_no_select(with_selected: %w[Commando Boxers])
313
+ expect(@session.has_no_select?(id: 'form_underwear', with_selected: ['Boxers'])).to be true
314
+ expect(@session).to have_no_select(id: 'form_underwear', with_selected: %w[Commando Boxers])
281
315
  end
282
316
  end
@@ -5,104 +5,138 @@ Capybara::SpecHelper.spec '#has_selector?' do
5
5
  @session.visit('/with_html')
6
6
  end
7
7
 
8
- it "should be true if the given selector is on the page" do
9
- expect(@session).to have_selector(:xpath, "//p")
10
- expect(@session).to have_selector(:css, "p a#foo")
8
+ it 'should be true if the given selector is on the page' do
9
+ expect(@session).to have_selector(:xpath, '//p')
10
+ expect(@session).to have_selector(:css, 'p a#foo')
11
11
  expect(@session).to have_selector("//p[contains(.,'est')]")
12
12
  end
13
13
 
14
- it "should be false if the given selector is not on the page" do
15
- expect(@session).not_to have_selector(:xpath, "//abbr")
16
- expect(@session).not_to have_selector(:css, "p a#doesnotexist")
14
+ it 'should be false if the given selector is not on the page' do
15
+ expect(@session).not_to have_selector(:xpath, '//abbr')
16
+ expect(@session).not_to have_selector(:css, 'p a#doesnotexist')
17
17
  expect(@session).not_to have_selector("//p[contains(.,'thisstringisnotonpage')]")
18
18
  end
19
19
 
20
- it "should use default selector" do
20
+ it 'should use default selector' do
21
21
  Capybara.default_selector = :css
22
- expect(@session).not_to have_selector("p a#doesnotexist")
23
- expect(@session).to have_selector("p a#foo")
22
+ expect(@session).not_to have_selector('p a#doesnotexist')
23
+ expect(@session).to have_selector('p a#foo')
24
24
  end
25
25
 
26
- it "should respect scopes" do
26
+ it 'should respect scopes' do
27
27
  @session.within "//p[@id='first']" do
28
28
  expect(@session).to have_selector(".//a[@id='foo']")
29
29
  expect(@session).not_to have_selector(".//a[@id='red']")
30
30
  end
31
31
  end
32
32
 
33
- it "should accept a filter block" do
34
- expect(@session).to have_selector(:css, "a", count: 1) { |el| el[:id] == "foo" }
33
+ it 'should accept a filter block' do
34
+ expect(@session).to have_selector(:css, 'a', count: 1) { |el| el[:id] == 'foo' }
35
35
  end
36
36
 
37
- context "with count" do
38
- it "should be true if the content is on the page the given number of times" do
39
- expect(@session).to have_selector("//p", count: 3)
37
+ context 'with count' do
38
+ it 'should be true if the content is on the page the given number of times' do
39
+ expect(@session).to have_selector('//p', count: 3)
40
40
  expect(@session).to have_selector("//p//a[@id='foo']", count: 1)
41
41
  expect(@session).to have_selector("//p[contains(.,'est')]", count: 1)
42
42
  end
43
43
 
44
- it "should be false if the content is on the page the given number of times" do
45
- expect(@session).not_to have_selector("//p", count: 6)
44
+ it 'should be false if the content is on the page the given number of times' do
45
+ expect(@session).not_to have_selector('//p', count: 6)
46
46
  expect(@session).not_to have_selector("//p//a[@id='foo']", count: 2)
47
47
  expect(@session).not_to have_selector("//p[contains(.,'est')]", count: 5)
48
48
  end
49
49
 
50
50
  it "should be false if the content isn't on the page at all" do
51
- expect(@session).not_to have_selector("//abbr", count: 2)
51
+ expect(@session).not_to have_selector('//abbr', count: 2)
52
52
  expect(@session).not_to have_selector("//p//a[@id='doesnotexist']", count: 1)
53
53
  end
54
54
  end
55
55
 
56
- context "with text" do
57
- it "should discard all matches where the given string is not contained" do
58
- expect(@session).to have_selector("//p//a", text: "Redirect", count: 1)
59
- expect(@session).not_to have_selector("//p", text: "Doesnotexist")
56
+ context 'with text' do
57
+ it 'should discard all matches where the given string is not contained' do
58
+ expect(@session).to have_selector('//p//a', text: 'Redirect', count: 1)
59
+ expect(@session).to have_selector(:css, 'p a', text: 'Redirect', count: 1)
60
+ expect(@session).not_to have_selector('//p', text: 'Doesnotexist')
60
61
  end
61
62
 
62
- it "should respect visibility setting" do
63
- expect(@session).to have_selector(:id, "hidden-text", text: "Some of this text is hidden!", visible: false)
64
- expect(@session).not_to have_selector(:id, "hidden-text", text: "Some of this text is hidden!", visible: true)
63
+ it 'should respect visibility setting' do
64
+ expect(@session).to have_selector(:id, 'hidden-text', text: 'Some of this text is hidden!', visible: :all)
65
+ expect(@session).not_to have_selector(:id, 'hidden-text', text: 'Some of this text is hidden!', visible: :visible)
65
66
  Capybara.ignore_hidden_elements = false
66
- expect(@session).to have_selector(:id, "hidden-text", text: "Some of this text is hidden!", visible: false)
67
+ expect(@session).to have_selector(:id, 'hidden-text', text: 'Some of this text is hidden!', visible: :all)
67
68
  Capybara.visible_text_only = true
68
- expect(@session).not_to have_selector(:id, "hidden-text", text: "Some of this text is hidden!", visible: true)
69
+ expect(@session).not_to have_selector(:id, 'hidden-text', text: 'Some of this text is hidden!', visible: :visible)
69
70
  end
70
71
 
71
- it "should discard all matches where the given regexp is not matched" do
72
- expect(@session).to have_selector("//p//a", text: /re[dab]i/i, count: 1)
73
- expect(@session).not_to have_selector("//p//a", text: /Red$/)
72
+ it 'should discard all matches where the given regexp is not matched' do
73
+ expect(@session).to have_selector('//p//a', text: /re[dab]i/i, count: 1)
74
+ expect(@session).not_to have_selector('//p//a', text: /Red$/)
74
75
  end
75
76
 
76
- it "should raise when extra parameters passed" do
77
+ it 'should raise when extra parameters passed' do
77
78
  expect do
78
- expect(@session).to have_selector(:css, "p a#foo", 'extra')
79
+ expect(@session).to have_selector(:css, 'p a#foo', 'extra')
79
80
  end.to raise_error ArgumentError, /extra/
80
81
  end
82
+
83
+ context 'with whitespace normalization' do
84
+ context 'Capybara.default_normalize_ws = false' do
85
+ it 'should support normalize_ws option' do
86
+ Capybara.default_normalize_ws = false
87
+ expect(@session).not_to have_selector(:id, 'second', text: 'text with whitespace')
88
+ expect(@session).to have_selector(:id, 'second', text: 'text with whitespace', normalize_ws: true)
89
+ end
90
+ end
91
+
92
+ context 'Capybara.default_normalize_ws = true' do
93
+ it 'should support normalize_ws option' do
94
+ Capybara.default_normalize_ws = true
95
+ expect(@session).to have_selector(:id, 'second', text: 'text with whitespace')
96
+ expect(@session).not_to have_selector(:id, 'second', text: 'text with whitespace', normalize_ws: false)
97
+ end
98
+ end
99
+ end
81
100
  end
82
101
 
83
- context "with exact_text" do
84
- context "string" do
85
- it "should only match elements that match exactly" do
86
- expect(@session).to have_selector(:id, "h2one", exact_text: "Header Class Test One")
87
- expect(@session).to have_no_selector(:id, "h2one", exact_text: "Header Class Test")
102
+ context 'with exact_text' do
103
+ context 'string' do
104
+ it 'should only match elements that match exactly' do
105
+ expect(@session).to have_selector(:id, 'h2one', exact_text: 'Header Class Test One')
106
+ expect(@session).to have_no_selector(:id, 'h2one', exact_text: 'Header Class Test')
88
107
  end
89
108
  end
90
109
 
91
- context "boolean" do
92
- it "should only match elements that match exactly when true" do
93
- expect(@session).to have_selector(:id, "h2one", text: "Header Class Test One", exact_text: true)
94
- expect(@session).to have_no_selector(:id, "h2one", text: "Header Class Test", exact_text: true)
110
+ context 'boolean' do
111
+ it 'should only match elements that match exactly when true' do
112
+ expect(@session).to have_selector(:id, 'h2one', text: 'Header Class Test One', exact_text: true)
113
+ expect(@session).to have_no_selector(:id, 'h2one', text: 'Header Class Test', exact_text: true)
114
+ end
115
+
116
+ it 'should match substrings when false' do
117
+ expect(@session).to have_selector(:id, 'h2one', text: 'Header Class Test One', exact_text: false)
118
+ expect(@session).to have_selector(:id, 'h2one', text: 'Header Class Test', exact_text: false)
95
119
  end
96
120
 
97
- it "should match substrings when false" do
98
- expect(@session).to have_selector(:id, "h2one", text: "Header Class Test One", exact_text: false)
99
- expect(@session).to have_selector(:id, "h2one", text: "Header Class Test", exact_text: false)
121
+ it 'should warn if text option is a regexp that it is ignoring exact_text' do
122
+ allow(Capybara::Helpers).to receive(:warn)
123
+ expect(@session).to have_selector(:id, 'h2one', text: /Class Test/, exact_text: true)
124
+ expect(Capybara::Helpers).to have_received(:warn).with(/'exact_text' option is not supported/)
125
+ end
126
+ end
127
+
128
+ context 'regexp' do
129
+ it 'should only match when it fully matches' do
130
+ expect(@session).to have_selector(:id, 'h2one', exact_text: /Header Class Test One/)
131
+ expect(@session).to have_no_selector(:id, 'h2one', exact_text: /Header Class Test/)
132
+ expect(@session).to have_no_selector(:id, 'h2one', exact_text: /Class Test One/)
133
+ expect(@session).to have_no_selector(:id, 'h2one', exact_text: /Class Test/)
100
134
  end
101
135
  end
102
136
  end
103
137
 
104
- context "datalist" do
105
- it "should match options" do
138
+ context 'datalist' do
139
+ it 'should match options' do
106
140
  @session.visit('/form')
107
141
  expect(@session).to have_selector(:datalist_input, with_options: %w[Jaguar Audi Mercedes])
108
142
  expect(@session).not_to have_selector(:datalist_input, with_options: %w[Ford Chevy])
@@ -115,63 +149,69 @@ Capybara::SpecHelper.spec '#has_no_selector?' do
115
149
  @session.visit('/with_html')
116
150
  end
117
151
 
118
- it "should be false if the given selector is on the page" do
119
- expect(@session).not_to have_no_selector(:xpath, "//p")
120
- expect(@session).not_to have_no_selector(:css, "p a#foo")
152
+ it 'should be false if the given selector is on the page' do
153
+ expect(@session).not_to have_no_selector(:xpath, '//p')
154
+ expect(@session).not_to have_no_selector(:css, 'p a#foo')
121
155
  expect(@session).not_to have_no_selector("//p[contains(.,'est')]")
122
156
  end
123
157
 
124
- it "should be true if the given selector is not on the page" do
125
- expect(@session).to have_no_selector(:xpath, "//abbr")
126
- expect(@session).to have_no_selector(:css, "p a#doesnotexist")
158
+ it 'should be true if the given selector is not on the page' do
159
+ expect(@session).to have_no_selector(:xpath, '//abbr')
160
+ expect(@session).to have_no_selector(:css, 'p a#doesnotexist')
127
161
  expect(@session).to have_no_selector("//p[contains(.,'thisstringisnotonpage')]")
128
162
  end
129
163
 
130
- it "should use default selector" do
164
+ it 'should use default selector' do
131
165
  Capybara.default_selector = :css
132
- expect(@session).to have_no_selector("p a#doesnotexist")
133
- expect(@session).not_to have_no_selector("p a#foo")
166
+ expect(@session).to have_no_selector('p a#doesnotexist')
167
+ expect(@session).not_to have_no_selector('p a#foo')
134
168
  end
135
169
 
136
- it "should respect scopes" do
170
+ it 'should respect scopes' do
137
171
  @session.within "//p[@id='first']" do
138
172
  expect(@session).not_to have_no_selector(".//a[@id='foo']")
139
173
  expect(@session).to have_no_selector(".//a[@id='red']")
140
174
  end
141
175
  end
142
176
 
143
- it "should accept a filter block" do
144
- expect(@session).to have_no_selector(:css, "a#foo") { |el| el[:id] != "foo" }
177
+ it 'should accept a filter block' do
178
+ expect(@session).to have_no_selector(:css, 'a#foo') { |el| el[:id] != 'foo' }
145
179
  end
146
180
 
147
- context "with count" do
148
- it "should be false if the content is on the page the given number of times" do
149
- expect(@session).not_to have_no_selector("//p", count: 3)
181
+ context 'with count' do
182
+ it 'should be false if the content is on the page the given number of times' do
183
+ expect(@session).not_to have_no_selector('//p', count: 3)
150
184
  expect(@session).not_to have_no_selector("//p//a[@id='foo']", count: 1)
151
185
  expect(@session).not_to have_no_selector("//p[contains(.,'est')]", count: 1)
152
186
  end
153
187
 
154
- it "should be true if the content is on the page the wrong number of times" do
155
- expect(@session).to have_no_selector("//p", count: 6)
188
+ it 'should be true if the content is on the page the wrong number of times' do
189
+ expect(@session).to have_no_selector('//p', count: 6)
156
190
  expect(@session).to have_no_selector("//p//a[@id='foo']", count: 2)
157
191
  expect(@session).to have_no_selector("//p[contains(.,'est')]", count: 5)
158
192
  end
159
193
 
160
194
  it "should be true if the content isn't on the page at all" do
161
- expect(@session).to have_no_selector("//abbr", count: 2)
195
+ expect(@session).to have_no_selector('//abbr', count: 2)
162
196
  expect(@session).to have_no_selector("//p//a[@id='doesnotexist']", count: 1)
163
197
  end
164
198
  end
165
199
 
166
- context "with text" do
167
- it "should discard all matches where the given string is contained" do
168
- expect(@session).not_to have_no_selector("//p//a", text: "Redirect", count: 1)
169
- expect(@session).to have_no_selector("//p", text: "Doesnotexist")
200
+ context 'with text' do
201
+ it 'should discard all matches where the given string is contained' do
202
+ expect(@session).not_to have_no_selector('//p//a', text: 'Redirect', count: 1)
203
+ expect(@session).to have_no_selector('//p', text: 'Doesnotexist')
170
204
  end
171
205
 
172
- it "should discard all matches where the given regexp is matched" do
173
- expect(@session).not_to have_no_selector("//p//a", text: /re[dab]i/i, count: 1)
174
- expect(@session).to have_no_selector("//p//a", text: /Red$/)
206
+ it 'should discard all matches where the given regexp is matched' do
207
+ expect(@session).not_to have_no_selector('//p//a', text: /re[dab]i/i, count: 1)
208
+ expect(@session).to have_no_selector('//p//a', text: /Red$/)
209
+ end
210
+
211
+ it 'should error when matching element exists' do
212
+ expect do
213
+ expect(@session).to have_no_selector('//h2', text: 'Header Class Test Five')
214
+ end.to raise_error RSpec::Expectations::ExpectationNotMetError
175
215
  end
176
216
  end
177
217
  end