capybara 2.7.0 → 3.35.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (318) hide show
  1. checksums.yaml +5 -5
  2. data/.yardopts +1 -0
  3. data/History.md +1147 -11
  4. data/License.txt +1 -1
  5. data/README.md +252 -131
  6. data/lib/capybara/config.rb +92 -0
  7. data/lib/capybara/cucumber.rb +3 -3
  8. data/lib/capybara/driver/base.rb +52 -21
  9. data/lib/capybara/driver/node.rb +48 -14
  10. data/lib/capybara/dsl.rb +16 -9
  11. data/lib/capybara/helpers.rb +72 -81
  12. data/lib/capybara/minitest/spec.rb +267 -0
  13. data/lib/capybara/minitest.rb +385 -0
  14. data/lib/capybara/node/actions.rb +337 -89
  15. data/lib/capybara/node/base.rb +50 -32
  16. data/lib/capybara/node/document.rb +19 -3
  17. data/lib/capybara/node/document_matchers.rb +22 -24
  18. data/lib/capybara/node/element.rb +388 -125
  19. data/lib/capybara/node/finders.rb +231 -121
  20. data/lib/capybara/node/matchers.rb +503 -217
  21. data/lib/capybara/node/simple.rb +64 -27
  22. data/lib/capybara/queries/ancestor_query.rb +27 -0
  23. data/lib/capybara/queries/base_query.rb +87 -11
  24. data/lib/capybara/queries/current_path_query.rb +24 -24
  25. data/lib/capybara/queries/match_query.rb +15 -10
  26. data/lib/capybara/queries/selector_query.rb +675 -81
  27. data/lib/capybara/queries/sibling_query.rb +26 -0
  28. data/lib/capybara/queries/style_query.rb +45 -0
  29. data/lib/capybara/queries/text_query.rb +88 -20
  30. data/lib/capybara/queries/title_query.rb +9 -11
  31. data/lib/capybara/rack_test/browser.rb +63 -39
  32. data/lib/capybara/rack_test/css_handlers.rb +6 -4
  33. data/lib/capybara/rack_test/driver.rb +26 -16
  34. data/lib/capybara/rack_test/errors.rb +6 -0
  35. data/lib/capybara/rack_test/form.rb +73 -58
  36. data/lib/capybara/rack_test/node.rb +187 -67
  37. data/lib/capybara/rails.rb +4 -8
  38. data/lib/capybara/registration_container.rb +44 -0
  39. data/lib/capybara/registrations/drivers.rb +42 -0
  40. data/lib/capybara/registrations/patches/puma_ssl.rb +29 -0
  41. data/lib/capybara/registrations/servers.rb +45 -0
  42. data/lib/capybara/result.rb +142 -14
  43. data/lib/capybara/rspec/features.rb +17 -42
  44. data/lib/capybara/rspec/matcher_proxies.rb +82 -0
  45. data/lib/capybara/rspec/matchers/base.rb +111 -0
  46. data/lib/capybara/rspec/matchers/become_closed.rb +33 -0
  47. data/lib/capybara/rspec/matchers/compound.rb +88 -0
  48. data/lib/capybara/rspec/matchers/count_sugar.rb +37 -0
  49. data/lib/capybara/rspec/matchers/have_ancestor.rb +28 -0
  50. data/lib/capybara/rspec/matchers/have_current_path.rb +29 -0
  51. data/lib/capybara/rspec/matchers/have_selector.rb +77 -0
  52. data/lib/capybara/rspec/matchers/have_sibling.rb +27 -0
  53. data/lib/capybara/rspec/matchers/have_text.rb +33 -0
  54. data/lib/capybara/rspec/matchers/have_title.rb +29 -0
  55. data/lib/capybara/rspec/matchers/match_selector.rb +27 -0
  56. data/lib/capybara/rspec/matchers/match_style.rb +43 -0
  57. data/lib/capybara/rspec/matchers/spatial_sugar.rb +39 -0
  58. data/lib/capybara/rspec/matchers.rb +143 -244
  59. data/lib/capybara/rspec.rb +10 -12
  60. data/lib/capybara/selector/builders/css_builder.rb +84 -0
  61. data/lib/capybara/selector/builders/xpath_builder.rb +71 -0
  62. data/lib/capybara/selector/css.rb +102 -0
  63. data/lib/capybara/selector/definition/button.rb +63 -0
  64. data/lib/capybara/selector/definition/checkbox.rb +26 -0
  65. data/lib/capybara/selector/definition/css.rb +10 -0
  66. data/lib/capybara/selector/definition/datalist_input.rb +35 -0
  67. data/lib/capybara/selector/definition/datalist_option.rb +25 -0
  68. data/lib/capybara/selector/definition/element.rb +28 -0
  69. data/lib/capybara/selector/definition/field.rb +40 -0
  70. data/lib/capybara/selector/definition/fieldset.rb +14 -0
  71. data/lib/capybara/selector/definition/file_field.rb +13 -0
  72. data/lib/capybara/selector/definition/fillable_field.rb +33 -0
  73. data/lib/capybara/selector/definition/frame.rb +17 -0
  74. data/lib/capybara/selector/definition/id.rb +6 -0
  75. data/lib/capybara/selector/definition/label.rb +62 -0
  76. data/lib/capybara/selector/definition/link.rb +54 -0
  77. data/lib/capybara/selector/definition/link_or_button.rb +16 -0
  78. data/lib/capybara/selector/definition/option.rb +27 -0
  79. data/lib/capybara/selector/definition/radio_button.rb +27 -0
  80. data/lib/capybara/selector/definition/select.rb +81 -0
  81. data/lib/capybara/selector/definition/table.rb +109 -0
  82. data/lib/capybara/selector/definition/table_row.rb +21 -0
  83. data/lib/capybara/selector/definition/xpath.rb +5 -0
  84. data/lib/capybara/selector/definition.rb +278 -0
  85. data/lib/capybara/selector/filter.rb +3 -46
  86. data/lib/capybara/selector/filter_set.rb +124 -0
  87. data/lib/capybara/selector/filters/base.rb +77 -0
  88. data/lib/capybara/selector/filters/expression_filter.rb +22 -0
  89. data/lib/capybara/selector/filters/locator_filter.rb +29 -0
  90. data/lib/capybara/selector/filters/node_filter.rb +31 -0
  91. data/lib/capybara/selector/regexp_disassembler.rb +214 -0
  92. data/lib/capybara/selector/selector.rb +155 -0
  93. data/lib/capybara/selector/xpath_extensions.rb +17 -0
  94. data/lib/capybara/selector.rb +232 -369
  95. data/lib/capybara/selenium/atoms/getAttribute.min.js +1 -0
  96. data/lib/capybara/selenium/atoms/isDisplayed.min.js +1 -0
  97. data/lib/capybara/selenium/atoms/src/getAttribute.js +161 -0
  98. data/lib/capybara/selenium/atoms/src/isDisplayed.js +454 -0
  99. data/lib/capybara/selenium/driver.rb +380 -142
  100. data/lib/capybara/selenium/driver_specializations/chrome_driver.rb +117 -0
  101. data/lib/capybara/selenium/driver_specializations/edge_driver.rb +124 -0
  102. data/lib/capybara/selenium/driver_specializations/firefox_driver.rb +89 -0
  103. data/lib/capybara/selenium/driver_specializations/internet_explorer_driver.rb +26 -0
  104. data/lib/capybara/selenium/driver_specializations/safari_driver.rb +24 -0
  105. data/lib/capybara/selenium/extensions/file_input_click_emulation.rb +34 -0
  106. data/lib/capybara/selenium/extensions/find.rb +110 -0
  107. data/lib/capybara/selenium/extensions/html5_drag.rb +228 -0
  108. data/lib/capybara/selenium/extensions/modifier_keys_stack.rb +28 -0
  109. data/lib/capybara/selenium/extensions/scroll.rb +76 -0
  110. data/lib/capybara/selenium/logger_suppressor.rb +40 -0
  111. data/lib/capybara/selenium/node.rb +528 -97
  112. data/lib/capybara/selenium/nodes/chrome_node.rb +137 -0
  113. data/lib/capybara/selenium/nodes/edge_node.rb +104 -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/action_pauser.rb +26 -0
  118. data/lib/capybara/selenium/patches/atoms.rb +18 -0
  119. data/lib/capybara/selenium/patches/is_displayed.rb +16 -0
  120. data/lib/capybara/selenium/patches/logs.rb +45 -0
  121. data/lib/capybara/selenium/patches/pause_duration_fix.rb +9 -0
  122. data/lib/capybara/selenium/patches/persistent_client.rb +20 -0
  123. data/lib/capybara/server/animation_disabler.rb +63 -0
  124. data/lib/capybara/server/checker.rb +44 -0
  125. data/lib/capybara/server/middleware.rb +71 -0
  126. data/lib/capybara/server.rb +74 -71
  127. data/lib/capybara/session/config.rb +126 -0
  128. data/lib/capybara/session/matchers.rb +44 -27
  129. data/lib/capybara/session.rb +500 -297
  130. data/lib/capybara/spec/fixtures/no_extension +1 -0
  131. data/lib/capybara/spec/public/jquery.js +5 -5
  132. data/lib/capybara/spec/public/offset.js +6 -0
  133. data/lib/capybara/spec/public/test.js +168 -14
  134. data/lib/capybara/spec/session/accept_alert_spec.rb +37 -14
  135. data/lib/capybara/spec/session/accept_confirm_spec.rb +7 -6
  136. data/lib/capybara/spec/session/accept_prompt_spec.rb +38 -10
  137. data/lib/capybara/spec/session/all_spec.rb +179 -59
  138. data/lib/capybara/spec/session/ancestor_spec.rb +88 -0
  139. data/lib/capybara/spec/session/assert_all_of_selectors_spec.rb +140 -0
  140. data/lib/capybara/spec/session/assert_current_path_spec.rb +75 -0
  141. data/lib/capybara/spec/session/assert_selector_spec.rb +143 -0
  142. data/lib/capybara/spec/session/assert_style_spec.rb +26 -0
  143. data/lib/capybara/spec/session/assert_text_spec.rb +258 -0
  144. data/lib/capybara/spec/session/assert_title_spec.rb +93 -0
  145. data/lib/capybara/spec/session/attach_file_spec.rb +154 -48
  146. data/lib/capybara/spec/session/body_spec.rb +12 -13
  147. data/lib/capybara/spec/session/check_spec.rb +168 -41
  148. data/lib/capybara/spec/session/choose_spec.rb +75 -23
  149. data/lib/capybara/spec/session/click_button_spec.rb +243 -175
  150. data/lib/capybara/spec/session/click_link_or_button_spec.rb +57 -32
  151. data/lib/capybara/spec/session/click_link_spec.rb +100 -53
  152. data/lib/capybara/spec/session/current_scope_spec.rb +11 -10
  153. data/lib/capybara/spec/session/current_url_spec.rb +61 -35
  154. data/lib/capybara/spec/session/dismiss_confirm_spec.rb +7 -7
  155. data/lib/capybara/spec/session/dismiss_prompt_spec.rb +5 -4
  156. data/lib/capybara/spec/session/element/{assert_match_selector.rb → assert_match_selector_spec.rb} +13 -6
  157. data/lib/capybara/spec/session/element/match_css_spec.rb +21 -7
  158. data/lib/capybara/spec/session/element/match_xpath_spec.rb +9 -7
  159. data/lib/capybara/spec/session/element/matches_selector_spec.rb +91 -34
  160. data/lib/capybara/spec/session/evaluate_async_script_spec.rb +23 -0
  161. data/lib/capybara/spec/session/evaluate_script_spec.rb +45 -3
  162. data/lib/capybara/spec/session/execute_script_spec.rb +24 -4
  163. data/lib/capybara/spec/session/fill_in_spec.rb +166 -64
  164. data/lib/capybara/spec/session/find_button_spec.rb +37 -18
  165. data/lib/capybara/spec/session/find_by_id_spec.rb +10 -9
  166. data/lib/capybara/spec/session/find_field_spec.rb +57 -34
  167. data/lib/capybara/spec/session/find_link_spec.rb +47 -10
  168. data/lib/capybara/spec/session/find_spec.rb +290 -144
  169. data/lib/capybara/spec/session/first_spec.rb +91 -48
  170. data/lib/capybara/spec/session/frame/frame_title_spec.rb +23 -0
  171. data/lib/capybara/spec/session/frame/frame_url_spec.rb +23 -0
  172. data/lib/capybara/spec/session/frame/switch_to_frame_spec.rb +116 -0
  173. data/lib/capybara/spec/session/frame/within_frame_spec.rb +112 -0
  174. data/lib/capybara/spec/session/go_back_spec.rb +3 -2
  175. data/lib/capybara/spec/session/go_forward_spec.rb +3 -2
  176. data/lib/capybara/spec/session/has_all_selectors_spec.rb +69 -0
  177. data/lib/capybara/spec/session/has_ancestor_spec.rb +46 -0
  178. data/lib/capybara/spec/session/has_any_selectors_spec.rb +25 -0
  179. data/lib/capybara/spec/session/has_button_spec.rb +76 -19
  180. data/lib/capybara/spec/session/has_css_spec.rb +277 -131
  181. data/lib/capybara/spec/session/has_current_path_spec.rb +98 -26
  182. data/lib/capybara/spec/session/has_field_spec.rb +177 -107
  183. data/lib/capybara/spec/session/has_link_spec.rb +13 -12
  184. data/lib/capybara/spec/session/has_none_selectors_spec.rb +78 -0
  185. data/lib/capybara/spec/session/has_select_spec.rb +191 -95
  186. data/lib/capybara/spec/session/has_selector_spec.rb +128 -64
  187. data/lib/capybara/spec/session/has_sibling_spec.rb +50 -0
  188. data/lib/capybara/spec/session/has_table_spec.rb +172 -5
  189. data/lib/capybara/spec/session/has_text_spec.rb +126 -60
  190. data/lib/capybara/spec/session/has_title_spec.rb +35 -12
  191. data/lib/capybara/spec/session/has_xpath_spec.rb +74 -53
  192. data/lib/capybara/spec/session/{headers.rb → headers_spec.rb} +3 -2
  193. data/lib/capybara/spec/session/html_spec.rb +14 -6
  194. data/lib/capybara/spec/session/matches_style_spec.rb +35 -0
  195. data/lib/capybara/spec/session/node_spec.rb +1028 -131
  196. data/lib/capybara/spec/session/node_wrapper_spec.rb +39 -0
  197. data/lib/capybara/spec/session/refresh_spec.rb +34 -0
  198. data/lib/capybara/spec/session/reset_session_spec.rb +75 -34
  199. data/lib/capybara/spec/session/{response_code.rb → response_code_spec.rb} +2 -1
  200. data/lib/capybara/spec/session/save_and_open_page_spec.rb +3 -2
  201. data/lib/capybara/spec/session/save_and_open_screenshot_spec.rb +11 -15
  202. data/lib/capybara/spec/session/save_page_spec.rb +42 -55
  203. data/lib/capybara/spec/session/save_screenshot_spec.rb +16 -14
  204. data/lib/capybara/spec/session/screenshot_spec.rb +2 -2
  205. data/lib/capybara/spec/session/scroll_spec.rb +117 -0
  206. data/lib/capybara/spec/session/select_spec.rb +112 -85
  207. data/lib/capybara/spec/session/selectors_spec.rb +71 -8
  208. data/lib/capybara/spec/session/sibling_spec.rb +52 -0
  209. data/lib/capybara/spec/session/text_spec.rb +38 -23
  210. data/lib/capybara/spec/session/title_spec.rb +17 -5
  211. data/lib/capybara/spec/session/uncheck_spec.rb +71 -12
  212. data/lib/capybara/spec/session/unselect_spec.rb +44 -43
  213. data/lib/capybara/spec/session/visit_spec.rb +99 -32
  214. data/lib/capybara/spec/session/window/become_closed_spec.rb +33 -29
  215. data/lib/capybara/spec/session/window/current_window_spec.rb +5 -3
  216. data/lib/capybara/spec/session/window/open_new_window_spec.rb +5 -3
  217. data/lib/capybara/spec/session/window/switch_to_window_spec.rb +39 -30
  218. data/lib/capybara/spec/session/window/window_opened_by_spec.rb +17 -10
  219. data/lib/capybara/spec/session/window/window_spec.rb +121 -73
  220. data/lib/capybara/spec/session/window/windows_spec.rb +12 -10
  221. data/lib/capybara/spec/session/window/within_window_spec.rb +52 -82
  222. data/lib/capybara/spec/session/within_spec.rb +76 -43
  223. data/lib/capybara/spec/spec_helper.rb +67 -33
  224. data/lib/capybara/spec/test_app.rb +85 -36
  225. data/lib/capybara/spec/views/animated.erb +49 -0
  226. data/lib/capybara/spec/views/buttons.erb +1 -1
  227. data/lib/capybara/spec/views/fieldsets.erb +1 -1
  228. data/lib/capybara/spec/views/form.erb +227 -20
  229. data/lib/capybara/spec/views/frame_child.erb +10 -2
  230. data/lib/capybara/spec/views/frame_one.erb +2 -1
  231. data/lib/capybara/spec/views/frame_parent.erb +2 -2
  232. data/lib/capybara/spec/views/frame_two.erb +1 -1
  233. data/lib/capybara/spec/views/header_links.erb +1 -1
  234. data/lib/capybara/spec/views/host_links.erb +1 -1
  235. data/lib/capybara/spec/views/initial_alert.erb +10 -0
  236. data/lib/capybara/spec/views/obscured.erb +47 -0
  237. data/lib/capybara/spec/views/offset.erb +32 -0
  238. data/lib/capybara/spec/views/path.erb +1 -1
  239. data/lib/capybara/spec/views/popup_one.erb +1 -1
  240. data/lib/capybara/spec/views/popup_two.erb +1 -1
  241. data/lib/capybara/spec/views/postback.erb +1 -1
  242. data/lib/capybara/spec/views/react.erb +45 -0
  243. data/lib/capybara/spec/views/scroll.erb +20 -0
  244. data/lib/capybara/spec/views/spatial.erb +31 -0
  245. data/lib/capybara/spec/views/tables.erb +69 -2
  246. data/lib/capybara/spec/views/with_animation.erb +82 -0
  247. data/lib/capybara/spec/views/with_base_tag.erb +1 -1
  248. data/lib/capybara/spec/views/with_count.erb +1 -1
  249. data/lib/capybara/spec/views/with_dragula.erb +24 -0
  250. data/lib/capybara/spec/views/with_fixed_header_footer.erb +17 -0
  251. data/lib/capybara/spec/views/with_hover.erb +7 -1
  252. data/lib/capybara/spec/views/with_hover1.erb +10 -0
  253. data/lib/capybara/spec/views/with_html.erb +100 -10
  254. data/lib/capybara/spec/views/with_html5_svg.erb +20 -0
  255. data/lib/capybara/spec/views/with_html_entities.erb +1 -1
  256. data/lib/capybara/spec/views/with_jquery_animation.erb +24 -0
  257. data/lib/capybara/spec/views/with_js.erb +49 -3
  258. data/lib/capybara/spec/views/with_jstree.erb +26 -0
  259. data/lib/capybara/spec/views/with_namespace.erb +20 -0
  260. data/lib/capybara/spec/views/with_scope.erb +1 -1
  261. data/lib/capybara/spec/views/with_scope_other.erb +6 -0
  262. data/lib/capybara/spec/views/with_simple_html.erb +1 -1
  263. data/lib/capybara/spec/views/with_sortable_js.erb +21 -0
  264. data/lib/capybara/spec/views/with_title.erb +1 -1
  265. data/lib/capybara/spec/views/with_unload_alert.erb +3 -1
  266. data/lib/capybara/spec/views/with_windows.erb +7 -1
  267. data/lib/capybara/spec/views/within_frames.erb +6 -3
  268. data/lib/capybara/version.rb +2 -1
  269. data/lib/capybara/window.rb +39 -21
  270. data/lib/capybara.rb +208 -186
  271. data/spec/basic_node_spec.rb +52 -39
  272. data/spec/capybara_spec.rb +72 -50
  273. data/spec/css_builder_spec.rb +101 -0
  274. data/spec/css_splitter_spec.rb +38 -0
  275. data/spec/dsl_spec.rb +81 -61
  276. data/spec/filter_set_spec.rb +46 -0
  277. data/spec/fixtures/capybara.csv +1 -0
  278. data/spec/fixtures/certificate.pem +25 -0
  279. data/spec/fixtures/key.pem +27 -0
  280. data/spec/fixtures/selenium_driver_rspec_failure.rb +7 -3
  281. data/spec/fixtures/selenium_driver_rspec_success.rb +7 -3
  282. data/spec/minitest_spec.rb +164 -0
  283. data/spec/minitest_spec_spec.rb +162 -0
  284. data/spec/per_session_config_spec.rb +68 -0
  285. data/spec/rack_test_spec.rb +189 -96
  286. data/spec/regexp_dissassembler_spec.rb +250 -0
  287. data/spec/result_spec.rb +143 -13
  288. data/spec/rspec/features_spec.rb +38 -32
  289. data/spec/rspec/scenarios_spec.rb +9 -7
  290. data/spec/rspec/shared_spec_matchers.rb +959 -0
  291. data/spec/rspec/views_spec.rb +9 -3
  292. data/spec/rspec_matchers_spec.rb +62 -0
  293. data/spec/rspec_spec.rb +127 -30
  294. data/spec/sauce_spec_chrome.rb +43 -0
  295. data/spec/selector_spec.rb +458 -37
  296. data/spec/selenium_spec_chrome.rb +196 -9
  297. data/spec/selenium_spec_chrome_remote.rb +100 -0
  298. data/spec/selenium_spec_edge.rb +47 -0
  299. data/spec/selenium_spec_firefox.rb +210 -0
  300. data/spec/selenium_spec_firefox_remote.rb +80 -0
  301. data/spec/selenium_spec_ie.rb +150 -0
  302. data/spec/selenium_spec_safari.rb +148 -0
  303. data/spec/server_spec.rb +200 -101
  304. data/spec/session_spec.rb +91 -0
  305. data/spec/shared_selenium_node.rb +83 -0
  306. data/spec/shared_selenium_session.rb +558 -0
  307. data/spec/spec_helper.rb +94 -2
  308. data/spec/xpath_builder_spec.rb +93 -0
  309. metadata +420 -60
  310. data/lib/capybara/query.rb +0 -7
  311. data/lib/capybara/spec/session/assert_current_path.rb +0 -60
  312. data/lib/capybara/spec/session/assert_selector.rb +0 -148
  313. data/lib/capybara/spec/session/assert_text.rb +0 -196
  314. data/lib/capybara/spec/session/assert_title.rb +0 -70
  315. data/lib/capybara/spec/session/source_spec.rb +0 -0
  316. data/lib/capybara/spec/session/within_frame_spec.rb +0 -53
  317. data/spec/rspec/matchers_spec.rb +0 -827
  318. data/spec/selenium_spec.rb +0 -151
@@ -0,0 +1,267 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'minitest/spec'
4
+
5
+ module Capybara
6
+ module Minitest
7
+ module Expectations
8
+ ##
9
+ # Expectation that there is an ancestor
10
+ #
11
+ # @!method must_have_ancestor
12
+ # See {Capybara::Node::Matchers#has_ancestor?}
13
+
14
+ ##
15
+ # Expectation that there is button
16
+ #
17
+ # @!method must_have_button
18
+ # See {Capybara::Node::Matchers#has_button?}
19
+
20
+ ##
21
+ # Expectation that there is no button
22
+ #
23
+ # @!method wont_have_button
24
+ # See {Capybara::Node::Matchers#has_no_button?}
25
+
26
+ ##
27
+ # Expectation that there is checked_field
28
+ #
29
+ # @!method must_have_checked_field
30
+ # See {Capybara::Node::Matchers#has_checked_field?}
31
+
32
+ ##
33
+ # Expectation that there is no checked_field
34
+ #
35
+ # @!method wont_have_checked_field
36
+ # See {Capybara::Node::Matchers#has_no_checked_field?}
37
+
38
+ ##
39
+ # Expectation that there is unchecked_field
40
+ #
41
+ # @!method must_have_unchecked_field
42
+ # See {Capybara::Node::Matchers#has_unchecked_field?}
43
+
44
+ ##
45
+ # Expectation that there is no unchecked_field
46
+ #
47
+ # @!method wont_have_unchecked_field
48
+ # See {Capybara::Node::Matchers#has_no_unchecked_field?}
49
+
50
+ ##
51
+ # Expectation that page content does match
52
+ #
53
+ # @!method must_have_content
54
+ # See {Capybara::Node::Matchers#has_content?}
55
+
56
+ ##
57
+ # Expectation that page content does not match
58
+ #
59
+ # @!method wont_have_content
60
+ # See {Capybara::Node::Matchers#has_no_content?}
61
+
62
+ ##
63
+ # Expectation that there is css
64
+ #
65
+ # @!method must_have_css
66
+ # See {Capybara::Node::Matchers#has_css?}
67
+
68
+ ##
69
+ # Expectation that there is no css
70
+ #
71
+ # @!method wont_have_css
72
+ # See {Capybara::Node::Matchers#has_no_css?}
73
+
74
+ ##
75
+ # Expectation that current path matches
76
+ #
77
+ # @!method must_have_current_path
78
+ # See {Capybara::SessionMatchers#has_current_path?}
79
+
80
+ ##
81
+ # Expectation that current page does not match
82
+ #
83
+ # @!method wont_have_current_path
84
+ # See {Capybara::SessionMatchers#has_no_current_path?}
85
+
86
+ ##
87
+ # Expectation that there is field
88
+ #
89
+ # @!method must_have_field
90
+ # See {Capybara::Node::Matchers#has_field?}
91
+
92
+ ##
93
+ # Expectation that there is no field
94
+ #
95
+ # @!method wont_have_field
96
+ # See {Capybara::Node::Matchers#has_no_field?}
97
+
98
+ ##
99
+ # Expectation that there is link
100
+ #
101
+ # @!method must_have_link
102
+ # See {Capybara::Node::Matchers#has_link?}
103
+
104
+ ##
105
+ # Expectation that there is no link
106
+ #
107
+ # @!method wont_have_link
108
+ # See {Capybara::Node::Matchers#has_no_link?}
109
+
110
+ ##
111
+ # Expectation that page text does match
112
+ #
113
+ # @!method must_have_text
114
+ # See {Capybara::Node::Matchers#has_text?}
115
+
116
+ ##
117
+ # Expectation that page text does not match
118
+ #
119
+ # @!method wont_have_text
120
+ # See {Capybara::Node::Matchers#has_no_text?}
121
+
122
+ ##
123
+ # Expectation that page title does match
124
+ #
125
+ # @!method must_have_title
126
+ # See {Capybara::Node::DocumentMatchers#has_title?}
127
+
128
+ ##
129
+ # Expectation that page title does not match
130
+ #
131
+ # @!method wont_have_title
132
+ # See {Capybara::Node::DocumentMatchers#has_no_title?}
133
+
134
+ ##
135
+ # Expectation that there is select
136
+ #
137
+ # @!method must_have_select
138
+ # See {Capybara::Node::Matchers#has_select?}
139
+
140
+ ##
141
+ # Expectation that there is no select
142
+ #
143
+ # @!method wont_have_select
144
+ # See {Capybara::Node::Matchers#has_no_select?}
145
+
146
+ ##
147
+ # Expectation that there is a selector
148
+ #
149
+ # @!method must_have_selector
150
+ # See {Capybara::Node::Matchers#has_selector?}
151
+
152
+ ##
153
+ # Expectation that there is no selector
154
+ #
155
+ # @!method wont_have_selector
156
+ # See {Capybara::Node::Matchers#has_no_selector?}
157
+
158
+ ##
159
+ # Expectation that all of the provided selectors are present
160
+ #
161
+ # @!method must_have_all_of_selectors
162
+ # See {Capybara::Node::Matchers#assert_all_of_selectors}
163
+
164
+ ##
165
+ # Expectation that none of the provided selectors are present
166
+ #
167
+ # @!method must_have_none_of_selectors
168
+ # See {Capybara::Node::Matchers#assert_none_of_selectors}
169
+
170
+ ##
171
+ # Expectation that any of the provided selectors are present
172
+ #
173
+ # @!method must_have_any_of_selectors
174
+ # See {Capybara::Node::Matchers#assert_any_of_selectors}
175
+
176
+ ##
177
+ # Expectation that there is a sibling
178
+ #
179
+ # @!method must_have_sibling
180
+ # See {Capybara::Node::Matchers#has_sibling?}
181
+
182
+ ##
183
+ # Expectation that element has style
184
+ #
185
+ # @!method must_match_style
186
+ # See {Capybara::Node::Matchers#matches_style?}
187
+
188
+ ##
189
+ # Expectation that there is table
190
+ #
191
+ # @!method must_have_table
192
+ # See {Capybara::Node::Matchers#has_table?}
193
+
194
+ ##
195
+ # Expectation that there is no table
196
+ #
197
+ # @!method wont_have_table
198
+ # See {Capybara::Node::Matchers#has_no_table?}
199
+
200
+ ##
201
+ # Expectation that there is xpath
202
+ #
203
+ # @!method must_have_xpath
204
+ # See {Capybara::Node::Matchers#has_xpath?}
205
+
206
+ ##
207
+ # Expectation that there is no xpath
208
+ #
209
+ # @!method wont_have_xpath
210
+ # See {Capybara::Node::Matchers#has_no_xpath?}
211
+
212
+ # This currently doesn't work for Ruby 2.8 due to Minitest not forwarding keyword args separately
213
+ # %w[text content title current_path].each do |assertion|
214
+ # infect_an_assertion "assert_#{assertion}", "must_have_#{assertion}", :reverse
215
+ # infect_an_assertion "refute_#{assertion}", "wont_have_#{assertion}", :reverse
216
+ # end
217
+
218
+ # rubocop:disable Style/MultilineBlockChain
219
+ (%w[text content title current_path
220
+ selector xpath css link button field select table checked_field unchecked_field
221
+ ancestor sibling].flat_map do |assertion|
222
+ [%W[assert_#{assertion} must_have_#{assertion}],
223
+ %W[refute_#{assertion} wont_have_#{assertion}]]
224
+ end + [%w[assert_all_of_selectors must_have_all_of_selectors],
225
+ %w[assert_none_of_selectors must_have_none_of_selectors],
226
+ %w[assert_any_of_selectors must_have_any_of_selectors],
227
+ %w[assert_matches_style must_match_style]] +
228
+ %w[selector xpath css].flat_map do |assertion|
229
+ [%W[assert_matches_#{assertion} must_match_#{assertion}],
230
+ %W[refute_matches_#{assertion} wont_match_#{assertion}]]
231
+ end).each do |(meth, new_name)|
232
+ class_eval <<-ASSERTION, __FILE__, __LINE__ + 1
233
+ def #{new_name} *args, **kw_args, &block
234
+ ::Minitest::Expectation.new(self, ::Minitest::Spec.current).#{new_name}(*args, **kw_args, &block)
235
+ end
236
+ ASSERTION
237
+
238
+ ::Minitest::Expectation.class_eval <<-ASSERTION, __FILE__, __LINE__ + 1
239
+ def #{new_name} *args, **kw_args, &block
240
+ raise "Calling ##{new_name} outside of test." unless ctx
241
+ ctx.#{meth}(target, *args, **kw_args, &block)
242
+ end
243
+ ASSERTION
244
+ end
245
+ # rubocop:enable Style/MultilineBlockChain
246
+
247
+ ##
248
+ # @deprecated
249
+ def must_have_style(*args, **kw_args, &block)
250
+ warn 'must_have_style is deprecated, please use must_match_style'
251
+ must_match_style(*args, **kw_args, &block)
252
+ end
253
+ end
254
+ end
255
+ end
256
+
257
+ class Capybara::Session
258
+ include Capybara::Minitest::Expectations unless ENV['MT_NO_EXPECTATIONS']
259
+ end
260
+
261
+ class Capybara::Node::Base
262
+ include Capybara::Minitest::Expectations unless ENV['MT_NO_EXPECTATIONS']
263
+ end
264
+
265
+ class Capybara::Node::Simple
266
+ include Capybara::Minitest::Expectations unless ENV['MT_NO_EXPECTATIONS']
267
+ end
@@ -0,0 +1,385 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'minitest'
4
+ require 'capybara/dsl'
5
+
6
+ module Capybara
7
+ module Minitest
8
+ module Assertions
9
+ ##
10
+ # Assert text exists
11
+ #
12
+ # @!method assert_content
13
+ # @!method assert_text
14
+ # See {Capybara::Node::Matchers#assert_text}
15
+
16
+ ##
17
+ # Assert text does not exist
18
+ #
19
+ # @!method refute_content
20
+ # @!method assert_no_content
21
+ # @!method refute_text
22
+ # @!method assert_no_text
23
+ # See {Capybara::Node::Matchers#assert_no_text}
24
+
25
+ ##
26
+ # Assertion that page title does match
27
+ #
28
+ # @!method assert_title
29
+ # See {Capybara::Node::DocumentMatchers#assert_title}
30
+
31
+ ##
32
+ # Assertion that page title does not match
33
+ #
34
+ # @!method refute_title
35
+ # @!method assert_no_title
36
+ # See {Capybara::Node::DocumentMatchers#assert_no_title}
37
+
38
+ ##
39
+ # Assertion that current path matches
40
+ #
41
+ # @!method assert_current_path
42
+ # See {Capybara::SessionMatchers#assert_current_path}
43
+
44
+ ##
45
+ # Assertion that current page does not match
46
+ #
47
+ # @!method refute_current_path
48
+ # @!method assert_no_current_path
49
+ # See {Capybara::SessionMatchers#assert_no_current_path}
50
+
51
+ %w[text no_text title no_title current_path no_current_path].each do |assertion_name|
52
+ class_eval <<-ASSERTION, __FILE__, __LINE__ + 1
53
+ def assert_#{assertion_name}(*args, **kwargs, &optional_filter_block)
54
+ self.assertions +=1
55
+ subject, args = determine_subject(args)
56
+ subject.assert_#{assertion_name}(*args, **kwargs, &optional_filter_block)
57
+ rescue Capybara::ExpectationNotMet => e
58
+ raise ::Minitest::Assertion, e.message
59
+ end
60
+ ASSERTION
61
+ end
62
+
63
+ alias_method :refute_title, :assert_no_title
64
+ alias_method :refute_text, :assert_no_text
65
+ alias_method :refute_content, :refute_text
66
+ alias_method :refute_current_path, :assert_no_current_path
67
+ alias_method :assert_content, :assert_text
68
+ alias_method :assert_no_content, :refute_text
69
+
70
+ ##
71
+ # Assert selector exists on page
72
+ #
73
+ # @!method assert_selector
74
+ # See {Capybara::Node::Matchers#assert_selector}
75
+
76
+ ##
77
+ # Assert selector does not exist on page
78
+ #
79
+ # @!method refute_selector
80
+ # @!method assert_no_selector
81
+ # See {Capybara::Node::Matchers#assert_no_selector}
82
+
83
+ ##
84
+ # Assert element matches selector
85
+ #
86
+ # @!method assert_matches_selector
87
+ # See {Capybara::Node::Matchers#assert_matches_selector}
88
+
89
+ ##
90
+ # Assert element does not match selector
91
+ #
92
+ # @!method refute_matches_selector
93
+ # @!method assert_not_matches_selector
94
+ # See {Capybara::Node::Matchers#assert_not_matches_selector}
95
+
96
+ ##
97
+ # Assert all of the provided selectors exist on page
98
+ #
99
+ # @!method assert_all_of_selectors
100
+ # See {Capybara::Node::Matchers#assert_all_of_selectors}
101
+
102
+ ##
103
+ # Assert none of the provided selectors exist on page
104
+ #
105
+ # @!method assert_none_of_selectors
106
+ # See {Capybara::Node::Matchers#assert_none_of_selectors}
107
+
108
+ ##
109
+ # Assert any of the provided selectors exist on page
110
+ #
111
+ # @!method assert_any_of_selectors
112
+ # See {Capybara::Node::Matchers#assert_any_of_selectors}
113
+
114
+ ##
115
+ # Assert element has the provided CSS styles
116
+ #
117
+ # @!method assert_matches_style
118
+ # See {Capybara::Node::Matchers#assert_matches_style}
119
+
120
+ ##
121
+ # Assert element has a matching sibling
122
+ #
123
+ # @!method assert_sibling
124
+ # See {Capybara::Node::Matchers#assert_sibling}
125
+
126
+ ##
127
+ # Assert element does not have a matching sibling
128
+ #
129
+ # @!method refute_sibling
130
+ # @!method assert_no_sibling
131
+ # See {Capybara::Node::Matchers#assert_no_sibling}
132
+
133
+ ##
134
+ # Assert element has a matching ancestor
135
+ #
136
+ # @!method assert_ancestor
137
+ # See {Capybara::Node::Matchers#assert_ancestor}
138
+
139
+ ##
140
+ # Assert element does not have a matching ancestor
141
+ #
142
+ # @!method refute_ancestor
143
+ # @!method assert_no_ancestor
144
+ # See {Capybara::Node::Matchers#assert_no_ancestor}
145
+
146
+ %w[selector no_selector matches_style
147
+ all_of_selectors none_of_selectors any_of_selectors
148
+ matches_selector not_matches_selector
149
+ sibling no_sibling ancestor no_ancestor].each do |assertion_name|
150
+ class_eval <<-ASSERTION, __FILE__, __LINE__ + 1
151
+ def assert_#{assertion_name} *args, &optional_filter_block
152
+ self.assertions +=1
153
+ subject, args = determine_subject(args)
154
+ subject.assert_#{assertion_name}(*args, &optional_filter_block)
155
+ rescue Capybara::ExpectationNotMet => e
156
+ raise ::Minitest::Assertion, e.message
157
+ end
158
+ ASSERTION
159
+ ruby2_keywords "assert_#{assertion_name}" if respond_to?(:ruby2_keywords)
160
+ end
161
+
162
+ alias_method :refute_selector, :assert_no_selector
163
+ alias_method :refute_matches_selector, :assert_not_matches_selector
164
+ alias_method :refute_ancestor, :assert_no_ancestor
165
+ alias_method :refute_sibling, :assert_no_sibling
166
+
167
+ ##
168
+ # Assert that provided xpath exists
169
+ #
170
+ # @!method assert_xpath
171
+ # See {Capybara::Node::Matchers#has_xpath?}
172
+
173
+ ##
174
+ # Assert that provide xpath does not exist
175
+ #
176
+ # @!method refute_xpath
177
+ # @!method assert_no_xpath
178
+ # See {Capybara::Node::Matchers#has_no_xpath?}
179
+
180
+ ##
181
+ # Assert that provided css exists
182
+ #
183
+ # @!method assert_css
184
+ # See {Capybara::Node::Matchers#has_css?}
185
+
186
+ ##
187
+ # Assert that provided css does not exist
188
+ #
189
+ # @!method refute_css
190
+ # @!method assert_no_css
191
+ # See {Capybara::Node::Matchers#has_no_css?}
192
+
193
+ ##
194
+ # Assert that provided link exists
195
+ #
196
+ # @!method assert_link
197
+ # See {Capybara::Node::Matchers#has_link?}
198
+
199
+ ##
200
+ # Assert that provided link does not exist
201
+ #
202
+ # @!method assert_no_link
203
+ # @!method refute_link
204
+ # See {Capybara::Node::Matchers#has_no_link?}
205
+
206
+ ##
207
+ # Assert that provided button exists
208
+ #
209
+ # @!method assert_button
210
+ # See {Capybara::Node::Matchers#has_button?}
211
+
212
+ ##
213
+ # Assert that provided button does not exist
214
+ #
215
+ # @!method refute_button
216
+ # @!method assert_no_button
217
+ # See {Capybara::Node::Matchers#has_no_button?}
218
+
219
+ ##
220
+ # Assert that provided field exists
221
+ #
222
+ # @!method assert_field
223
+ # See {Capybara::Node::Matchers#has_field?}
224
+
225
+ ##
226
+ # Assert that provided field does not exist
227
+ #
228
+ # @!method refute_field
229
+ # @!method assert_no_field
230
+ # See {Capybara::Node::Matchers#has_no_field?}
231
+
232
+ ##
233
+ # Assert that provided checked field exists
234
+ #
235
+ # @!method assert_checked_field
236
+ # See {Capybara::Node::Matchers#has_checked_field?}
237
+
238
+ ##
239
+ # Assert that provided checked_field does not exist
240
+ #
241
+ # @!method assert_no_checked_field
242
+ # @!method refute_checked_field
243
+ # See {Capybara::Node::Matchers#has_no_checked_field?}
244
+
245
+ ##
246
+ # Assert that provided unchecked field exists
247
+ #
248
+ # @!method assert_unchecked_field
249
+ # See {Capybara::Node::Matchers#has_unchecked_field?}
250
+
251
+ ##
252
+ # Assert that provided unchecked field does not exist
253
+ #
254
+ # @!method assert_no_unchecked_field
255
+ # @!method refute_unchecked_field
256
+ # See {Capybara::Node::Matchers#has_no_unchecked_field?}
257
+
258
+ ##
259
+ # Assert that provided select exists
260
+ #
261
+ # @!method assert_select
262
+ # See {Capybara::Node::Matchers#has_select?}
263
+
264
+ ##
265
+ # Assert that provided select does not exist
266
+ #
267
+ # @!method refute_select
268
+ # @!method assert_no_select
269
+ # See {Capybara::Node::Matchers#has_no_select?}
270
+
271
+ ##
272
+ # Assert that provided table exists
273
+ #
274
+ # @!method assert_table
275
+ # See {Capybara::Node::Matchers#has_table?}
276
+
277
+ ##
278
+ # Assert that provided table does not exist
279
+ #
280
+ # @!method refute_table
281
+ # @!method assert_no_table
282
+ # See {Capybara::Node::Matchers#has_no_table?}
283
+
284
+ %w[xpath css link button field select table].each do |selector_type|
285
+ define_method "assert_#{selector_type}" do |*args, &optional_filter_block|
286
+ subject, args = determine_subject(args)
287
+ locator, options = extract_locator(args)
288
+ assert_selector(subject, selector_type.to_sym, locator, **options, &optional_filter_block)
289
+ end
290
+ ruby2_keywords "assert_#{selector_type}" if respond_to?(:ruby2_keywords)
291
+
292
+ define_method "assert_no_#{selector_type}" do |*args, &optional_filter_block|
293
+ subject, args = determine_subject(args)
294
+ locator, options = extract_locator(args)
295
+ assert_no_selector(subject, selector_type.to_sym, locator, **options, &optional_filter_block)
296
+ end
297
+ ruby2_keywords "assert_no_#{selector_type}" if respond_to?(:ruby2_keywords)
298
+ alias_method "refute_#{selector_type}", "assert_no_#{selector_type}"
299
+ end
300
+
301
+ %w[checked unchecked].each do |field_type|
302
+ define_method "assert_#{field_type}_field" do |*args, &optional_filter_block|
303
+ subject, args = determine_subject(args)
304
+ locator, options = extract_locator(args)
305
+ assert_selector(subject, :field, locator, **options.merge(field_type.to_sym => true), &optional_filter_block)
306
+ end
307
+ ruby2_keywords "assert_#{field_type}_field" if respond_to?(:ruby2_keywords)
308
+
309
+ define_method "assert_no_#{field_type}_field" do |*args, &optional_filter_block|
310
+ subject, args = determine_subject(args)
311
+ locator, options = extract_locator(args)
312
+ assert_no_selector(
313
+ subject,
314
+ :field,
315
+ locator,
316
+ **options.merge(field_type.to_sym => true),
317
+ &optional_filter_block
318
+ )
319
+ end
320
+ ruby2_keywords "assert_no_#{field_type}_field" if respond_to?(:ruby2_keywords)
321
+ alias_method "refute_#{field_type}_field", "assert_no_#{field_type}_field"
322
+ end
323
+
324
+ ##
325
+ # Assert that element matches xpath
326
+ #
327
+ # @!method assert_matches_xpath
328
+ # See {Capybara::Node::Matchers#matches_xpath?}
329
+
330
+ ##
331
+ # Assert that element does not match xpath
332
+ #
333
+ # @!method refute_matches_xpath
334
+ # @!method assert_not_matches_xpath
335
+ # See {Capybara::Node::Matchers#not_matches_xpath?}
336
+
337
+ ##
338
+ # Assert that element matches css
339
+ #
340
+ # @!method assert_matches_css
341
+ # See {Capybara::Node::Matchers#matches_css?}
342
+
343
+ ##
344
+ # Assert that element matches css
345
+ #
346
+ # @!method refute_matches_css
347
+ # @!method assert_not_matches_css
348
+ # See {Capybara::Node::Matchers#not_matches_css?}
349
+
350
+ %w[xpath css].each do |selector_type|
351
+ define_method "assert_matches_#{selector_type}" do |*args, &optional_filter_block|
352
+ subject, args = determine_subject(args)
353
+ assert_matches_selector(subject, selector_type.to_sym, *args, &optional_filter_block)
354
+ end
355
+ ruby2_keywords "assert_matches_#{selector_type}" if respond_to?(:ruby2_keywords)
356
+
357
+ define_method "assert_not_matches_#{selector_type}" do |*args, &optional_filter_block|
358
+ subject, args = determine_subject(args)
359
+ assert_not_matches_selector(subject, selector_type.to_sym, *args, &optional_filter_block)
360
+ end
361
+ ruby2_keywords "assert_not_matches_#{selector_type}" if respond_to?(:ruby2_keywords)
362
+ alias_method "refute_matches_#{selector_type}", "assert_not_matches_#{selector_type}"
363
+ end
364
+
365
+ private
366
+
367
+ def determine_subject(args)
368
+ case args.first
369
+ when Capybara::Session, Capybara::Node::Base, Capybara::Node::Simple
370
+ [args.shift, args]
371
+ when ->(arg) { arg.respond_to?(:to_capybara_node) }
372
+ [args.shift.to_capybara_node, args]
373
+ else
374
+ [page, args]
375
+ end
376
+ end
377
+
378
+ def extract_locator(args)
379
+ locator, options = *args, {}
380
+ locator, options = nil, locator if locator.is_a? Hash
381
+ [locator, options]
382
+ end
383
+ end
384
+ end
385
+ end