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
@@ -11,521 +11,559 @@ RSpec.shared_examples Capybara::RSpecMatchers do |session, _mode|
11
11
  include Capybara::DSL
12
12
  include Capybara::RSpecMatchers
13
13
 
14
- describe "have_css matcher" do
15
- it "gives proper description" do
16
- expect(have_css('h1').description).to eq("have visible css \"h1\"")
14
+ describe 'have_css matcher' do
15
+ it 'gives proper description' do
16
+ expect(have_css('h1').description).to eq('have visible css "h1"')
17
17
  end
18
18
 
19
- context "on a string" do
20
- context "with should" do
21
- it "passes if has_css? returns true" do
22
- expect("<h1>Text</h1>").to have_css('h1')
19
+ context 'on a string' do
20
+ context 'with should' do
21
+ it 'passes if has_css? returns true' do
22
+ expect('<h1>Text</h1>').to have_css('h1')
23
23
  end
24
24
 
25
- it "fails if has_css? returns false" do
25
+ it 'fails if has_css? returns false' do
26
26
  expect do
27
- expect("<h1>Text</h1>").to have_css('h2')
28
- end.to raise_error(/expected to find visible css "h2" but there were no matches/)
27
+ expect('<h1>Text</h1>').to have_css('h2')
28
+ end.to raise_error(/expected to find css "h2" but there were no matches/)
29
29
  end
30
30
 
31
- it "passes if matched node count equals expected count" do
32
- expect("<h1>Text</h1>").to have_css('h1', count: 1)
31
+ it 'passes if matched node count equals expected count' do
32
+ expect('<h1>Text</h1>').to have_css('h1', count: 1)
33
33
  end
34
34
 
35
- it "fails if matched node count does not equal expected count" do
35
+ it 'fails if matched node count does not equal expected count' do
36
36
  expect do
37
- expect("<h1>Text</h1>").to have_css('h1', count: 2)
38
- end.to raise_error("expected to find visible css \"h1\" 2 times, found 1 match: \"Text\"")
37
+ expect('<h1>Text</h1>').to have_css('h1', count: 2)
38
+ end.to raise_error('expected to find visible css "h1" 2 times, found 1 match: "Text"')
39
39
  end
40
40
 
41
- it "fails if matched node count is less than expected minimum count" do
41
+ it 'fails if matched node count is less than expected minimum count' do
42
42
  expect do
43
- expect("<h1>Text</h1>").to have_css('p', minimum: 1)
44
- end.to raise_error("expected to find visible css \"p\" at least 1 time but there were no matches")
43
+ expect('<h1>Text</h1>').to have_css('p', minimum: 1)
44
+ end.to raise_error('expected to find css "p" at least 1 time but there were no matches')
45
45
  end
46
46
 
47
- it "fails if matched node count is more than expected maximum count" do
47
+ it 'fails if matched node count is more than expected maximum count' do
48
48
  expect do
49
- expect("<h1>Text</h1><h1>Text</h1><h1>Text</h1>").to have_css('h1', maximum: 2)
49
+ expect('<h1>Text</h1><h1>Text</h1><h1>Text</h1>').to have_css('h1', maximum: 2)
50
50
  end.to raise_error('expected to find visible css "h1" at most 2 times, found 3 matches: "Text", "Text", "Text"')
51
51
  end
52
52
 
53
- it "fails if matched node count does not belong to expected range" do
53
+ it 'fails if matched node count does not belong to expected range' do
54
54
  expect do
55
- expect("<h1>Text</h1>").to have_css('h1', between: 2..3)
56
- end.to raise_error("expected to find visible css \"h1\" between 2 and 3 times, found 1 match: \"Text\"")
55
+ expect('<h1>Text</h1>').to have_css('h1', between: 2..3)
56
+ end.to raise_error('expected to find visible css "h1" between 2 and 3 times, found 1 match: "Text"')
57
57
  end
58
58
  end
59
59
 
60
- context "with should_not" do
61
- it "passes if has_no_css? returns true" do
62
- expect("<h1>Text</h1>").not_to have_css('h2')
60
+ context 'with should_not' do
61
+ it 'passes if has_no_css? returns true' do
62
+ expect('<h1>Text</h1>').not_to have_css('h2')
63
63
  end
64
64
 
65
- it "fails if has_no_css? returns false" do
65
+ it 'fails if has_no_css? returns false' do
66
66
  expect do
67
- expect("<h1>Text</h1>").not_to have_css('h1')
67
+ expect('<h1>Text</h1>').not_to have_css('h1')
68
68
  end.to raise_error(/expected not to find visible css "h1"/)
69
69
  end
70
70
 
71
- it "passes if matched node count does not equal expected count" do
72
- expect("<h1>Text</h1>").not_to have_css('h1', count: 2)
71
+ it 'passes if matched node count does not equal expected count' do
72
+ expect('<h1>Text</h1>').not_to have_css('h1', count: 2)
73
73
  end
74
74
 
75
- it "fails if matched node count equals expected count" do
75
+ it 'fails if matched node count equals expected count' do
76
76
  expect do
77
- expect("<h1>Text</h1>").not_to have_css('h1', count: 1)
77
+ expect('<h1>Text</h1>').not_to have_css('h1', count: 1)
78
78
  end.to raise_error(/expected not to find visible css "h1"/)
79
79
  end
80
80
  end
81
81
 
82
- it "supports compounding" do
83
- expect("<h1>Text</h1><h2>Text</h2>").to have_css('h1').and have_css('h2')
84
- expect("<h1>Text</h1><h2>Text</h2>").to have_css('h3').or have_css('h1')
85
- expect("<h1>Text</h1><h2>Text</h2>").to have_no_css('h4').and have_css('h2')
86
- expect("<h1>Text</h1><h2>Text</h2>").to have_no_css('h2').or have_css('h1')
82
+ it 'supports compounding' do
83
+ expect('<h1>Text</h1><h2>Text</h2>').to have_css('h1').and have_css('h2')
84
+ expect('<h1>Text</h1><h2>Text</h2>').to have_css('h3').or have_css('h1')
85
+ expect('<h1>Text</h1><h2>Text</h2>').to have_no_css('h4').and have_css('h2')
86
+ expect('<h1>Text</h1><h2>Text</h2>').to have_no_css('h2').or have_css('h1')
87
87
  end
88
88
  end
89
89
 
90
- context "on a page or node" do
90
+ context 'on a page or node' do
91
91
  before do
92
- visit('/with_html')
92
+ session.visit('/with_html')
93
93
  end
94
94
 
95
- context "with should" do
96
- it "passes if has_css? returns true" do
97
- expect(page).to have_css('h1')
95
+ context 'with should' do
96
+ it 'passes if has_css? returns true' do
97
+ expect(session).to have_css('h1')
98
98
  end
99
99
 
100
- it "fails if has_css? returns false" do
100
+ it 'fails if has_css? returns false' do
101
101
  expect do
102
- expect(page).to have_css('h1#doesnotexist')
103
- end.to raise_error(/expected to find visible css "h1#doesnotexist" but there were no matches/)
102
+ expect(session).to have_css('h1#doesnotexist')
103
+ end.to raise_error(/expected to find css "h1#doesnotexist" but there were no matches/)
104
104
  end
105
105
  end
106
106
 
107
- context "with should_not" do
108
- it "passes if has_no_css? returns true" do
109
- expect(page).not_to have_css('h1#doesnotexist')
107
+ context 'with should_not' do
108
+ it 'passes if has_no_css? returns true' do
109
+ expect(session).not_to have_css('h1#doesnotexist')
110
110
  end
111
111
 
112
- it "fails if has_no_css? returns false" do
112
+ it 'fails if has_no_css? returns false' do
113
113
  expect do
114
- expect(page).not_to have_css('h1')
114
+ expect(session).not_to have_css('h1')
115
115
  end.to raise_error(/expected not to find visible css "h1"/)
116
116
  end
117
117
  end
118
118
  end
119
119
  end
120
120
 
121
- describe "have_xpath matcher" do
122
- it "gives proper description" do
123
- expect(have_xpath('//h1').description).to eq("have visible xpath \"\/\/h1\"")
121
+ describe 'have_xpath matcher' do
122
+ it 'gives proper description' do
123
+ expect(have_xpath('//h1').description).to eq('have visible xpath "//h1"')
124
124
  end
125
125
 
126
- context "on a string" do
127
- context "with should" do
128
- it "passes if has_xpath? returns true" do
129
- expect("<h1>Text</h1>").to have_xpath('//h1')
126
+ context 'on a string' do
127
+ context 'with should' do
128
+ it 'passes if has_xpath? returns true' do
129
+ expect('<h1>Text</h1>').to have_xpath('//h1')
130
130
  end
131
131
 
132
- it "fails if has_xpath? returns false" do
132
+ it 'fails if has_xpath? returns false' do
133
133
  expect do
134
- expect("<h1>Text</h1>").to have_xpath('//h2')
135
- end.to raise_error(%r{expected to find visible xpath "//h2" but there were no matches})
134
+ expect('<h1>Text</h1>').to have_xpath('//h2')
135
+ end.to raise_error(%r{expected to find xpath "//h2" but there were no matches})
136
136
  end
137
137
  end
138
138
 
139
- context "with should_not" do
140
- it "passes if has_no_xpath? returns true" do
141
- expect("<h1>Text</h1>").not_to have_xpath('//h2')
139
+ context 'with should_not' do
140
+ it 'passes if has_no_xpath? returns true' do
141
+ expect('<h1>Text</h1>').not_to have_xpath('//h2')
142
142
  end
143
143
 
144
- it "fails if has_no_xpath? returns false" do
144
+ it 'fails if has_no_xpath? returns false' do
145
145
  expect do
146
- expect("<h1>Text</h1>").not_to have_xpath('//h1')
146
+ expect('<h1>Text</h1>').not_to have_xpath('//h1')
147
147
  end.to raise_error(%r{expected not to find visible xpath "//h1"})
148
148
  end
149
149
  end
150
150
 
151
- it "supports compounding" do
152
- expect("<h1>Text</h1><h2>Text</h2>").to have_xpath('//h1').and have_xpath('//h2')
153
- expect("<h1>Text</h1><h2>Text</h2>").to have_xpath('//h3').or have_xpath('//h1')
154
- expect("<h1>Text</h1><h2>Text</h2>").to have_no_xpath('//h4').and have_xpath('//h1')
155
- expect("<h1>Text</h1><h2>Text</h2>").to have_no_xpath('//h4').or have_xpath('//h4')
151
+ it 'supports compounding' do
152
+ expect('<h1>Text</h1><h2>Text</h2>').to have_xpath('//h1').and have_xpath('//h2')
153
+ expect('<h1>Text</h1><h2>Text</h2>').to have_xpath('//h3').or have_xpath('//h1')
154
+ expect('<h1>Text</h1><h2>Text</h2>').to have_no_xpath('//h4').and have_xpath('//h1')
155
+ expect('<h1>Text</h1><h2>Text</h2>').to have_no_xpath('//h4').or have_xpath('//h4')
156
156
  end
157
157
  end
158
158
 
159
- context "on a page or node" do
159
+ context 'on a page or node' do
160
160
  before do
161
- visit('/with_html')
161
+ session.visit('/with_html')
162
162
  end
163
163
 
164
- context "with should" do
165
- it "passes if has_xpath? returns true" do
166
- expect(page).to have_xpath('//h1')
164
+ context 'with should' do
165
+ it 'passes if has_xpath? returns true' do
166
+ expect(session).to have_xpath('//h1')
167
167
  end
168
168
 
169
- it "fails if has_xpath? returns false" do
169
+ it 'fails if has_xpath? returns false' do
170
170
  expect do
171
- expect(page).to have_xpath("//h1[@id='doesnotexist']")
172
- end.to raise_error(%r{expected to find visible xpath "//h1\[@id='doesnotexist'\]" but there were no matches})
171
+ expect(session).to have_xpath("//h1[@id='doesnotexist']")
172
+ end.to raise_error(%r{expected to find xpath "//h1\[@id='doesnotexist'\]" but there were no matches})
173
173
  end
174
174
  end
175
175
 
176
- context "with should_not" do
177
- it "passes if has_no_xpath? returns true" do
178
- expect(page).not_to have_xpath('//h1[@id="doesnotexist"]')
176
+ context 'with should_not' do
177
+ it 'passes if has_no_xpath? returns true' do
178
+ expect(session).not_to have_xpath('//h1[@id="doesnotexist"]')
179
179
  end
180
180
 
181
- it "fails if has_no_xpath? returns false" do
181
+ it 'fails if has_no_xpath? returns false' do
182
182
  expect do
183
- expect(page).not_to have_xpath('//h1')
183
+ expect(session).not_to have_xpath('//h1')
184
184
  end.to raise_error(%r{expected not to find visible xpath "//h1"})
185
185
  end
186
186
  end
187
187
  end
188
188
  end
189
189
 
190
- describe "have_selector matcher" do
191
- it "gives proper description" do
190
+ describe 'have_selector matcher' do
191
+ it 'gives proper description' do
192
192
  matcher = have_selector('//h1')
193
- expect("<h1>Text</h1>").to matcher
194
- expect(matcher.description).to eq("have visible xpath \"//h1\"")
193
+ expect('<h1>Text</h1>').to matcher
194
+ expect(matcher.description).to eq('have visible xpath "//h1"')
195
195
  end
196
196
 
197
- context "on a string" do
198
- context "with should" do
199
- it "passes if has_selector? returns true" do
200
- expect("<h1>Text</h1>").to have_selector('//h1')
197
+ context 'on a string' do
198
+ context 'with should' do
199
+ it 'passes if has_selector? returns true' do
200
+ expect('<h1>Text</h1>').to have_selector('//h1')
201
201
  end
202
202
 
203
- it "fails if has_selector? returns false" do
203
+ it 'fails if has_selector? returns false' do
204
204
  expect do
205
- expect("<h1>Text</h1>").to have_selector('//h2')
206
- end.to raise_error(%r{expected to find visible xpath "//h2" but there were no matches})
205
+ expect('<h1>Text</h1>').to have_selector('//h2')
206
+ end.to raise_error(%r{expected to find xpath "//h2" but there were no matches})
207
207
  end
208
208
  end
209
209
 
210
- context "with should_not" do
211
- it "passes if has_no_selector? returns true" do
212
- expect("<h1>Text</h1>").not_to have_selector(:css, 'h2')
210
+ context 'with should_not' do
211
+ it 'passes if has_no_selector? returns true' do
212
+ expect('<h1>Text</h1>').not_to have_selector(:css, 'h2')
213
213
  end
214
214
 
215
- it "fails if has_no_selector? returns false" do
215
+ it 'fails if has_no_selector? returns false' do
216
216
  expect do
217
- expect("<h1>Text</h1>").not_to have_selector(:css, 'h1')
217
+ expect('<h1>Text</h1>').not_to have_selector(:css, 'h1')
218
218
  end.to raise_error(/expected not to find visible css "h1"/)
219
219
  end
220
220
  end
221
221
  end
222
222
 
223
- context "on a page or node" do
223
+ context 'on a page or node' do
224
224
  before do
225
- visit('/with_html')
225
+ session.visit('/with_html')
226
226
  end
227
227
 
228
- context "with should" do
229
- it "passes if has_selector? returns true" do
230
- expect(page).to have_selector('//h1', text: 'test')
228
+ context 'with should' do
229
+ it 'passes if has_selector? returns true' do
230
+ expect(session).to have_selector('//h1', text: 'test')
231
231
  end
232
232
 
233
- it "fails if has_selector? returns false" do
233
+ it 'fails if has_selector? returns false' do
234
234
  expect do
235
- expect(page).to have_selector("//h1[@id='doesnotexist']")
236
- end.to raise_error(%r{expected to find visible xpath "//h1\[@id='doesnotexist'\]" but there were no matches})
235
+ expect(session).to have_selector("//h1[@id='doesnotexist']")
236
+ end.to raise_error(%r{expected to find xpath "//h1\[@id='doesnotexist'\]" but there were no matches})
237
237
  end
238
238
 
239
- it "includes text in error message" do
239
+ it 'includes text in error message' do
240
240
  expect do
241
- expect(page).to have_selector("//h1", text: 'wrong text')
241
+ expect(session).to have_selector('//h1', text: 'wrong text')
242
242
  end.to raise_error(%r{expected to find visible xpath "//h1" with text "wrong text" but there were no matches})
243
243
  end
244
244
  end
245
245
 
246
- context "with should_not" do
247
- it "passes if has_no_css? returns true" do
248
- expect(page).not_to have_selector(:css, 'h1#doesnotexist')
246
+ context 'with should_not' do
247
+ it 'passes if has_no_css? returns true' do
248
+ expect(session).not_to have_selector(:css, 'h1#doesnotexist')
249
249
  end
250
250
 
251
- it "fails if has_no_selector? returns false" do
251
+ it 'fails if has_no_selector? returns false' do
252
252
  expect do
253
- expect(page).not_to have_selector(:css, 'h1', text: 'test')
253
+ expect(session).not_to have_selector(:css, 'h1', text: 'test')
254
254
  end.to raise_error(/expected not to find visible css "h1" with text "test"/)
255
255
  end
256
256
  end
257
257
  end
258
258
 
259
- it "supports compounding" do
260
- expect("<h1>Text</h1><h2>Text</h2>").to have_selector('//h1').and have_selector('//h2')
261
- expect("<h1>Text</h1><h2>Text</h2>").to have_selector('//h3').or have_selector('//h1')
262
- expect("<h1>Text</h1><h2>Text</h2>").to have_no_selector('//h3').and have_selector('//h1')
259
+ it 'supports compounding' do
260
+ expect('<h1>Text</h1><h2>Text</h2>').to have_selector('//h1').and have_selector('//h2')
261
+ expect('<h1>Text</h1><h2>Text</h2>').to have_selector('//h3').or have_selector('//h1')
262
+ expect('<h1>Text</h1><h2>Text</h2>').to have_no_selector('//h3').and have_selector('//h1')
263
263
  end
264
264
  end
265
265
 
266
- describe "have_content matcher" do
267
- it "gives proper description" do
268
- expect(have_content('Text').description).to eq("text \"Text\"")
266
+ describe 'have_content matcher' do
267
+ it 'gives proper description' do
268
+ expect(have_content('Text').description).to eq('have text "Text"')
269
269
  end
270
270
 
271
- context "on a string" do
272
- context "with should" do
273
- it "passes if has_content? returns true" do
274
- expect("<h1>Text</h1>").to have_content('Text')
271
+ context 'on a string' do
272
+ context 'with should' do
273
+ it 'passes if has_content? returns true' do
274
+ expect('<h1>Text</h1>').to have_content('Text')
275
275
  end
276
276
 
277
- it "passes if has_content? returns true using regexp" do
278
- expect("<h1>Text</h1>").to have_content(/ext/)
277
+ it 'passes if has_content? returns true using regexp' do
278
+ expect('<h1>Text</h1>').to have_content(/ext/)
279
279
  end
280
280
 
281
- it "fails if has_content? returns false" do
281
+ it 'fails if has_content? returns false' do
282
282
  expect do
283
- expect("<h1>Text</h1>").to have_content('No such Text')
283
+ expect('<h1>Text</h1>').to have_content('No such Text')
284
284
  end.to raise_error(/expected to find text "No such Text" in "Text"/)
285
285
  end
286
286
  end
287
287
 
288
- context "with should_not" do
289
- it "passes if has_no_content? returns true" do
290
- expect("<h1>Text</h1>").not_to have_content('No such Text')
288
+ context 'with should_not' do
289
+ it 'passes if has_no_content? returns true' do
290
+ expect('<h1>Text</h1>').not_to have_content('No such Text')
291
291
  end
292
292
 
293
- it "passes because escapes any characters that would have special meaning in a regexp" do
294
- expect("<h1>Text</h1>").not_to have_content('.')
293
+ it 'passes because escapes any characters that would have special meaning in a regexp' do
294
+ expect('<h1>Text</h1>').not_to have_content('.')
295
295
  end
296
296
 
297
- it "fails if has_no_content? returns false" do
297
+ it 'fails if has_no_content? returns false' do
298
298
  expect do
299
- expect("<h1>Text</h1>").not_to have_content('Text')
299
+ expect('<h1>Text</h1>').not_to have_content('Text')
300
300
  end.to raise_error(/expected not to find text "Text" in "Text"/)
301
301
  end
302
302
  end
303
303
  end
304
304
 
305
- context "on a page or node" do
305
+ context 'on a page or node' do
306
306
  before do
307
- visit('/with_html')
307
+ session.visit('/with_html')
308
308
  end
309
309
 
310
- context "with should" do
311
- it "passes if has_content? returns true" do
312
- expect(page).to have_content('This is a test')
310
+ context 'with should' do
311
+ it 'passes if has_content? returns true' do
312
+ expect(session).to have_content('This is a test')
313
313
  end
314
314
 
315
- it "passes if has_content? returns true using regexp" do
316
- expect(page).to have_content(/test/)
315
+ it 'passes if has_content? returns true using regexp' do
316
+ expect(session).to have_content(/test/)
317
317
  end
318
318
 
319
- it "fails if has_content? returns false" do
319
+ it 'fails if has_content? returns false' do
320
320
  expect do
321
- expect(page).to have_content('No such Text')
321
+ expect(session).to have_content('No such Text')
322
322
  end.to raise_error(/expected to find text "No such Text" in "(.*)This is a test(.*)"/)
323
323
  end
324
324
 
325
- context "with default selector CSS" do
325
+ context 'with default selector CSS' do
326
326
  before { Capybara.default_selector = :css }
327
327
 
328
- it "fails if has_content? returns false" do
328
+ after { Capybara.default_selector = :xpath }
329
+
330
+ it 'fails if has_content? returns false' do
329
331
  expect do
330
- expect(page).to have_content('No such Text')
332
+ expect(session).to have_content('No such Text')
331
333
  end.to raise_error(/expected to find text "No such Text" in "(.*)This is a test(.*)"/)
332
334
  end
333
- after { Capybara.default_selector = :xpath }
334
335
  end
335
336
  end
336
337
 
337
- context "with should_not" do
338
- it "passes if has_no_content? returns true" do
339
- expect(page).not_to have_content('No such Text')
338
+ context 'with should_not' do
339
+ it 'passes if has_no_content? returns true' do
340
+ expect(session).not_to have_content('No such Text')
340
341
  end
341
342
 
342
- it "fails if has_no_content? returns false" do
343
+ it 'fails if has_no_content? returns false' do
343
344
  expect do
344
- expect(page).not_to have_content('This is a test')
345
+ expect(session).not_to have_content('This is a test')
345
346
  end.to raise_error(/expected not to find text "This is a test"/)
346
347
  end
348
+
349
+ it 'not_to have_content behaves the same as to have_no_content' do
350
+ Capybara.using_wait_time(5) do
351
+ expect(session).to have_content('This is a test')
352
+ start = Time.now
353
+ expect(session).to have_no_content('No such Text')
354
+ to_time = Time.now
355
+ expect(session).not_to have_content('No such Text')
356
+ not_to_time = Time.now
357
+ expect(not_to_time - to_time).to be_within(0.5).of(to_time - start)
358
+ end
359
+ end
347
360
  end
348
361
  end
349
362
 
350
- it "supports compounding" do
351
- expect("<h1>Text</h1><h2>And</h2>").to have_content('Text').and have_content('And')
352
- expect("<h1>Text</h1><h2>Or</h2>").to have_content('XYZ').or have_content('Or')
353
- expect("<h1>Text</h1><h2>Or</h2>").to have_no_content('XYZ').and have_content('Or')
363
+ it 'supports compounding' do
364
+ expect('<h1>Text</h1><h2>And</h2>').to have_content('Text').and have_content('And')
365
+ expect('<h1>Text</h1><h2>Or</h2>').to have_content('XYZ').or have_content('Or')
366
+ expect('<h1>Text</h1><h2>Or</h2>').to have_no_content('XYZ').and have_content('Or')
354
367
  end
355
368
  end
356
369
 
357
- describe "have_text matcher" do
358
- it "gives proper description" do
359
- expect(have_text('Text').description).to eq("text \"Text\"")
370
+ describe 'have_text matcher' do
371
+ it 'gives proper description' do
372
+ expect(have_text('Text').description).to eq('have text "Text"')
360
373
  end
361
374
 
362
- context "on a string" do
363
- context "with should" do
364
- it "passes if text contains given string" do
365
- expect("<h1>Text</h1>").to have_text('Text')
375
+ context 'on a string' do
376
+ context 'with should' do
377
+ it 'passes if text contains given string' do
378
+ expect('<h1>Text</h1>').to have_text('Text')
366
379
  end
367
380
 
368
- it "passes if text matches given regexp" do
369
- expect("<h1>Text</h1>").to have_text(/ext/)
381
+ it 'passes if text matches given regexp' do
382
+ expect('<h1>Text</h1>').to have_text(/ext/)
370
383
  end
371
384
 
372
385
  it "fails if text doesn't contain given string" do
373
386
  expect do
374
- expect("<h1>Text</h1>").to have_text('No such Text')
387
+ expect('<h1>Text</h1>').to have_text('No such Text')
375
388
  end.to raise_error(/expected to find text "No such Text" in "Text"/)
376
389
  end
377
390
 
378
391
  it "fails if text doesn't match given regexp" do
379
392
  expect do
380
- expect("<h1>Text</h1>").to have_text(/No such Text/)
393
+ expect('<h1>Text</h1>').to have_text(/No such Text/)
381
394
  end.to raise_error('expected to find text matching /No such Text/ in "Text"')
382
395
  end
383
396
 
384
- it "casts Integer to string" do
397
+ it 'casts Integer to string' do
385
398
  expect do
386
- expect("<h1>Text</h1>").to have_text(3)
399
+ expect('<h1>Text</h1>').to have_text(3)
387
400
  end.to raise_error(/expected to find text "3" in "Text"/)
388
401
  end
389
402
 
390
- it "fails if matched text count does not equal to expected count" do
403
+ it 'fails if matched text count does not equal to expected count' do
391
404
  expect do
392
- expect("<h1>Text</h1>").to have_text('Text', count: 2)
405
+ expect('<h1>Text</h1>').to have_text('Text', count: 2)
393
406
  end.to raise_error('expected to find text "Text" 2 times but found 1 time in "Text"')
394
407
  end
395
408
 
396
- it "fails if matched text count is less than expected minimum count" do
409
+ it 'fails if matched text count is less than expected minimum count' do
397
410
  expect do
398
- expect("<h1>Text</h1>").to have_text('Lorem', minimum: 1)
411
+ expect('<h1>Text</h1>').to have_text('Lorem', minimum: 1)
399
412
  end.to raise_error('expected to find text "Lorem" at least 1 time but found 0 times in "Text"')
400
413
  end
401
414
 
402
- it "fails if matched text count is more than expected maximum count" do
415
+ it 'fails if matched text count is more than expected maximum count' do
403
416
  expect do
404
- expect("<h1>Text TextText</h1>").to have_text('Text', maximum: 2)
417
+ expect('<h1>Text TextText</h1>').to have_text('Text', maximum: 2)
405
418
  end.to raise_error('expected to find text "Text" at most 2 times but found 3 times in "Text TextText"')
406
419
  end
407
420
 
408
- it "fails if matched text count does not belong to expected range" do
421
+ it 'fails if matched text count does not belong to expected range' do
409
422
  expect do
410
- expect("<h1>Text</h1>").to have_text('Text', between: 2..3)
423
+ expect('<h1>Text</h1>').to have_text('Text', between: 2..3)
411
424
  end.to raise_error('expected to find text "Text" between 2 and 3 times but found 1 time in "Text"')
412
425
  end
413
426
  end
414
427
 
415
- context "with should_not" do
428
+ context 'with should_not' do
416
429
  it "passes if text doesn't contain a string" do
417
- expect("<h1>Text</h1>").not_to have_text('No such Text')
430
+ expect('<h1>Text</h1>').not_to have_text('No such Text')
418
431
  end
419
432
 
420
- it "passes because escapes any characters that would have special meaning in a regexp" do
421
- expect("<h1>Text</h1>").not_to have_text('.')
433
+ it 'passes because escapes any characters that would have special meaning in a regexp' do
434
+ expect('<h1>Text</h1>').not_to have_text('.')
422
435
  end
423
436
 
424
- it "fails if text contains a string" do
437
+ it 'fails if text contains a string' do
425
438
  expect do
426
- expect("<h1>Text</h1>").not_to have_text('Text')
439
+ expect('<h1>Text</h1>').not_to have_text('Text')
427
440
  end.to raise_error(/expected not to find text "Text" in "Text"/)
428
441
  end
429
442
  end
430
443
  end
431
444
 
432
- context "on a page or node" do
445
+ context 'on a page or node' do
433
446
  before do
434
- visit('/with_html')
447
+ session.visit('/with_html')
435
448
  end
436
449
 
437
- context "with should" do
438
- it "passes if has_text? returns true" do
439
- expect(page).to have_text('This is a test')
450
+ context 'with should' do
451
+ it 'passes if has_text? returns true' do
452
+ expect(session).to have_text('This is a test')
440
453
  end
441
454
 
442
- it "passes if has_text? returns true using regexp" do
443
- expect(page).to have_text(/test/)
455
+ it 'passes if has_text? returns true using regexp' do
456
+ expect(session).to have_text(/test/)
444
457
  end
445
458
 
446
- it "can check for all text" do
447
- expect(page).to have_text(:all, 'Some of this text is hidden!')
459
+ it 'can check for all text' do
460
+ expect(session).to have_text(:all, 'Some of this text is hidden!')
448
461
  end
449
462
 
450
- it "can check for visible text" do
451
- expect(page).to have_text(:visible, 'Some of this text is')
452
- expect(page).not_to have_text(:visible, 'Some of this text is hidden!')
463
+ it 'can check for visible text' do
464
+ expect(session).to have_text(:visible, 'Some of this text is')
465
+ expect(session).not_to have_text(:visible, 'Some of this text is hidden!')
453
466
  end
454
467
 
455
- it "fails if has_text? returns false" do
468
+ it 'fails if has_text? returns false' do
456
469
  expect do
457
- expect(page).to have_text('No such Text')
470
+ expect(session).to have_text('No such Text')
458
471
  end.to raise_error(/expected to find text "No such Text" in "(.*)This is a test(.*)"/)
459
472
  end
460
473
 
461
- context "with default selector CSS" do
474
+ context 'with default selector CSS' do
462
475
  before { Capybara.default_selector = :css }
463
476
 
464
- it "fails if has_text? returns false" do
477
+ after { Capybara.default_selector = :xpath }
478
+
479
+ it 'fails if has_text? returns false' do
465
480
  expect do
466
- expect(page).to have_text('No such Text')
481
+ expect(session).to have_text('No such Text')
467
482
  end.to raise_error(/expected to find text "No such Text" in "(.*)This is a test(.*)"/)
468
483
  end
469
- after { Capybara.default_selector = :xpath }
470
484
  end
471
485
  end
472
486
 
473
- context "with should_not" do
474
- it "passes if has_no_text? returns true" do
475
- expect(page).not_to have_text('No such Text')
487
+ context 'with should_not' do
488
+ it 'passes if has_no_text? returns true' do
489
+ expect(session).not_to have_text('No such Text')
476
490
  end
477
491
 
478
- it "fails if has_no_text? returns false" do
492
+ it 'fails if has_no_text? returns false' do
479
493
  expect do
480
- expect(page).not_to have_text('This is a test')
494
+ expect(session).not_to have_text('This is a test')
481
495
  end.to raise_error(/expected not to find text "This is a test"/)
482
496
  end
483
497
  end
484
498
  end
485
499
 
486
- it "supports compounding" do
487
- expect("<h1>Text</h1><h2>And</h2>").to have_text('Text').and have_text('And')
488
- expect("<h1>Text</h1><h2>Or</h2>").to have_text('Not here').or have_text('Or')
500
+ it 'supports compounding' do
501
+ expect('<h1>Text</h1><h2>And</h2>').to have_text('Text').and have_text('And')
502
+ expect('<h1>Text</h1><h2>Or</h2>').to have_text('Not here').or have_text('Or')
503
+ end
504
+ end
505
+
506
+ describe 'have_element matcher' do
507
+ let(:html) { '<img src="/img.jpg" alt="a JPEG"><img src="/img.png" alt="a PNG">' }
508
+
509
+ it 'gives proper description' do
510
+ expect(have_element('img').description).to eq('have visible element "img"')
511
+ end
512
+
513
+ it 'passes if there is such a element' do
514
+ expect(html).to have_element('img', src: '/img.jpg')
515
+ end
516
+
517
+ it 'fails if there is no such element' do
518
+ expect do
519
+ expect(html).to have_element('photo')
520
+ end.to raise_error(/expected to find element "photo"/)
521
+ end
522
+
523
+ it 'supports compounding' do
524
+ expect(html).to have_element('img', alt: 'a JPEG').and have_element('img', src: '/img.png')
525
+ expect(html).to have_element('photo').or have_element('img', src: '/img.jpg')
526
+ expect(html).to have_no_element('photo').and have_element('img', alt: 'a PNG')
489
527
  end
490
528
  end
491
529
 
492
- describe "have_link matcher" do
530
+ describe 'have_link matcher' do
493
531
  let(:html) { '<a href="#">Just a link</a><a href="#">Another link</a>' }
494
532
 
495
- it "gives proper description" do
496
- expect(have_link('Just a link').description).to eq("have visible link \"Just a link\"")
533
+ it 'gives proper description' do
534
+ expect(have_link('Just a link').description).to eq('have visible link "Just a link"')
497
535
  end
498
536
 
499
- it "passes if there is such a button" do
537
+ it 'passes if there is such a link' do
500
538
  expect(html).to have_link('Just a link')
501
539
  end
502
540
 
503
- it "fails if there is no such button" do
541
+ it 'fails if there is no such link' do
504
542
  expect do
505
543
  expect(html).to have_link('No such Link')
506
- end.to raise_error(/expected to find visible link "No such Link"/)
544
+ end.to raise_error(/expected to find link "No such Link"/)
507
545
  end
508
546
 
509
- it "supports compounding" do
547
+ it 'supports compounding' do
510
548
  expect(html).to have_link('Just a link').and have_link('Another link')
511
549
  expect(html).to have_link('Not a link').or have_link('Another link')
512
550
  expect(html).to have_no_link('Not a link').and have_link('Another link')
513
551
  end
514
552
  end
515
553
 
516
- describe "have_title matcher" do
517
- it "gives proper description" do
518
- expect(have_title('Just a title').description).to eq("have title \"Just a title\"")
554
+ describe 'have_title matcher' do
555
+ it 'gives proper description' do
556
+ expect(have_title('Just a title').description).to eq('have title "Just a title"')
519
557
  end
520
558
 
521
- context "on a string" do
559
+ context 'on a string' do
522
560
  let(:html) { '<title>Just a title</title>' }
523
561
 
524
- it "passes if there is such a title" do
562
+ it 'passes if there is such a title' do
525
563
  expect(html).to have_title('Just a title')
526
564
  end
527
565
 
528
- it "fails if there is no such title" do
566
+ it 'fails if there is no such title' do
529
567
  expect do
530
568
  expect(html).to have_title('No such title')
531
569
  end.to raise_error('expected "Just a title" to include "No such title"')
@@ -538,401 +576,405 @@ RSpec.shared_examples Capybara::RSpecMatchers do |session, _mode|
538
576
  end
539
577
  end
540
578
 
541
- context "on a page or node" do
542
- it "passes if there is such a title" do
543
- visit('/with_js')
544
- expect(page).to have_title('with_js')
579
+ context 'on a page or node' do
580
+ it 'passes if there is such a title' do
581
+ session.visit('/with_js')
582
+ expect(session).to have_title('with_js')
545
583
  end
546
584
 
547
- it "fails if there is no such title" do
548
- visit('/with_js')
585
+ it 'fails if there is no such title' do
586
+ session.visit('/with_js')
549
587
  expect do
550
- expect(page).to have_title('No such title')
551
- end.to raise_error('expected "with_js" to include "No such title"')
588
+ expect(session).to have_title('No such title')
589
+ end.to raise_error(/ to include "No such title"/)
552
590
  end
553
591
 
554
592
  context 'with wait' do
555
593
  before do
556
- @session = session
557
- @session.visit('/with_js')
594
+ session.visit('/with_js')
558
595
  end
559
596
 
560
597
  it 'waits if wait time is more than timeout' do
561
- @session.click_link("Change title")
562
- using_wait_time 0 do
563
- expect(@session).to have_title('changed title', wait: 2)
598
+ session.click_link('Change title')
599
+ session.using_wait_time 0 do
600
+ expect(session).to have_title('changed title', wait: 2)
564
601
  end
565
602
  end
566
603
 
567
604
  it "doesn't wait if wait time is less than timeout" do
568
- @session.click_link("Change title")
569
- using_wait_time 3 do
570
- expect(@session).not_to have_title('changed title', wait: 0)
605
+ session.click_link('Change title')
606
+ session.using_wait_time 3 do
607
+ expect(session).not_to have_title('changed title', wait: 0)
571
608
  end
572
609
  end
573
610
  end
574
611
  end
575
612
 
576
- it "supports compounding" do
577
- expect("<title>I compound</title>").to have_title('I dont compound').or have_title('I compound')
613
+ it 'supports compounding' do
614
+ expect('<title>I compound</title>').to have_title('I dont compound').or have_title('I compound')
578
615
  end
579
616
  end
580
617
 
581
- describe "have_current_path matcher" do
582
- it "gives proper description" do
583
- expect(have_current_path('http://www.example.com').description).to eq("have current path \"http://www.example.com\"")
618
+ describe 'have_current_path matcher' do
619
+ it 'gives proper description' do
620
+ expect(have_current_path('http://www.example.com').description).to eq('have current path "http://www.example.com"')
584
621
  end
585
622
 
586
- context "on a page or node" do
587
- it "passes if there is such a current path" do
588
- visit('/with_js')
589
- expect(page).to have_current_path('/with_js')
623
+ context 'on a page or node' do
624
+ it 'passes if there is such a current path' do
625
+ session.visit('/with_js')
626
+ expect(session).to have_current_path('/with_js')
590
627
  end
591
628
 
592
- it "fails if there is no such current_path" do
629
+ it 'fails if there is no such current_path' do
593
630
  visit('/with_js')
594
631
  expect do
595
- expect(page).to have_current_path('/not_with_js')
596
- end.to raise_error('expected "/with_js" to equal "/not_with_js"')
632
+ expect(session).to have_current_path('/not_with_js')
633
+ end.to raise_error(%r{to equal "/not_with_js"})
597
634
  end
598
635
 
599
636
  context 'with wait' do
600
637
  before do
601
- @session = session
602
- @session.visit('/with_js')
638
+ session.visit('/with_js')
603
639
  end
604
640
 
605
641
  it 'waits if wait time is more than timeout' do
606
- @session.click_link("Change page")
607
- using_wait_time 0 do
608
- expect(@session).to have_current_path('/with_html', wait: 2)
642
+ session.click_link('Change page')
643
+ session.using_wait_time 0 do
644
+ expect(session).to have_current_path('/with_html', wait: 2)
609
645
  end
610
646
  end
611
647
 
612
648
  it "doesn't wait if wait time is less than timeout" do
613
- @session.click_link("Change page")
614
- using_wait_time 0 do
615
- expect(@session).not_to have_current_path('/with_html')
649
+ session.click_link('Change page')
650
+ session.using_wait_time 0 do
651
+ expect(session).not_to have_current_path('/with_html')
616
652
  end
617
653
  end
618
654
  end
619
655
  end
620
656
 
621
- it "supports compounding" do
622
- visit('/with_html')
623
- expect(page).to have_current_path('/not_with_html').or have_current_path('/with_html')
657
+ it 'supports compounding' do
658
+ session.visit('/with_html')
659
+ expect(session).to have_current_path('/not_with_html').or have_current_path('/with_html')
624
660
  end
625
661
  end
626
662
 
627
- describe "have_button matcher" do
663
+ describe 'have_button matcher' do
628
664
  let(:html) { '<button>A button</button><input type="submit" value="Another button"/>' }
629
665
 
630
- it "gives proper description" do
631
- expect(have_button('A button').description).to eq("have visible button \"A button\"")
666
+ it 'gives proper description with no options' do
667
+ expect(have_button('A button').description).to eq('have visible button "A button" that is not disabled')
632
668
  end
633
669
 
634
- it "passes if there is such a button" do
670
+ it 'gives proper description with disabled :any option' do
671
+ expect(have_button('A button', disabled: :all).description).to eq('have visible button "A button"')
672
+ end
673
+
674
+ it 'passes if there is such a button' do
635
675
  expect(html).to have_button('A button')
636
676
  end
637
677
 
638
- it "fails if there is no such button" do
678
+ it 'fails if there is no such button' do
639
679
  expect do
640
680
  expect(html).to have_button('No such Button')
641
- end.to raise_error(/expected to find visible button "No such Button"/)
681
+ end.to raise_error(/expected to find button "No such Button"/)
642
682
  end
643
683
 
644
- it "supports compounding" do
684
+ it 'supports compounding' do
645
685
  expect(html).to have_button('Not this button').or have_button('A button')
646
686
  end
647
687
  end
648
688
 
649
- describe "have_field matcher" do
689
+ describe 'have_field matcher' do
650
690
  let(:html) { '<p><label>Text field<input type="text" value="some value"/></label></p>' }
651
691
 
652
- it "gives proper description" do
653
- expect(have_field('Text field').description).to eq("have visible field \"Text field\" that is not disabled")
692
+ it 'gives proper description' do
693
+ expect(have_field('Text field').description).to eq('have visible field "Text field" that is not disabled')
654
694
  end
655
695
 
656
- it "gives proper description for a given value" do
657
- expect(have_field('Text field', with: 'some value').description).to eq("have visible field \"Text field\" that is not disabled with value \"some value\"")
696
+ it 'gives proper description for a given value' do
697
+ expect(have_field('Text field', with: 'some value').description).to eq('have visible field "Text field" that is not disabled with value "some value"')
658
698
  end
659
699
 
660
- it "passes if there is such a field" do
700
+ it 'passes if there is such a field' do
661
701
  expect(html).to have_field('Text field')
662
702
  end
663
703
 
664
- it "passes if there is such a field with value" do
704
+ it 'passes if there is such a field with value' do
665
705
  expect(html).to have_field('Text field', with: 'some value')
666
706
  end
667
707
 
668
- it "fails if there is no such field" do
708
+ it 'fails if there is no such field' do
669
709
  expect do
670
710
  expect(html).to have_field('No such Field')
671
- end.to raise_error(/expected to find visible field "No such Field"/)
711
+ end.to raise_error(/expected to find field "No such Field"/)
672
712
  end
673
713
 
674
- it "fails if there is such field but with false value" do
714
+ it 'fails if there is such field but with false value' do
675
715
  expect do
676
716
  expect(html).to have_field('Text field', with: 'false value')
677
717
  end.to raise_error(/expected to find visible field "Text field"/)
678
718
  end
679
719
 
680
- it "treats a given value as a string" do
681
- class Foo
720
+ it 'treats a given value as a string' do
721
+ foo = Class.new do
682
722
  def to_s
683
- "some value"
723
+ 'some value'
684
724
  end
685
725
  end
686
- expect(html).to have_field('Text field', with: Foo.new)
726
+ expect(html).to have_field('Text field', with: foo.new)
687
727
  end
688
728
 
689
- it "supports compounding" do
729
+ it 'supports compounding' do
690
730
  expect(html).to have_field('Not this one').or have_field('Text field')
691
731
  end
692
732
  end
693
733
 
694
- describe "have_checked_field matcher" do
734
+ describe 'have_checked_field matcher' do
695
735
  let(:html) do
696
736
  '<label>it is checked<input type="checkbox" checked="checked"/></label>
697
737
  <label>unchecked field<input type="checkbox"/></label>'
698
738
  end
699
739
 
700
- it "gives proper description" do
701
- expect(have_checked_field('it is checked').description).to eq("have visible field \"it is checked\" that is checked and not disabled")
740
+ it 'gives proper description' do
741
+ expect(have_checked_field('it is checked').description).to eq('have visible field "it is checked" that is not disabled that is checked')
702
742
  end
703
743
 
704
- context "with should" do
705
- it "passes if there is such a field and it is checked" do
744
+ context 'with should' do
745
+ it 'passes if there is such a field and it is checked' do
706
746
  expect(html).to have_checked_field('it is checked')
707
747
  end
708
748
 
709
- it "fails if there is such a field but it is not checked" do
749
+ it 'fails if there is such a field but it is not checked' do
710
750
  expect do
711
751
  expect(html).to have_checked_field('unchecked field')
712
752
  end.to raise_error(/expected to find visible field "unchecked field"/)
713
753
  end
714
754
 
715
- it "fails if there is no such field" do
755
+ it 'fails if there is no such field' do
716
756
  expect do
717
757
  expect(html).to have_checked_field('no such field')
718
- end.to raise_error(/expected to find visible field "no such field"/)
758
+ end.to raise_error(/expected to find field "no such field"/)
719
759
  end
720
760
  end
721
761
 
722
- context "with should not" do
723
- it "fails if there is such a field and it is checked" do
762
+ context 'with should not' do
763
+ it 'fails if there is such a field and it is checked' do
724
764
  expect do
725
765
  expect(html).not_to have_checked_field('it is checked')
726
766
  end.to raise_error(/expected not to find visible field "it is checked"/)
727
767
  end
728
768
 
729
- it "passes if there is such a field but it is not checked" do
769
+ it 'passes if there is such a field but it is not checked' do
730
770
  expect(html).not_to have_checked_field('unchecked field')
731
771
  end
732
772
 
733
- it "passes if there is no such field" do
773
+ it 'passes if there is no such field' do
734
774
  expect(html).not_to have_checked_field('no such field')
735
775
  end
736
776
  end
737
777
 
738
- it "supports compounding" do
778
+ it 'supports compounding' do
739
779
  expect(html).to have_checked_field('not this one').or have_checked_field('it is checked')
740
780
  end
741
781
  end
742
782
 
743
- describe "have_unchecked_field matcher" do
783
+ describe 'have_unchecked_field matcher' do
744
784
  let(:html) do
745
785
  '<label>it is checked<input type="checkbox" checked="checked"/></label>
746
786
  <label>unchecked field<input type="checkbox"/></label>'
747
787
  end
748
788
 
749
- it "gives proper description" do
750
- expect(have_unchecked_field('unchecked field').description).to eq("have visible field \"unchecked field\" that is not checked and not disabled")
789
+ it 'gives proper description' do
790
+ expect(have_unchecked_field('unchecked field').description).to eq('have visible field "unchecked field" that is not disabled that is not checked')
751
791
  end
752
792
 
753
- context "with should" do
754
- it "passes if there is such a field and it is not checked" do
793
+ context 'with should' do
794
+ it 'passes if there is such a field and it is not checked' do
755
795
  expect(html).to have_unchecked_field('unchecked field')
756
796
  end
757
797
 
758
- it "fails if there is such a field but it is checked" do
798
+ it 'fails if there is such a field but it is checked' do
759
799
  expect do
760
800
  expect(html).to have_unchecked_field('it is checked')
761
801
  end.to raise_error(/expected to find visible field "it is checked"/)
762
802
  end
763
803
 
764
- it "fails if there is no such field" do
804
+ it 'fails if there is no such field' do
765
805
  expect do
766
806
  expect(html).to have_unchecked_field('no such field')
767
- end.to raise_error(/expected to find visible field "no such field"/)
807
+ end.to raise_error(/expected to find field "no such field"/)
768
808
  end
769
809
  end
770
810
 
771
- context "with should not" do
772
- it "fails if there is such a field and it is not checked" do
811
+ context 'with should not' do
812
+ it 'fails if there is such a field and it is not checked' do
773
813
  expect do
774
814
  expect(html).not_to have_unchecked_field('unchecked field')
775
815
  end.to raise_error(/expected not to find visible field "unchecked field"/)
776
816
  end
777
817
 
778
- it "passes if there is such a field but it is checked" do
818
+ it 'passes if there is such a field but it is checked' do
779
819
  expect(html).not_to have_unchecked_field('it is checked')
780
820
  end
781
821
 
782
- it "passes if there is no such field" do
822
+ it 'passes if there is no such field' do
783
823
  expect(html).not_to have_unchecked_field('no such field')
784
824
  end
785
825
  end
786
826
 
787
- it "supports compounding" do
827
+ it 'supports compounding' do
788
828
  expect(html).to have_unchecked_field('it is checked').or have_unchecked_field('unchecked field')
789
829
  end
790
830
  end
791
831
 
792
- describe "have_select matcher" do
832
+ describe 'have_select matcher' do
793
833
  let(:html) { '<label>Select Box<select></select></label>' }
794
834
 
795
- it "gives proper description" do
796
- expect(have_select('Select Box').description).to eq("have visible select box \"Select Box\" that is not disabled")
835
+ it 'gives proper description' do
836
+ expect(have_select('Select Box').description).to eq('have visible select box "Select Box" that is not disabled')
797
837
  end
798
838
 
799
- it "gives proper description for a given selected value" do
839
+ it 'gives proper description for a given selected value' do
800
840
  expect(have_select('Select Box', selected: 'some value').description).to eq('have visible select box "Select Box" that is not disabled with "some value" selected')
801
841
  end
802
842
 
803
- it "passes if there is such a select" do
843
+ it 'passes if there is such a select' do
804
844
  expect(html).to have_select('Select Box')
805
845
  end
806
846
 
807
- it "fails if there is no such select" do
847
+ it 'fails if there is no such select' do
808
848
  expect do
809
849
  expect(html).to have_select('No such Select box')
810
- end.to raise_error(/expected to find visible select box "No such Select box"/)
850
+ end.to raise_error(/expected to find select box "No such Select box"/)
811
851
  end
812
852
 
813
- it "supports compounding" do
853
+ it 'supports compounding' do
814
854
  expect(html).to have_select('Not this one').or have_select('Select Box')
815
855
  end
816
856
  end
817
857
 
818
- describe "have_table matcher" do
858
+ describe 'have_table matcher' do
819
859
  let(:html) { '<table><caption>Lovely table</caption></table>' }
820
860
 
821
- it "gives proper description" do
822
- expect(have_table('Lovely table').description).to eq("have visible table \"Lovely table\"")
861
+ it 'gives proper description' do
862
+ expect(have_table('Lovely table').description).to eq('have visible table "Lovely table"')
863
+ expect(have_table('Lovely table', caption: 'my caption').description).to eq('have visible table "Lovely table" with caption "my caption"')
823
864
  end
824
865
 
825
- it "gives proper description when :visible option passed" do
826
- expect(have_table('Lovely table', visible: true).description).to eq("have visible table \"Lovely table\"")
827
- expect(have_table('Lovely table', visible: :hidden).description).to eq("have non-visible table \"Lovely table\"")
828
- expect(have_table('Lovely table', visible: :all).description).to eq("have table \"Lovely table\"")
829
- expect(have_table('Lovely table', visible: false).description).to eq("have table \"Lovely table\"")
866
+ it 'gives proper description when :visible option passed' do
867
+ expect(have_table('Lovely table', visible: true).description).to eq('have visible table "Lovely table"') # rubocop:disable Capybara/VisibilityMatcher
868
+ expect(have_table('Lovely table', visible: :hidden).description).to eq('have non-visible table "Lovely table"')
869
+ expect(have_table('Lovely table', visible: :all).description).to eq('have table "Lovely table"')
870
+ expect(have_table('Lovely table', visible: false).description).to eq('have table "Lovely table"') # rubocop:disable Capybara/VisibilityMatcher
830
871
  end
831
872
 
832
- it "passes if there is such a select" do
873
+ it 'passes if there is such a table' do
833
874
  expect(html).to have_table('Lovely table')
834
875
  end
835
876
 
836
- it "fails if there is no such select" do
877
+ it 'fails if there is no such table' do
837
878
  expect do
838
879
  expect(html).to have_table('No such Table')
839
- end.to raise_error(/expected to find visible table "No such Table"/)
880
+ end.to raise_error(/expected to find table "No such Table"/)
840
881
  end
841
882
 
842
- it "supports compounding" do
883
+ it 'supports compounding' do
843
884
  expect(html).to have_table('nope').or have_table('Lovely table')
844
885
  end
845
886
  end
846
887
 
847
- context "compounding timing" do
888
+ context 'compounding timing' do
889
+ let(:session) { session }
890
+ let(:el) { session.find(:css, '#reload-me') }
891
+
848
892
  before do
849
- @session = session
850
- @session.visit('/with_js')
851
- @el = @session.find(:css, '#reload-me')
893
+ session.visit('/with_js')
852
894
  end
853
895
 
854
- context "#and" do
896
+ describe '#and' do
855
897
  it "should run 'concurrently'" do
856
- Capybara.using_wait_time(2) do
898
+ session.using_wait_time(2) do
857
899
  matcher = have_text('this is not there').and have_text('neither is this')
858
900
  expect(Benchmark.realtime do
859
901
  expect do
860
- expect(@el).to matcher
902
+ expect(el).to matcher
861
903
  end.to raise_error RSpec::Expectations::ExpectationNotMetError
862
904
  end).to be_between(2, 3)
863
905
  end
864
906
  end
865
907
 
866
908
  it "should run 'concurrently' and retry" do
867
- @session.click_link('reload-link')
868
- @session.using_wait_time(2) do
909
+ session.click_link('reload-link')
910
+ session.using_wait_time(2) do
869
911
  expect(Benchmark.realtime do
870
912
  expect do
871
- expect(@el).to have_text('waiting to be reloaded').and(have_text('has been reloaded'))
913
+ expect(el).to have_text('waiting to be reloaded').and(have_text('has been reloaded'))
872
914
  end.to raise_error RSpec::Expectations::ExpectationNotMetError, /expected to find text "waiting to be reloaded" in "has been reloaded"/
873
915
  end).to be_between(2, 3)
874
916
  end
875
917
  end
876
918
 
877
- it "should ignore :wait options" do
878
- @session.using_wait_time(2) do
919
+ it 'should ignore :wait options' do
920
+ session.using_wait_time(2) do
879
921
  matcher = have_text('this is not there', wait: 5).and have_text('neither is this', wait: 6)
880
922
  expect(Benchmark.realtime do
881
923
  expect do
882
- expect(@el).to matcher
924
+ expect(el).to matcher
883
925
  end.to raise_error RSpec::Expectations::ExpectationNotMetError
884
926
  end).to be_between(2, 3)
885
927
  end
886
928
  end
887
929
 
888
- it "should work on the session" do
889
- @session.using_wait_time(2) do
890
- @session.click_link('reload-link')
891
- expect(@session).to have_selector(:css, 'h1', text: 'FooBar').and have_text('has been reloaded')
930
+ it 'should work on the session' do
931
+ session.using_wait_time(2) do
932
+ session.click_link('reload-link')
933
+ expect(session).to have_selector(:css, 'h1', text: 'FooBar').and have_text('has been reloaded')
892
934
  end
893
935
  end
894
936
  end
895
937
 
896
- context "#and_then" do
897
- it "should run sequentially" do
898
- @session.click_link('reload-link')
899
- expect(@el).to have_text('waiting to be reloaded').and_then have_text('has been reloaded')
938
+ describe '#and_then' do
939
+ it 'should run sequentially' do
940
+ session.click_link('reload-link')
941
+ expect(el).to have_text('waiting to be reloaded').and_then have_text('has been reloaded')
900
942
  end
901
943
  end
902
944
 
903
- context "#or" do
945
+ describe '#or' do
904
946
  it "should run 'concurrently'" do
905
- @session.using_wait_time(3) do
947
+ session.using_wait_time(3) do
906
948
  expect(Benchmark.realtime do
907
- expect(@el).to have_text('has been reloaded').or have_text('waiting to be reloaded')
949
+ expect(el).to have_text('has been reloaded').or have_text('waiting to be reloaded')
908
950
  end).to be < 1
909
951
  end
910
952
  end
911
953
 
912
- it "should retry" do
913
- @session.using_wait_time(3) do
954
+ it 'should retry' do
955
+ session.using_wait_time(3) do
914
956
  expect(Benchmark.realtime do
915
957
  expect do
916
- expect(@el).to have_text('has been reloaded').or have_text('random stuff')
958
+ expect(el).to have_text('has been reloaded').or have_text('random stuff')
917
959
  end.to raise_error RSpec::Expectations::ExpectationNotMetError
918
960
  end).to be > 3
919
961
  end
920
962
  end
921
963
 
922
- it "should ignore :wait options" do
923
- @session.using_wait_time(2) do
964
+ it 'should ignore :wait options' do
965
+ session.using_wait_time(2) do
924
966
  expect(Benchmark.realtime do
925
967
  expect do
926
- expect(@el).to have_text('this is not there', wait: 10).or have_text('neither is this', wait: 15)
968
+ expect(el).to have_text('this is not there', wait: 10).or have_text('neither is this', wait: 15)
927
969
  end.to raise_error RSpec::Expectations::ExpectationNotMetError
928
970
  end).to be_between(2, 3)
929
971
  end
930
972
  end
931
973
 
932
- it "should work on the session" do
933
- @session.using_wait_time(2) do
934
- @session.click_link('reload-link')
935
- expect(@session).to have_selector(:css, 'h1', text: 'Not on the page').or have_text('has been reloaded')
974
+ it 'should work on the session' do
975
+ session.using_wait_time(2) do
976
+ session.click_link('reload-link')
977
+ expect(session).to have_selector(:css, 'h1', text: 'Not on the page').or have_text('has been reloaded')
936
978
  end
937
979
  end
938
980
  end