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
@@ -1,69 +1,121 @@
1
1
  # frozen_string_literal: true
2
- Capybara::SpecHelper.spec "#choose" do
2
+
3
+ Capybara::SpecHelper.spec '#choose' do
3
4
  before do
4
5
  @session.visit('/form')
5
6
  end
6
7
 
7
- it "should choose a radio button by id" do
8
- @session.choose("gender_male")
8
+ it 'should choose a radio button by id' do
9
+ @session.choose('gender_male')
9
10
  @session.click_button('awesome')
10
11
  expect(extract_results(@session)['gender']).to eq('male')
11
12
  end
12
13
 
13
- it "should choose a radio button by label" do
14
- @session.choose("Both")
14
+ it 'should choose a radio button by label' do
15
+ @session.choose('Both')
15
16
  @session.click_button('awesome')
16
17
  expect(extract_results(@session)['gender']).to eq('both')
17
18
  end
18
19
 
19
- it "casts to string" do
20
- @session.choose("Both")
21
- @session.click_button(:'awesome')
20
+ it 'should work without a locator string' do
21
+ @session.choose(id: 'gender_male')
22
+ @session.click_button('awesome')
23
+ expect(extract_results(@session)['gender']).to eq('male')
24
+ end
25
+
26
+ it 'should be able to choose self when no locator string specified' do
27
+ rb = @session.find(:id, 'gender_male')
28
+ rb.choose
29
+ @session.click_button('awesome')
30
+ expect(extract_results(@session)['gender']).to eq('male')
31
+ end
32
+
33
+ it 'casts to string' do
34
+ @session.choose('Both')
35
+ @session.click_button(:awesome)
22
36
  expect(extract_results(@session)['gender']).to eq('both')
23
37
  end
24
38
 
25
39
  context "with a locator that doesn't exist" do
26
- it "should raise an error" do
27
- msg = "Unable to find radio button \"does not exist\""
40
+ it 'should raise an error' do
41
+ msg = /Unable to find radio button "does not exist"/
28
42
  expect do
29
43
  @session.choose('does not exist')
30
44
  end.to raise_error(Capybara::ElementNotFound, msg)
31
45
  end
32
46
  end
33
47
 
34
- context "with a disabled radio button" do
35
- it "should raise an error" do
48
+ context 'with a disabled radio button' do
49
+ it 'should raise an error' do
36
50
  expect do
37
51
  @session.choose('Disabled Radio')
38
52
  end.to raise_error(Capybara::ElementNotFound)
39
53
  end
40
54
  end
41
55
 
42
- context "with :exact option" do
43
- it "should accept partial matches when false" do
44
- @session.choose("Mal", :exact => false)
56
+ context 'with :exact option' do
57
+ it 'should accept partial matches when false' do
58
+ @session.choose('Mal', exact: false)
45
59
  @session.click_button('awesome')
46
60
  expect(extract_results(@session)['gender']).to eq('male')
47
61
  end
48
62
 
49
- it "should not accept partial matches when true" do
63
+ it 'should not accept partial matches when true' do
50
64
  expect do
51
- @session.choose("Mal", :exact => true)
65
+ @session.choose('Mal', exact: true)
52
66
  end.to raise_error(Capybara::ElementNotFound)
53
67
  end
54
68
  end
55
69
 
56
- context "with `option` option" do
57
- it "can check radio buttons by their value" do
58
- @session.choose('form[gender]', :option => "male")
70
+ context 'with `option` option' do
71
+ it 'can check radio buttons by their value' do
72
+ @session.choose('form[gender]', option: 'male')
73
+ @session.click_button('awesome')
74
+ expect(extract_results(@session)['gender']).to eq('male')
75
+ end
76
+
77
+ it 'should alias `:with` option' do
78
+ @session.choose('form[gender]', with: 'male')
59
79
  @session.click_button('awesome')
60
- expect(extract_results(@session)['gender']).to eq("male")
80
+ expect(extract_results(@session)['gender']).to eq('male')
61
81
  end
62
82
 
63
- it "should raise an error if option not found" do
83
+ it 'should raise an error if option not found' do
64
84
  expect do
65
- @session.choose('form[gender]', :option => "hermaphrodite")
85
+ @session.choose('form[gender]', option: 'hermaphrodite')
66
86
  end.to raise_error(Capybara::ElementNotFound)
67
87
  end
68
88
  end
89
+
90
+ context 'with hidden radio buttons' do
91
+ context 'with Capybara.automatic_label_click == true' do
92
+ around do |spec|
93
+ old_click_label, Capybara.automatic_label_click = Capybara.automatic_label_click, true
94
+ spec.run
95
+ Capybara.automatic_label_click = old_click_label
96
+ end
97
+
98
+ it 'should select by clicking the label if available' do
99
+ @session.choose('party_democrat')
100
+ @session.click_button('awesome')
101
+ expect(extract_results(@session)['party']).to eq('democrat')
102
+ end
103
+
104
+ it 'should select self by clicking the label if no locator specified' do
105
+ cb = @session.find(:id, 'party_democrat', visible: :hidden)
106
+ cb.choose
107
+ @session.click_button('awesome')
108
+ expect(extract_results(@session)['party']).to eq('democrat')
109
+ end
110
+
111
+ it 'should raise error if not allowed to click label' do
112
+ expect { @session.choose('party_democrat', allow_label_click: false) }.to raise_error(Capybara::ElementNotFound, /Unable to find visible radio button "party_democrat"/)
113
+ end
114
+ end
115
+ end
116
+
117
+ it 'should return the chosen radio button' do
118
+ el = @session.find(:radio_button, 'gender_male')
119
+ expect(@session.choose('gender_male')).to eq el
120
+ end
69
121
  end
@@ -1,448 +1,516 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  Capybara::SpecHelper.spec '#click_button' do
3
4
  before do
4
5
  @session.visit('/form')
5
6
  end
6
7
 
7
- it "should wait for asynchronous load", :requires => [:js] do
8
+ it 'should wait for asynchronous load', requires: [:js] do
8
9
  @session.visit('/with_js')
9
- @session.click_link('Click me')
10
- @session.click_button('New Here')
10
+ @session.using_wait_time(1.5) do
11
+ @session.click_link('Click me')
12
+ @session.click_button('New Here')
13
+ end
11
14
  end
12
15
 
13
- it "casts to string" do
16
+ it 'casts to string' do
14
17
  @session.click_button(:'Relative Action')
15
18
  expect(extract_results(@session)['relative']).to eq('Relative Action')
16
19
  expect(@session.current_path).to eq('/relative')
17
20
  end
18
21
 
19
- context "with multiple values with the same name" do
20
- it "should use the latest given value" do
22
+ context 'with multiple values with the same name' do
23
+ it 'should use the latest given value' do
21
24
  @session.check('Terms of Use')
22
25
  @session.click_button('awesome')
23
26
  expect(extract_results(@session)['terms_of_use']).to eq('1')
24
27
  end
25
28
  end
26
29
 
27
- context "with a form that has a relative url as an action" do
28
- it "should post to the correct url" do
30
+ context 'with a form that has a relative url as an action' do
31
+ it 'should post to the correct url' do
29
32
  @session.click_button('Relative Action')
30
33
  expect(extract_results(@session)['relative']).to eq('Relative Action')
31
34
  expect(@session.current_path).to eq('/relative')
32
35
  end
33
36
  end
34
37
 
35
- context "with a form that has no action specified" do
36
- it "should post to the correct url" do
38
+ context 'with a form that has no action specified' do
39
+ it 'should post to the correct url' do
37
40
  @session.click_button('No Action')
38
41
  expect(extract_results(@session)['no_action']).to eq('No Action')
39
42
  expect(@session.current_path).to eq('/form')
40
43
  end
41
44
  end
42
45
 
43
- context "with value given on a submit button" do
44
- context "on a form with HTML5 fields" do
46
+ context 'with value given on a submit button' do
47
+ context 'on a form with HTML5 fields' do
48
+ let(:results) { extract_results(@session) }
49
+
45
50
  before do
46
51
  @session.click_button('html5_submit')
47
- @results = extract_results(@session)
48
52
  end
49
53
 
50
- it "should serialise and submit search fields" do
51
- expect(@results['html5_search']).to eq('what are you looking for')
54
+ it 'should serialise and submit search fields' do
55
+ expect(results['html5_search']).to eq('what are you looking for')
52
56
  end
53
57
 
54
- it "should serialise and submit email fields" do
55
- expect(@results['html5_email']).to eq('person@email.com')
58
+ it 'should serialise and submit email fields' do
59
+ expect(results['html5_email']).to eq('person@email.com')
56
60
  end
57
61
 
58
- it "should serialise and submit url fields" do
59
- expect(@results['html5_url']).to eq('http://www.example.com')
62
+ it 'should serialise and submit url fields' do
63
+ expect(results['html5_url']).to eq('http://www.example.com')
60
64
  end
61
65
 
62
- it "should serialise and submit tel fields" do
63
- expect(@results['html5_tel']).to eq('911')
66
+ it 'should serialise and submit tel fields' do
67
+ expect(results['html5_tel']).to eq('911')
64
68
  end
65
69
 
66
- it "should serialise and submit color fields" do
67
- expect(@results['html5_color'].upcase).to eq('#FFFFFF')
70
+ it 'should serialise and submit color fields' do
71
+ expect(results['html5_color'].upcase).to eq('#FFFFFF')
68
72
  end
69
73
  end
70
74
 
71
- context "on an HTML4 form" do
75
+ context 'on an HTML4 form' do
76
+ let(:results) { extract_results(@session) }
77
+
72
78
  before do
73
79
  @session.click_button('awesome')
74
- @results = extract_results(@session)
75
80
  end
76
81
 
77
- it "should serialize and submit text fields" do
78
- expect(@results['first_name']).to eq('John')
82
+ it 'should serialize and submit text fields' do
83
+ expect(results['first_name']).to eq('John')
79
84
  end
80
85
 
81
- it "should escape fields when submitting" do
82
- expect(@results['phone']).to eq('+1 555 7021')
86
+ it 'should escape fields when submitting' do
87
+ expect(results['phone']).to eq('+1 555 7021')
83
88
  end
84
89
 
85
- it "should serialize and submit password fields" do
86
- expect(@results['password']).to eq('seeekrit')
90
+ it 'should serialize and submit password fields' do
91
+ expect(results['password']).to eq('seeekrit')
87
92
  end
88
93
 
89
- it "should serialize and submit hidden fields" do
90
- expect(@results['token']).to eq('12345')
94
+ it 'should serialize and submit hidden fields' do
95
+ expect(results['token']).to eq('12345')
91
96
  end
92
97
 
93
- it "should not serialize fields from other forms" do
94
- expect(@results['middle_name']).to be_nil
98
+ it 'should not serialize fields from other forms' do
99
+ expect(results['middle_name']).to be_nil
95
100
  end
96
101
 
97
- it "should submit the button that was clicked, but not other buttons" do
98
- expect(@results['awesome']).to eq('awesome')
99
- expect(@results['crappy']).to be_nil
102
+ it 'should submit the button that was clicked, but not other buttons' do
103
+ expect(results['awesome']).to eq('awesome')
104
+ expect(results['crappy']).to be_nil
100
105
  end
101
106
 
102
- it "should serialize radio buttons" do
103
- expect(@results['gender']).to eq('female')
107
+ it 'should serialize radio buttons' do
108
+ expect(results['gender']).to eq('female')
104
109
  end
105
110
 
106
111
  it "should default radio value to 'on' if none specified" do
107
- expect(@results['valueless_radio']).to eq('on')
112
+ expect(results['valueless_radio']).to eq('on')
108
113
  end
109
114
 
110
- it "should serialize check boxes" do
111
- expect(@results['pets']).to include('dog', 'hamster')
112
- expect(@results['pets']).not_to include('cat')
115
+ it 'should serialize check boxes' do
116
+ expect(results['pets']).to include('dog', 'hamster')
117
+ expect(results['pets']).not_to include('cat')
113
118
  end
114
119
 
115
120
  it "should default checkbox value to 'on' if none specififed" do
116
- expect(@results['valueless_checkbox']).to eq('on')
121
+ expect(results['valueless_checkbox']).to eq('on')
117
122
  end
118
123
 
119
- it "should serialize text areas" do
120
- expect(@results['description']).to eq('Descriptive text goes here')
124
+ it 'should serialize text areas' do
125
+ expect(results['description']).to eq('Descriptive text goes here')
121
126
  end
122
127
 
123
- it "should serialize select tag with values" do
124
- expect(@results['locale']).to eq('en')
128
+ it 'should serialize select tag with values' do
129
+ expect(results['locale']).to eq('en')
125
130
  end
126
131
 
127
- it "should serialize select tag without values" do
128
- expect(@results['region']).to eq('Norway')
132
+ it 'should serialize select tag without values' do
133
+ expect(results['region']).to eq('Norway')
129
134
  end
130
135
 
131
- it "should serialize first option for select tag with no selection" do
132
- expect(@results['city']).to eq('London')
136
+ it 'should serialize first option for select tag with no selection' do
137
+ expect(results['city']).to eq('London')
133
138
  end
134
139
 
135
- it "should not serialize a select tag without options" do
136
- expect(@results['tendency']).to be_nil
140
+ it 'should not serialize a select tag without options' do
141
+ expect(results['tendency']).to be_nil
137
142
  end
138
143
 
139
- it "should convert lf to cr/lf in submitted textareas" do
140
- expect(@results['newline']).to eq("\r\nNew line after and before textarea tag\r\n")
144
+ it 'should convert lf to cr/lf in submitted textareas' do
145
+ expect(results['newline']).to eq("\r\nNew line after and before textarea tag\r\n")
141
146
  end
142
147
 
143
- it "should not submit disabled fields" do
144
- expect(@results['disabled_text_field']).to be_nil
145
- expect(@results['disabled_textarea']).to be_nil
146
- expect(@results['disabled_checkbox']).to be_nil
147
- expect(@results['disabled_radio']).to be_nil
148
- expect(@results['disabled_select']).to be_nil
149
- expect(@results['disabled_file']).to be_nil
148
+ it 'should not submit disabled fields' do
149
+ expect(results['disabled_text_field']).to be_nil
150
+ expect(results['disabled_textarea']).to be_nil
151
+ expect(results['disabled_checkbox']).to be_nil
152
+ expect(results['disabled_radio']).to be_nil
153
+ expect(results['disabled_select']).to be_nil
154
+ expect(results['disabled_file']).to be_nil
150
155
  end
151
156
  end
152
157
  end
153
158
 
154
- context "with id given on a submit button" do
155
- it "should submit the associated form" do
159
+ context 'input type=submit button' do
160
+ it 'should submit by button id' do
156
161
  @session.click_button('awe123')
157
162
  expect(extract_results(@session)['first_name']).to eq('John')
158
163
  end
159
164
 
160
- it "should work with partial matches" do
161
- @session.click_button('Go')
162
- expect(@session).to have_content('You landed')
165
+ it 'should submit by specific button id' do
166
+ @session.click_button(id: 'awe123')
167
+ expect(extract_results(@session)['first_name']).to eq('John')
163
168
  end
164
- end
165
169
 
166
- context "with title given on a submit button" do
167
- it "should submit the associated form" do
170
+ it 'should submit by button title' do
168
171
  @session.click_button('What an Awesome Button')
169
172
  expect(extract_results(@session)['first_name']).to eq('John')
170
173
  end
171
174
 
172
- it "should work with partial matches" do
175
+ it 'should submit by partial title', :exact_false do
173
176
  @session.click_button('What an Awesome')
174
177
  expect(extract_results(@session)['first_name']).to eq('John')
175
178
  end
179
+
180
+ it 'should submit by button name' do
181
+ @session.click_button('form[awesome]')
182
+ expect(extract_results(@session)['first_name']).to eq('John')
183
+ end
184
+
185
+ it 'should submit by specific button name' do
186
+ @session.click_button(name: 'form[awesome]')
187
+ expect(extract_results(@session)['first_name']).to eq('John')
188
+ end
189
+
190
+ it 'should submit by specific button name regex' do
191
+ @session.click_button(name: /form\[awes.*\]/)
192
+ expect(extract_results(@session)['first_name']).to eq('John')
193
+ end
176
194
  end
177
195
 
178
- context "with fields associated with the form using the form attribute" do
196
+ context 'when Capybara.enable_aria_role = true' do
197
+ it 'should click on a button role', requires: [:js] do
198
+ Capybara.enable_aria_role = true
199
+ @session.using_wait_time(1.5) do
200
+ @session.visit('/with_js')
201
+ @session.click_button('ARIA button')
202
+ expect(@session).to have_button('ARIA button has been clicked')
203
+ end
204
+ end
205
+ end
206
+
207
+ context 'with fields associated with the form using the form attribute', requires: [:form_attribute] do
208
+ let(:results) { extract_results(@session) }
209
+
179
210
  before do
180
211
  @session.click_button('submit_form1')
181
- @results = extract_results(@session)
182
212
  end
183
213
 
184
- it "should serialize and submit text fields" do
185
- expect(@results['outside_input']).to eq('outside_input')
214
+ it 'should serialize and submit text fields' do
215
+ expect(results['outside_input']).to eq('outside_input')
186
216
  end
187
217
 
188
- it "should serialize text areas" do
189
- expect(@results['outside_textarea']).to eq('Some text here')
218
+ it 'should serialize text areas' do
219
+ expect(results['outside_textarea']).to eq('Some text here')
190
220
  end
191
221
 
192
- it "should serialize select tags" do
193
- expect(@results['outside_select']).to eq('Ruby')
222
+ it 'should serialize select tags' do
223
+ expect(results['outside_select']).to eq('Ruby')
194
224
  end
195
225
 
196
- it "should not serliaze fields associated with a different form" do
197
- expect(@results['for_form2']).to be_nil
226
+ it 'should not serliaze fields associated with a different form' do
227
+ expect(results['for_form2']).to be_nil
198
228
  end
199
229
  end
200
230
 
231
+ context 'with submit button outside the form defined by <button> tag', requires: [:form_attribute] do
232
+ let(:results) { extract_results(@session) }
201
233
 
202
- context "with submit button outside the form defined by <button> tag" do
203
234
  before do
204
235
  @session.click_button('outside_button')
205
- @results = extract_results(@session)
206
236
  end
207
237
 
208
- it "should submit the associated form" do
209
- expect(@results['which_form']).to eq('form2')
238
+ it 'should submit the associated form' do
239
+ expect(results['which_form']).to eq('form2')
210
240
  end
211
241
 
212
- it "should submit the button that was clicked, but not other buttons" do
213
- expect(@results['outside_button']).to eq('outside_button')
214
- expect(@results['unused']).to be_nil
242
+ it 'should submit the button that was clicked, but not other buttons' do
243
+ expect(results['outside_button']).to eq('outside_button')
244
+ expect(results['unused']).to be_nil
215
245
  end
216
246
  end
217
247
 
218
- context "with submit button outside the form defined by <input type='submit'> tag" do
248
+ context "with submit button outside the form defined by <input type='submit'> tag", requires: [:form_attribute] do
249
+ let(:results) { extract_results(@session) }
250
+
219
251
  before do
220
252
  @session.click_button('outside_submit')
221
- @results = extract_results(@session)
222
253
  end
223
254
 
224
- it "should submit the associated form" do
225
- expect(@results['which_form']).to eq('form1')
255
+ it 'should submit the associated form' do
256
+ expect(results['which_form']).to eq('form1')
226
257
  end
227
258
 
228
- it "should submit the button that was clicked, but not other buttons" do
229
- expect(@results['outside_submit']).to eq('outside_submit')
230
- expect(@results['submit_form1']).to be_nil
259
+ it 'should submit the button that was clicked, but not other buttons' do
260
+ expect(results['outside_submit']).to eq('outside_submit')
261
+ expect(results['submit_form1']).to be_nil
231
262
  end
232
263
  end
233
264
 
234
- context "with submit button for form1 located within form2" do
235
- it "should submit the form associated with the button" do
265
+ context 'with submit button for form1 located within form2', requires: [:form_attribute] do
266
+ it 'should submit the form associated with the button' do
236
267
  @session.click_button('other_form_button')
237
- expect(extract_results(@session)['which_form']).to eq("form1")
268
+ expect(extract_results(@session)['which_form']).to eq('form1')
238
269
  end
239
270
  end
240
271
 
241
- context "with submit button not associated with any form" do
242
- it "should not error when clicked" do
272
+ context 'with submit button not associated with any form' do
273
+ it 'should not error when clicked' do
243
274
  expect { @session.click_button('no_form_button') }.not_to raise_error
244
275
  end
245
276
  end
246
277
 
247
- context "with alt given on an image button" do
248
- it "should submit the associated form" do
278
+ context 'with alt given on an image button' do
279
+ it 'should submit the associated form' do
249
280
  @session.click_button('oh hai thar')
250
281
  expect(extract_results(@session)['first_name']).to eq('John')
251
282
  end
252
283
 
253
- it "should work with partial matches" do
284
+ it 'should work with partial matches', :exact_false do
254
285
  @session.click_button('hai')
255
286
  expect(extract_results(@session)['first_name']).to eq('John')
256
287
  end
257
288
  end
258
289
 
259
-
260
- context "with value given on an image button" do
261
- it "should submit the associated form" do
290
+ context 'with value given on an image button' do
291
+ it 'should submit the associated form' do
262
292
  @session.click_button('okay')
263
293
  expect(extract_results(@session)['first_name']).to eq('John')
264
294
  end
265
295
 
266
- it "should work with partial matches" do
296
+ it 'should work with partial matches', :exact_false do
267
297
  @session.click_button('kay')
268
298
  expect(extract_results(@session)['first_name']).to eq('John')
269
299
  end
270
300
  end
271
301
 
272
- context "with id given on an image button" do
273
- it "should submit the associated form" do
302
+ context 'with id given on an image button' do
303
+ it 'should submit the associated form' do
274
304
  @session.click_button('okay556')
275
305
  expect(extract_results(@session)['first_name']).to eq('John')
276
306
  end
277
307
  end
278
308
 
279
- context "with title given on an image button" do
280
- it "should submit the associated form" do
309
+ context 'with title given on an image button' do
310
+ it 'should submit the associated form' do
281
311
  @session.click_button('Okay 556 Image')
282
312
  expect(extract_results(@session)['first_name']).to eq('John')
283
313
  end
284
314
 
285
- it "should work with partial matches" do
315
+ it 'should work with partial matches', :exact_false do
286
316
  @session.click_button('Okay 556')
287
317
  expect(extract_results(@session)['first_name']).to eq('John')
288
318
  end
289
319
  end
290
320
 
291
- context "with text given on a button defined by <button> tag" do
292
- it "should submit the associated form" do
293
- @session.click_button('Click me')
321
+ context 'with text given on a button defined by <button> tag' do
322
+ it 'should submit the associated form' do
323
+ @session.click_button('Click me!')
294
324
  expect(extract_results(@session)['first_name']).to eq('John')
295
325
  end
296
326
 
297
- it "should work with partial matches" do
327
+ it 'should work with partial matches', :exact_false do
298
328
  @session.click_button('Click')
299
329
  expect(extract_results(@session)['first_name']).to eq('John')
300
330
  end
301
331
  end
302
332
 
303
- context "with id given on a button defined by <button> tag" do
304
- it "should submit the associated form" do
333
+ context 'with id given on a button defined by <button> tag' do
334
+ it 'should submit the associated form' do
305
335
  @session.click_button('click_me_123')
306
336
  expect(extract_results(@session)['first_name']).to eq('John')
307
337
  end
308
338
 
309
- it "should serialize and send GET forms" do
339
+ it 'should serialize and send GET forms' do
310
340
  @session.visit('/form')
311
341
  @session.click_button('med')
312
- @results = extract_results(@session)
313
- expect(@results['middle_name']).to eq('Darren')
314
- expect(@results['foo']).to be_nil
342
+ results = extract_results(@session)
343
+ expect(results['middle_name']).to eq('Darren')
344
+ expect(results['foo']).to be_nil
315
345
  end
316
346
  end
317
347
 
318
- context "with value given on a button defined by <button> tag" do
319
- it "should submit the associated form" do
348
+ context 'with name given on a button defined by <button> tag' do
349
+ it 'should submit the associated form when name is locator' do
350
+ @session.click_button('form[no_value]')
351
+ expect(extract_results(@session)['first_name']).to eq('John')
352
+ end
353
+
354
+ it 'should submit the associated form when name is specific' do
355
+ @session.click_button(name: 'form[no_value]')
356
+ expect(extract_results(@session)['first_name']).to eq('John')
357
+ end
358
+ end
359
+
360
+ context 'with value given on a button defined by <button> tag' do
361
+ it 'should submit the associated form' do
320
362
  @session.click_button('click_me')
321
363
  expect(extract_results(@session)['first_name']).to eq('John')
322
364
  end
323
365
 
324
- it "should work with partial matches" do
366
+ it 'should work with partial matches', :exact_false do
325
367
  @session.click_button('ck_me')
326
368
  expect(extract_results(@session)['first_name']).to eq('John')
327
369
  end
328
370
  end
329
371
 
330
- context "with title given on a button defined by <button> tag" do
331
- it "should submit the associated form" do
372
+ context 'with title given on a button defined by <button> tag' do
373
+ it 'should submit the associated form' do
332
374
  @session.click_button('Click Title button')
333
375
  expect(extract_results(@session)['first_name']).to eq('John')
334
376
  end
335
377
 
336
- it "should work with partial matches" do
378
+ it 'should work with partial matches', :exact_false do
337
379
  @session.click_button('Click Title')
338
380
  expect(extract_results(@session)['first_name']).to eq('John')
339
381
  end
340
382
  end
383
+
384
+ context 'with descendant image alt given on a button defined by <button> tag' do
385
+ it 'should submit the associated form' do
386
+ @session.click_button('A horse eating hay')
387
+ expect(extract_results(@session)['first_name']).to eq('John')
388
+ end
389
+
390
+ it 'should work with partial matches', :exact_false do
391
+ @session.click_button('se eating h')
392
+ expect(extract_results(@session)['first_name']).to eq('John')
393
+ end
394
+ end
395
+
341
396
  context "with a locator that doesn't exist" do
342
- it "should raise an error" do
343
- msg = "Unable to find button \"does not exist\""
397
+ it 'should raise an error' do
398
+ msg = /Unable to find button "does not exist"/
344
399
  expect do
345
400
  @session.click_button('does not exist')
346
401
  end.to raise_error(Capybara::ElementNotFound, msg)
347
402
  end
348
403
  end
349
404
 
350
- context "with formaction attribute on button" do
351
- it "should submit to the formaction attribute" do
405
+ context 'with formaction attribute on button' do
406
+ it 'should submit to the formaction attribute' do
352
407
  @session.click_button('Formaction button')
353
- @results = extract_results(@session)
408
+ results = extract_results(@session)
354
409
  expect(@session.current_path).to eq '/form'
355
- expect(@results['which_form']).to eq 'formaction form'
410
+ expect(results['which_form']).to eq 'formaction form'
356
411
  end
357
412
  end
358
413
 
359
- context "with formmethod attribute on button" do
360
- it "should submit to the formethod attribute" do
414
+ context 'with formmethod attribute on button' do
415
+ it 'should submit to the formethod attribute' do
361
416
  @session.click_button('Formmethod button')
362
- @results = extract_results(@session)
417
+ results = extract_results(@session)
363
418
  expect(@session.current_path).to eq '/form/get'
364
- expect(@results['which_form']).to eq 'formaction form'
419
+ expect(results['which_form']).to eq 'formaction form'
365
420
  end
366
421
  end
367
422
 
368
- it "should serialize and send valueless buttons that were clicked" do
423
+ it 'should serialize and send valueless buttons that were clicked' do
369
424
  @session.click_button('No Value!')
370
- @results = extract_results(@session)
371
- expect(@results['no_value']).not_to be_nil
425
+ results = extract_results(@session)
426
+ expect(results['no_value']).not_to be_nil
427
+ end
428
+
429
+ it 'should send button in document order' do
430
+ @session.click_button('outside_button')
431
+ results = extract_results(@session)
432
+ expect(results.keys).to eq %w[for_form2 outside_button which_form post_count]
372
433
  end
373
434
 
374
- it "should not send image buttons that were not clicked" do
435
+ it 'should not send image buttons that were not clicked' do
375
436
  @session.click_button('Click me!')
376
- @results = extract_results(@session)
377
- expect(@results['okay']).to be_nil
437
+ results = extract_results(@session)
438
+ expect(results['okay']).to be_nil
378
439
  end
379
440
 
380
- it "should serialize and send GET forms" do
441
+ it 'should serialize and send GET forms' do
381
442
  @session.visit('/form')
382
443
  @session.click_button('med')
383
- @results = extract_results(@session)
384
- expect(@results['middle_name']).to eq('Darren')
385
- expect(@results['foo']).to be_nil
444
+ results = extract_results(@session)
445
+ expect(results['middle_name']).to eq('Darren')
446
+ expect(results['foo']).to be_nil
386
447
  end
387
448
 
388
- it "should follow redirects" do
449
+ it 'should follow redirects' do
389
450
  @session.click_button('Go FAR')
390
451
  expect(@session).to have_content('You landed')
391
452
  expect(@session.current_url).to match(%r{/landed$})
392
453
  end
393
454
 
394
- it "should post pack to the same URL when no action given" do
455
+ it 'should follow temporary redirects that maintain method' do
456
+ @session.click_button('Go 307')
457
+ expect(@session).to have_content('You post landed: TWTW')
458
+ end
459
+
460
+ it 'should follow permanent redirects that maintain method' do
461
+ @session.click_button('Go 308')
462
+ expect(@session).to have_content('You post landed: TWTW')
463
+ end
464
+
465
+ it 'should post pack to the same URL when no action given' do
395
466
  @session.visit('/postback')
396
467
  @session.click_button('With no action')
397
468
  expect(@session).to have_content('Postback')
398
469
  end
399
470
 
400
- it "should post pack to the same URL when blank action given" do
471
+ it 'should post pack to the same URL when blank action given' do
401
472
  @session.visit('/postback')
402
473
  @session.click_button('With blank action')
403
474
  expect(@session).to have_content('Postback')
404
475
  end
405
476
 
406
- it "ignores disabled buttons" do
477
+ it 'ignores disabled buttons' do
407
478
  expect do
408
479
  @session.click_button('Disabled button')
409
480
  end.to raise_error(Capybara::ElementNotFound)
410
481
  end
411
482
 
412
- it "should encode complex field names, like array[][value]" do
483
+ it 'should encode complex field names, like array[][value]' do
413
484
  @session.visit('/form')
414
- @session.fill_in('address1_city', :with =>'Paris')
415
- @session.fill_in('address1_street', :with =>'CDG')
416
- @session.fill_in('address1_street', :with =>'CDG')
417
- @session.select("France", :from => 'address1_country')
485
+ @session.fill_in('address1_city', with: 'Paris')
486
+ @session.fill_in('address1_street', with: 'CDG')
418
487
 
419
- @session.fill_in('address2_city', :with => 'Mikolaiv')
420
- @session.fill_in('address2_street', :with => 'PGS')
421
- @session.select("Ukraine", :from => 'address2_country')
488
+ @session.fill_in('address2_city', with: 'Mikolaiv')
489
+ @session.fill_in('address2_street', with: 'PGS')
422
490
 
423
- @session.click_button "awesome"
491
+ @session.click_button 'awesome'
424
492
 
425
- addresses=extract_results(@session)["addresses"]
493
+ addresses = extract_results(@session)['addresses']
426
494
  expect(addresses.size).to eq(2)
427
495
 
428
- expect(addresses[0]["street"]).to eq('CDG')
429
- expect(addresses[0]["city"]).to eq('Paris')
430
- expect(addresses[0]["country"]).to eq('France')
496
+ expect(addresses[0]['street']).to eq('CDG')
497
+ expect(addresses[0]['city']).to eq('Paris')
498
+ expect(addresses[0]['country']).to eq('France')
431
499
 
432
- expect(addresses[1]["street"]).to eq('PGS')
433
- expect(addresses[1]["city"]).to eq('Mikolaiv')
434
- expect(addresses[1]["country"]).to eq('Ukraine')
500
+ expect(addresses[1]['street']).to eq('PGS')
501
+ expect(addresses[1]['city']).to eq('Mikolaiv')
502
+ expect(addresses[1]['country']).to eq('Ukraine')
435
503
  end
436
504
 
437
- context "with :exact option" do
438
- it "should accept partial matches when false" do
439
- @session.click_button('What an Awesome', :exact => false)
505
+ context 'with :exact option' do
506
+ it 'should accept partial matches when false' do
507
+ @session.click_button('What an Awesome', exact: false)
440
508
  expect(extract_results(@session)['first_name']).to eq('John')
441
509
  end
442
510
 
443
- it "should not accept partial matches when true" do
511
+ it 'should not accept partial matches when true' do
444
512
  expect do
445
- @session.click_button('What an Awesome', :exact => true)
513
+ @session.click_button('What an Awesome', exact: true)
446
514
  end.to raise_error(Capybara::ElementNotFound)
447
515
  end
448
516
  end