capybara 2.5.0 → 2.18.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (205) hide show
  1. checksums.yaml +5 -5
  2. data/.yard/templates_custom/default/class/html/selectors.erb +38 -0
  3. data/.yard/templates_custom/default/class/html/setup.rb +17 -0
  4. data/.yard/yard_extensions.rb +78 -0
  5. data/.yardopts +1 -0
  6. data/History.md +413 -10
  7. data/License.txt +1 -1
  8. data/README.md +237 -130
  9. data/lib/capybara/config.rb +132 -0
  10. data/lib/capybara/cucumber.rb +3 -1
  11. data/lib/capybara/driver/base.rb +27 -6
  12. data/lib/capybara/driver/node.rb +14 -5
  13. data/lib/capybara/dsl.rb +2 -3
  14. data/lib/capybara/helpers.rb +13 -65
  15. data/lib/capybara/minitest/spec.rb +177 -0
  16. data/lib/capybara/minitest.rb +278 -0
  17. data/lib/capybara/node/actions.rb +180 -24
  18. data/lib/capybara/node/base.rb +17 -5
  19. data/lib/capybara/node/document.rb +5 -0
  20. data/lib/capybara/node/document_matchers.rb +15 -14
  21. data/lib/capybara/node/element.rb +55 -7
  22. data/lib/capybara/node/finders.rb +179 -67
  23. data/lib/capybara/node/matchers.rb +301 -105
  24. data/lib/capybara/node/simple.rb +15 -4
  25. data/lib/capybara/queries/ancestor_query.rb +25 -0
  26. data/lib/capybara/queries/base_query.rb +69 -3
  27. data/lib/capybara/queries/current_path_query.rb +17 -8
  28. data/lib/capybara/queries/match_query.rb +19 -0
  29. data/lib/capybara/queries/selector_query.rb +251 -0
  30. data/lib/capybara/queries/sibling_query.rb +25 -0
  31. data/lib/capybara/queries/text_query.rb +67 -16
  32. data/lib/capybara/queries/title_query.rb +4 -2
  33. data/lib/capybara/query.rb +3 -131
  34. data/lib/capybara/rack_test/browser.rb +14 -5
  35. data/lib/capybara/rack_test/css_handlers.rb +1 -0
  36. data/lib/capybara/rack_test/driver.rb +15 -8
  37. data/lib/capybara/rack_test/form.rb +34 -12
  38. data/lib/capybara/rack_test/node.rb +29 -12
  39. data/lib/capybara/rails.rb +3 -3
  40. data/lib/capybara/result.rb +104 -9
  41. data/lib/capybara/rspec/compound.rb +95 -0
  42. data/lib/capybara/rspec/features.rb +17 -6
  43. data/lib/capybara/rspec/matcher_proxies.rb +45 -0
  44. data/lib/capybara/rspec/matchers.rb +199 -80
  45. data/lib/capybara/rspec.rb +4 -2
  46. data/lib/capybara/selector/css.rb +30 -0
  47. data/lib/capybara/selector/filter.rb +20 -0
  48. data/lib/capybara/selector/filter_set.rb +74 -0
  49. data/lib/capybara/selector/filters/base.rb +33 -0
  50. data/lib/capybara/selector/filters/expression_filter.rb +40 -0
  51. data/lib/capybara/selector/filters/node_filter.rb +27 -0
  52. data/lib/capybara/selector/selector.rb +276 -0
  53. data/lib/capybara/selector.rb +452 -157
  54. data/lib/capybara/selenium/driver.rb +282 -81
  55. data/lib/capybara/selenium/node.rb +144 -46
  56. data/lib/capybara/server.rb +59 -16
  57. data/lib/capybara/session/config.rb +114 -0
  58. data/lib/capybara/session/matchers.rb +29 -19
  59. data/lib/capybara/session.rb +378 -143
  60. data/lib/capybara/spec/fixtures/no_extension +1 -0
  61. data/lib/capybara/spec/public/jquery-ui.js +13 -791
  62. data/lib/capybara/spec/public/jquery.js +4 -9045
  63. data/lib/capybara/spec/public/test.js +45 -11
  64. data/lib/capybara/spec/session/accept_alert_spec.rb +30 -7
  65. data/lib/capybara/spec/session/accept_confirm_spec.rb +14 -2
  66. data/lib/capybara/spec/session/accept_prompt_spec.rb +35 -6
  67. data/lib/capybara/spec/session/all_spec.rb +45 -32
  68. data/lib/capybara/spec/session/ancestor_spec.rb +85 -0
  69. data/lib/capybara/spec/session/assert_all_of_selectors_spec.rb +110 -0
  70. data/lib/capybara/spec/session/assert_current_path.rb +15 -2
  71. data/lib/capybara/spec/session/assert_selector.rb +29 -28
  72. data/lib/capybara/spec/session/assert_text.rb +59 -20
  73. data/lib/capybara/spec/session/assert_title.rb +25 -11
  74. data/lib/capybara/spec/session/attach_file_spec.rb +42 -4
  75. data/lib/capybara/spec/session/body_spec.rb +1 -0
  76. data/lib/capybara/spec/session/check_spec.rb +90 -14
  77. data/lib/capybara/spec/session/choose_spec.rb +31 -5
  78. data/lib/capybara/spec/session/click_button_spec.rb +20 -9
  79. data/lib/capybara/spec/session/click_link_or_button_spec.rb +15 -9
  80. data/lib/capybara/spec/session/click_link_spec.rb +39 -15
  81. data/lib/capybara/spec/session/current_scope_spec.rb +2 -1
  82. data/lib/capybara/spec/session/current_url_spec.rb +12 -3
  83. data/lib/capybara/spec/session/dismiss_confirm_spec.rb +6 -5
  84. data/lib/capybara/spec/session/dismiss_prompt_spec.rb +4 -3
  85. data/lib/capybara/spec/session/element/assert_match_selector.rb +36 -0
  86. data/lib/capybara/spec/session/element/match_css_spec.rb +23 -0
  87. data/lib/capybara/spec/session/element/match_xpath_spec.rb +23 -0
  88. data/lib/capybara/spec/session/element/matches_selector_spec.rb +106 -0
  89. data/lib/capybara/spec/session/evaluate_async_script_spec.rb +22 -0
  90. data/lib/capybara/spec/session/evaluate_script_spec.rb +23 -1
  91. data/lib/capybara/spec/session/execute_script_spec.rb +22 -3
  92. data/lib/capybara/spec/session/fill_in_spec.rb +50 -32
  93. data/lib/capybara/spec/session/find_button_spec.rb +43 -2
  94. data/lib/capybara/spec/session/find_by_id_spec.rb +3 -2
  95. data/lib/capybara/spec/session/find_field_spec.rb +42 -6
  96. data/lib/capybara/spec/session/find_link_spec.rb +22 -3
  97. data/lib/capybara/spec/session/find_spec.rb +103 -57
  98. data/lib/capybara/spec/session/first_spec.rb +34 -18
  99. data/lib/capybara/spec/session/frame/switch_to_frame_spec.rb +103 -0
  100. data/lib/capybara/spec/session/{within_frame_spec.rb → frame/within_frame_spec.rb} +44 -2
  101. data/lib/capybara/spec/session/go_back_spec.rb +2 -1
  102. data/lib/capybara/spec/session/go_forward_spec.rb +2 -1
  103. data/lib/capybara/spec/session/has_all_selectors_spec.rb +69 -0
  104. data/lib/capybara/spec/session/has_button_spec.rb +17 -8
  105. data/lib/capybara/spec/session/has_css_spec.rb +85 -73
  106. data/lib/capybara/spec/session/has_current_path_spec.rb +91 -7
  107. data/lib/capybara/spec/session/has_field_spec.rb +93 -58
  108. data/lib/capybara/spec/session/has_link_spec.rb +9 -8
  109. data/lib/capybara/spec/session/has_none_selectors_spec.rb +76 -0
  110. data/lib/capybara/spec/session/has_select_spec.rb +159 -59
  111. data/lib/capybara/spec/session/has_selector_spec.rb +64 -28
  112. data/lib/capybara/spec/session/has_table_spec.rb +1 -0
  113. data/lib/capybara/spec/session/has_text_spec.rb +27 -12
  114. data/lib/capybara/spec/session/has_title_spec.rb +22 -4
  115. data/lib/capybara/spec/session/has_xpath_spec.rb +32 -29
  116. data/lib/capybara/spec/session/headers.rb +2 -1
  117. data/lib/capybara/spec/session/html_spec.rb +4 -3
  118. data/lib/capybara/spec/session/node_spec.rb +198 -38
  119. data/lib/capybara/spec/session/refresh_spec.rb +28 -0
  120. data/lib/capybara/spec/session/reset_session_spec.rb +46 -5
  121. data/lib/capybara/spec/session/response_code.rb +2 -1
  122. data/lib/capybara/spec/session/save_and_open_page_spec.rb +1 -0
  123. data/lib/capybara/spec/session/save_and_open_screenshot_spec.rb +6 -5
  124. data/lib/capybara/spec/session/save_page_spec.rb +34 -2
  125. data/lib/capybara/spec/session/save_screenshot_spec.rb +31 -1
  126. data/lib/capybara/spec/session/screenshot_spec.rb +4 -2
  127. data/lib/capybara/spec/session/select_spec.rb +34 -32
  128. data/lib/capybara/spec/session/selectors_spec.rb +65 -0
  129. data/lib/capybara/spec/session/sibling_spec.rb +52 -0
  130. data/lib/capybara/spec/session/text_spec.rb +4 -4
  131. data/lib/capybara/spec/session/title_spec.rb +2 -1
  132. data/lib/capybara/spec/session/uncheck_spec.rb +42 -2
  133. data/lib/capybara/spec/session/unselect_spec.rb +17 -16
  134. data/lib/capybara/spec/session/visit_spec.rb +77 -2
  135. data/lib/capybara/spec/session/window/become_closed_spec.rb +12 -11
  136. data/lib/capybara/spec/session/window/current_window_spec.rb +1 -0
  137. data/lib/capybara/spec/session/window/open_new_window_spec.rb +1 -0
  138. data/lib/capybara/spec/session/window/switch_to_window_spec.rb +16 -11
  139. data/lib/capybara/spec/session/window/window_opened_by_spec.rb +7 -4
  140. data/lib/capybara/spec/session/window/window_spec.rb +36 -29
  141. data/lib/capybara/spec/session/window/windows_spec.rb +1 -0
  142. data/lib/capybara/spec/session/window/within_window_spec.rb +31 -7
  143. data/lib/capybara/spec/session/within_spec.rb +14 -6
  144. data/lib/capybara/spec/spec_helper.rb +37 -4
  145. data/lib/capybara/spec/test_app.rb +15 -3
  146. data/lib/capybara/spec/views/buttons.erb +1 -0
  147. data/lib/capybara/spec/views/fieldsets.erb +2 -1
  148. data/lib/capybara/spec/views/form.erb +169 -9
  149. data/lib/capybara/spec/views/frame_child.erb +10 -2
  150. data/lib/capybara/spec/views/frame_one.erb +2 -1
  151. data/lib/capybara/spec/views/frame_parent.erb +3 -2
  152. data/lib/capybara/spec/views/frame_two.erb +2 -1
  153. data/lib/capybara/spec/views/header_links.erb +1 -0
  154. data/lib/capybara/spec/views/host_links.erb +1 -0
  155. data/lib/capybara/spec/views/initial_alert.erb +10 -0
  156. data/lib/capybara/spec/views/path.erb +1 -0
  157. data/lib/capybara/spec/views/popup_one.erb +1 -0
  158. data/lib/capybara/spec/views/popup_two.erb +1 -0
  159. data/lib/capybara/spec/views/postback.erb +2 -1
  160. data/lib/capybara/spec/views/tables.erb +1 -0
  161. data/lib/capybara/spec/views/with_base_tag.erb +1 -0
  162. data/lib/capybara/spec/views/with_count.erb +2 -1
  163. data/lib/capybara/spec/views/with_fixed_header_footer.erb +17 -0
  164. data/lib/capybara/spec/views/with_hover.erb +7 -1
  165. data/lib/capybara/spec/views/with_html.erb +40 -2
  166. data/lib/capybara/spec/views/with_html_entities.erb +1 -0
  167. data/lib/capybara/spec/views/with_js.erb +32 -1
  168. data/lib/capybara/spec/views/with_scope.erb +1 -0
  169. data/lib/capybara/spec/views/with_simple_html.erb +2 -1
  170. data/lib/capybara/spec/views/with_slow_unload.erb +17 -0
  171. data/lib/capybara/spec/views/with_title.erb +2 -1
  172. data/lib/capybara/spec/views/with_unload_alert.erb +14 -0
  173. data/lib/capybara/spec/views/with_windows.erb +7 -0
  174. data/lib/capybara/spec/views/within_frames.erb +3 -2
  175. data/lib/capybara/version.rb +2 -1
  176. data/lib/capybara/window.rb +20 -3
  177. data/lib/capybara.rb +189 -93
  178. data/spec/basic_node_spec.rb +7 -6
  179. data/spec/capybara_spec.rb +90 -4
  180. data/spec/dsl_spec.rb +3 -1
  181. data/spec/filter_set_spec.rb +28 -0
  182. data/spec/fixtures/capybara.csv +1 -0
  183. data/spec/fixtures/selenium_driver_rspec_failure.rb +5 -1
  184. data/spec/fixtures/selenium_driver_rspec_success.rb +5 -1
  185. data/spec/minitest_spec.rb +130 -0
  186. data/spec/minitest_spec_spec.rb +135 -0
  187. data/spec/per_session_config_spec.rb +67 -0
  188. data/spec/rack_test_spec.rb +50 -7
  189. data/spec/result_spec.rb +76 -0
  190. data/spec/rspec/features_spec.rb +21 -8
  191. data/spec/rspec/scenarios_spec.rb +21 -0
  192. data/spec/rspec/{matchers_spec.rb → shared_spec_matchers.rb} +160 -54
  193. data/spec/rspec/views_spec.rb +5 -0
  194. data/spec/rspec_matchers_spec.rb +46 -0
  195. data/spec/rspec_spec.rb +79 -1
  196. data/spec/selector_spec.rb +199 -0
  197. data/spec/selenium_spec_chrome.rb +54 -9
  198. data/spec/selenium_spec_firefox.rb +68 -0
  199. data/spec/selenium_spec_marionette.rb +127 -0
  200. data/spec/server_spec.rb +102 -14
  201. data/spec/session_spec.rb +54 -0
  202. data/spec/shared_selenium_session.rb +215 -0
  203. data/spec/spec_helper.rb +7 -0
  204. metadata +140 -15
  205. data/spec/selenium_spec.rb +0 -128
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  Capybara::SpecHelper.spec '#assert_current_path' do
2
3
  before do
3
4
  @session.visit('/with_js')
@@ -11,7 +12,7 @@ Capybara::SpecHelper.spec '#assert_current_path' do
11
12
  expect { @session.assert_current_path(/w[a-z]{3}_js/) }.not_to raise_error
12
13
  end
13
14
 
14
- it "should wait for current_path", :requires => [:js] do
15
+ it "should wait for current_path", requires: [:js] do
15
16
  @session.click_link("Change page")
16
17
  expect { @session.assert_current_path("/with_html") }.not_to raise_error
17
18
  end
@@ -33,6 +34,12 @@ Capybara::SpecHelper.spec '#assert_current_path' do
33
34
  @session.visit('/with_js?test=test')
34
35
  expect{@session.assert_current_path('/with_js', only_path: true)}.not_to raise_error
35
36
  end
37
+
38
+ it "should not cause an exception when current_url is nil" do
39
+ allow_any_instance_of(Capybara::Session).to receive(:current_url) { nil }
40
+
41
+ expect{@session.assert_current_path(nil)}.not_to raise_error
42
+ end
36
43
  end
37
44
 
38
45
  Capybara::SpecHelper.spec '#assert_no_current_path?' do
@@ -48,7 +55,7 @@ Capybara::SpecHelper.spec '#assert_no_current_path?' do
48
55
  expect{@session.assert_no_current_path(/monkey/)}.not_to raise_error
49
56
  end
50
57
 
51
- it "should wait for current_path to disappear", :requires => [:js] do
58
+ it "should wait for current_path to disappear", requires: [:js] do
52
59
  @session.click_link("Change page")
53
60
  expect{@session.assert_no_current_path('/with_js')}.not_to raise_error
54
61
  end
@@ -56,4 +63,10 @@ Capybara::SpecHelper.spec '#assert_no_current_path?' do
56
63
  it "should not raise if the page has not the given current_path" do
57
64
  expect{@session.assert_no_current_path('/with_html')}.not_to raise_error
58
65
  end
66
+
67
+ it "should not cause an exception when current_url is nil" do
68
+ allow_any_instance_of(Capybara::Session).to receive(:current_url) { nil }
69
+
70
+ expect{@session.assert_no_current_path('/with_html')}.not_to raise_error
71
+ end
59
72
  end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  Capybara::SpecHelper.spec '#assert_selector' do
2
3
  before do
3
4
  @session.visit('/with_html')
@@ -30,41 +31,41 @@ Capybara::SpecHelper.spec '#assert_selector' do
30
31
 
31
32
  context "with count" do
32
33
  it "should be true if the content is on the page the given number of times" do
33
- @session.assert_selector("//p", :count => 3)
34
- @session.assert_selector("//p//a[@id='foo']", :count => 1)
35
- @session.assert_selector("//p[contains(.,'est')]", :count => 1)
34
+ @session.assert_selector("//p", count: 3)
35
+ @session.assert_selector("//p//a[@id='foo']", count: 1)
36
+ @session.assert_selector("//p[contains(.,'est')]", count: 1)
36
37
  end
37
38
 
38
39
  it "should be false if the content is on the page the given number of times" do
39
- expect { @session.assert_selector("//p", :count => 6) }.to raise_error(Capybara::ElementNotFound)
40
- expect { @session.assert_selector("//p//a[@id='foo']", :count => 2) }.to raise_error(Capybara::ElementNotFound)
41
- expect { @session.assert_selector("//p[contains(.,'est')]", :count => 5) }.to raise_error(Capybara::ElementNotFound)
40
+ expect { @session.assert_selector("//p", count: 6) }.to raise_error(Capybara::ElementNotFound)
41
+ expect { @session.assert_selector("//p//a[@id='foo']", count: 2) }.to raise_error(Capybara::ElementNotFound)
42
+ expect { @session.assert_selector("//p[contains(.,'est')]", count: 5) }.to raise_error(Capybara::ElementNotFound)
42
43
  end
43
44
 
44
45
  it "should be false if the content isn't on the page at all" do
45
- expect { @session.assert_selector("//abbr", :count => 2) }.to raise_error(Capybara::ElementNotFound)
46
- expect { @session.assert_selector("//p//a[@id='doesnotexist']", :count => 1) }.to raise_error(Capybara::ElementNotFound)
46
+ expect { @session.assert_selector("//abbr", count: 2) }.to raise_error(Capybara::ElementNotFound)
47
+ expect { @session.assert_selector("//p//a[@id='doesnotexist']", count: 1) }.to raise_error(Capybara::ElementNotFound)
47
48
  end
48
49
  end
49
50
 
50
51
  context "with text" do
51
52
  it "should discard all matches where the given string is not contained" do
52
- @session.assert_selector("//p//a", :text => "Redirect", :count => 1)
53
- expect { @session.assert_selector("//p", :text => "Doesnotexist") }.to raise_error(Capybara::ElementNotFound)
53
+ @session.assert_selector("//p//a", text: "Redirect", count: 1)
54
+ expect { @session.assert_selector("//p", text: "Doesnotexist") }.to raise_error(Capybara::ElementNotFound)
54
55
  end
55
56
 
56
57
  it "should discard all matches where the given regexp is not matched" do
57
- @session.assert_selector("//p//a", :text => /re[dab]i/i, :count => 1)
58
- expect { @session.assert_selector("//p//a", :text => /Red$/) }.to raise_error(Capybara::ElementNotFound)
58
+ @session.assert_selector("//p//a", text: /re[dab]i/i, count: 1)
59
+ expect { @session.assert_selector("//p//a", text: /Red$/) }.to raise_error(Capybara::ElementNotFound)
59
60
  end
60
61
  end
61
62
 
62
- context "with wait", :requires => [:js] do
63
+ context "with wait", requires: [:js] do
63
64
  it "should find element if it appears before given wait duration" do
64
65
  Capybara.using_wait_time(0.1) do
65
66
  @session.visit('/with_js')
66
67
  @session.click_link('Click me')
67
- @session.assert_selector(:css, "a#has-been-clicked", :text => "Has been clicked", :wait => 0.9)
68
+ @session.assert_selector(:css, "a#has-been-clicked", text: "Has been clicked", wait: 2)
68
69
  end
69
70
  end
70
71
  end
@@ -108,40 +109,40 @@ Capybara::SpecHelper.spec '#assert_no_selector' do
108
109
 
109
110
  context "with count" do
110
111
  it "should be false if the content is on the page the given number of times" do
111
- expect { @session.assert_no_selector("//p", :count => 3) }.to raise_error(Capybara::ElementNotFound)
112
- expect { @session.assert_no_selector("//p//a[@id='foo']", :count => 1) }.to raise_error(Capybara::ElementNotFound)
113
- expect { @session.assert_no_selector("//p[contains(.,'est')]", :count => 1) }.to raise_error(Capybara::ElementNotFound)
112
+ expect { @session.assert_no_selector("//p", count: 3) }.to raise_error(Capybara::ElementNotFound)
113
+ expect { @session.assert_no_selector("//p//a[@id='foo']", count: 1) }.to raise_error(Capybara::ElementNotFound)
114
+ expect { @session.assert_no_selector("//p[contains(.,'est')]", count: 1) }.to raise_error(Capybara::ElementNotFound)
114
115
  end
115
116
 
116
117
  it "should be true if the content is on the page the wrong number of times" do
117
- @session.assert_no_selector("//p", :count => 6)
118
- @session.assert_no_selector("//p//a[@id='foo']", :count => 2)
119
- @session.assert_no_selector("//p[contains(.,'est')]", :count => 5)
118
+ @session.assert_no_selector("//p", count: 6)
119
+ @session.assert_no_selector("//p//a[@id='foo']", count: 2)
120
+ @session.assert_no_selector("//p[contains(.,'est')]", count: 5)
120
121
  end
121
122
 
122
123
  it "should be true if the content isn't on the page at all" do
123
- @session.assert_no_selector("//abbr", :count => 2)
124
- @session.assert_no_selector("//p//a[@id='doesnotexist']", :count => 1)
124
+ @session.assert_no_selector("//abbr", count: 2)
125
+ @session.assert_no_selector("//p//a[@id='doesnotexist']", count: 1)
125
126
  end
126
127
  end
127
128
 
128
129
  context "with text" do
129
130
  it "should discard all matches where the given string is contained" do
130
- expect { @session.assert_no_selector("//p//a", :text => "Redirect", :count => 1) }.to raise_error(Capybara::ElementNotFound)
131
- @session.assert_no_selector("//p", :text => "Doesnotexist")
131
+ expect { @session.assert_no_selector("//p//a", text: "Redirect", count: 1) }.to raise_error(Capybara::ElementNotFound)
132
+ @session.assert_no_selector("//p", text: "Doesnotexist")
132
133
  end
133
134
 
134
135
  it "should discard all matches where the given regexp is matched" do
135
- expect { @session.assert_no_selector("//p//a", :text => /re[dab]i/i, :count => 1) }.to raise_error(Capybara::ElementNotFound)
136
- @session.assert_no_selector("//p//a", :text => /Red$/)
136
+ expect { @session.assert_no_selector("//p//a", text: /re[dab]i/i, count: 1) }.to raise_error(Capybara::ElementNotFound)
137
+ @session.assert_no_selector("//p//a", text: /Red$/)
137
138
  end
138
139
  end
139
140
 
140
- context "with wait", :requires => [:js] do
141
+ context "with wait", requires: [:js] do
141
142
  it "should not find element if it appears after given wait duration" do
142
143
  @session.visit('/with_js')
143
144
  @session.click_link('Click me')
144
- @session.assert_no_selector(:css, "a#has-been-clicked", :text => "Has been clicked", :wait => 0.1)
145
+ @session.assert_no_selector(:css, "a#has-been-clicked", text: "Has been clicked", wait: 0.1)
145
146
  end
146
147
  end
147
148
  end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  Capybara::SpecHelper.spec '#assert_text' do
2
3
  it "should be true if the given text is on the page" do
3
4
  @session.visit('/with_html')
@@ -36,6 +37,36 @@ Capybara::SpecHelper.spec '#assert_text' do
36
37
  expect(@session.assert_text('Some of this text is hidden!')).to eq(true)
37
38
  end
38
39
 
40
+ it "should raise error with a helpful message if the requested text is present but invisible" do
41
+ @session.visit('/with_html')
42
+ el = @session.find(:css, '#hidden-text')
43
+ expect do
44
+ el.assert_text(:visible, 'Some of this text is hidden!')
45
+ end.to raise_error(Capybara::ExpectationNotMet, /it was found 1 time including non-visible text/)
46
+ end
47
+
48
+ it "should raise error with a helpful message if the requested text is present but with incorrect case" do
49
+ @session.visit('/with_html')
50
+ expect do
51
+ @session.assert_text('Text With Whitespace')
52
+ end.to raise_error(Capybara::ExpectationNotMet, /it was found 1 time using a case insensitive search/)
53
+ end
54
+
55
+ it "should raise error with helpful message if requested text is present but invisible and with incorrect case", requires: [:js] do
56
+ @session.visit('/with_html')
57
+ el = @session.find(:css, '#uppercase')
58
+ expect do
59
+ el.assert_text('text here')
60
+ end.to raise_error(Capybara::ExpectationNotMet, /it was found 1 time using a case insensitive search and it was found 1 time including non-visible text/)
61
+ end
62
+
63
+ it "should raise the correct error if requested text is missing but contains regex special characters" do
64
+ @session.visit('/with_html')
65
+ expect do
66
+ @session.assert_text('[]*.')
67
+ end.to raise_error(Capybara::ExpectationNotMet, /expected to find text "\[\]\*\."/)
68
+ end
69
+
39
70
  it "should be true if the text in the page matches given regexp" do
40
71
  @session.visit('/with_html')
41
72
  expect(@session.assert_text(/Lorem/)).to eq(true)
@@ -55,7 +86,7 @@ Capybara::SpecHelper.spec '#assert_text' do
55
86
  end.to raise_error(Capybara::ExpectationNotMet)
56
87
  end
57
88
 
58
- it "should wait for text to appear", :requires => [:js] do
89
+ it "should wait for text to appear", requires: [:js] do
59
90
  @session.visit('/with_js')
60
91
  @session.click_link('Click me')
61
92
  expect(@session.assert_text('Has been clicked')).to eq(true)
@@ -75,7 +106,7 @@ Capybara::SpecHelper.spec '#assert_text' do
75
106
  end
76
107
  end
77
108
 
78
- context "with wait", :requires => [:js] do
109
+ context "with wait", requires: [:js] do
79
110
  it "should find element if it appears before given wait duration" do
80
111
  Capybara.using_wait_time(0) do
81
112
  @session.visit('/with_js')
@@ -102,35 +133,35 @@ Capybara::SpecHelper.spec '#assert_text' do
102
133
  end
103
134
 
104
135
  it 'ignores other filters when :count is specified' do
105
- o = {:count => 5,
106
- :minimum => 6,
107
- :maximum => 0,
108
- :between => 0..4}
136
+ o = {count: 5,
137
+ minimum: 6,
138
+ maximum: 0,
139
+ between: 0..4}
109
140
  expect { @session.assert_text('Header', o) }.not_to raise_error
110
141
  end
111
142
  context 'with no :count expectation' do
112
143
  it 'fails if :minimum is not met' do
113
- o = {:minimum => 6,
114
- :maximum => 5,
115
- :between => 2..7}
144
+ o = {minimum: 6,
145
+ maximum: 5,
146
+ between: 2..7}
116
147
  expect { @session.assert_text('Header', o) }.to raise_error(Capybara::ExpectationNotMet)
117
148
  end
118
149
  it 'fails if :maximum is not met' do
119
- o = {:minimum => 0,
120
- :maximum => 0,
121
- :between => 2..7}
150
+ o = {minimum: 0,
151
+ maximum: 0,
152
+ between: 2..7}
122
153
  expect { @session.assert_text('Header', o) }.to raise_error(Capybara::ExpectationNotMet)
123
154
  end
124
155
  it 'fails if :between is not met' do
125
- o = {:minimum => 0,
126
- :maximum => 5,
127
- :between => 0..4}
156
+ o = {minimum: 0,
157
+ maximum: 5,
158
+ between: 0..4}
128
159
  expect { @session.assert_text('Header', o) }.to raise_error(Capybara::ExpectationNotMet)
129
160
  end
130
161
  it 'succeeds if all combineable expectations are met' do
131
- o = {:minimum => 0,
132
- :maximum => 5,
133
- :between => 2..7}
162
+ o = {minimum: 0,
163
+ maximum: 5,
164
+ between: 2..7}
134
165
  expect { @session.assert_text('Header', o) }.not_to raise_error
135
166
  end
136
167
  end
@@ -165,6 +196,14 @@ Capybara::SpecHelper.spec '#assert_no_text' do
165
196
  end.to raise_error(Capybara::ExpectationNotMet, 'expected not to find text "Some of this text is hidden!" in "Some of this text is hidden!"')
166
197
  end
167
198
 
199
+ it "should raise error if :all given and text is invisible." do
200
+ @session.visit('/with_html')
201
+ el = @session.find(:css, '#some-hidden-text', visible: false)
202
+ expect do
203
+ el.assert_no_text(:visible, 'hidden')
204
+ end.to raise_error(Capybara::ExpectationNotMet, 'expected not to find text "hidden" in "Some of this text is not hidden"')
205
+ end
206
+
168
207
  it "should be true if the text in the page doesn't match given regexp" do
169
208
  @session.visit('/with_html')
170
209
  @session.assert_no_text(/xxxxyzzz/)
@@ -184,12 +223,12 @@ Capybara::SpecHelper.spec '#assert_no_text' do
184
223
  end
185
224
  end
186
225
 
187
- context "with wait", :requires => [:js] do
226
+ context "with wait", requires: [:js] do
188
227
  it "should not find element if it appears after given wait duration" do
189
228
  @session.visit('/with_js')
190
229
  @session.click_link('Click me')
191
230
  @session.find(:css, '#reload-list').click
192
- @session.find(:css, '#the-list').assert_no_text('Foo Bar', :wait => 0.3)
231
+ @session.find(:css, '#the-list').assert_no_text('Foo Bar', wait: 0.3)
193
232
  end
194
233
  end
195
234
  end
@@ -1,26 +1,36 @@
1
+ # frozen_string_literal: true
1
2
  Capybara::SpecHelper.spec '#assert_title' do
2
3
  before do
3
4
  @session.visit('/with_js')
4
5
  end
5
6
 
6
- it "should be true if the page's title contains the given string" do
7
- expect(@session.assert_title('js')).to eq(true)
7
+ it "should not raise if the page's title contains the given string" do
8
+ expect do
9
+ @session.assert_title('js')
10
+ end.not_to raise_error
8
11
  end
9
12
 
10
- it "should be true when given an empty string" do
11
- expect(@session.assert_title('')).to eq(true)
13
+ it "should not raise when given an empty string" do
14
+ expect do
15
+ @session.assert_title('')
16
+ end.not_to raise_error
12
17
  end
13
18
 
14
19
  it "should allow regexp matches" do
15
- expect(@session.assert_title(/w[a-z]{3}_js/)).to eq(true)
20
+ expect do
21
+ @session.assert_title(/w[a-z]{3}_js/)
22
+ end.not_to raise_error
23
+
16
24
  expect do
17
25
  @session.assert_title(/w[a-z]{10}_js/)
18
26
  end.to raise_error(Capybara::ExpectationNotMet, 'expected "with_js" to match /w[a-z]{10}_js/')
19
27
  end
20
28
 
21
- it "should wait for title", :requires => [:js] do
29
+ it "should wait for title", requires: [:js] do
22
30
  @session.click_link("Change title")
23
- expect(@session.assert_title("changed title")).to eq(true)
31
+ expect do
32
+ @session.assert_title("changed title", wait: 3)
33
+ end.not_to raise_error
24
34
  end
25
35
 
26
36
  it "should raise error if the title doesn't contain the given string" do
@@ -58,12 +68,16 @@ Capybara::SpecHelper.spec '#assert_no_title' do
58
68
  @session.assert_no_title(/monkey/)
59
69
  end
60
70
 
61
- it "should wait for title to disappear", :requires => [:js] do
71
+ it "should wait for title to disappear", requires: [:js] do
62
72
  @session.click_link("Change title")
63
- expect(@session.assert_no_title('with_js')).to eq(true)
73
+ expect do
74
+ @session.assert_no_title('with_js', wait: 3)
75
+ end.not_to raise_error
64
76
  end
65
77
 
66
- it "should be true if the title doesn't contain the given string" do
67
- expect(@session.assert_no_title('monkey')).to eq(true)
78
+ it "should not raise if the title doesn't contain the given string" do
79
+ expect do
80
+ @session.assert_no_title('monkey')
81
+ end.not_to raise_error
68
82
  end
69
83
  end
@@ -1,8 +1,10 @@
1
+ # frozen_string_literal: true
1
2
  Capybara::SpecHelper.spec "#attach_file" do
2
3
  before do
3
4
  @test_file_path = File.expand_path('../fixtures/test_file.txt', File.dirname(__FILE__))
4
5
  @another_test_file_path = File.expand_path('../fixtures/another_test_file.txt', File.dirname(__FILE__))
5
6
  @test_jpg_file_path = File.expand_path('../fixtures/capybara.jpg', File.dirname(__FILE__))
7
+ @no_extension_file_path = File.expand_path('../fixtures/no_extension', File.dirname(__FILE__))
6
8
  @session.visit('/form')
7
9
  end
8
10
 
@@ -56,6 +58,12 @@ Capybara::SpecHelper.spec "#attach_file" do
56
58
  expect(@session).to have_content('image/jpeg')
57
59
  end
58
60
 
61
+ it "should not break when uploading a file without extension" do
62
+ @session.attach_file "Single Document", @no_extension_file_path
63
+ @session.click_button 'Upload Single'
64
+ expect(@session).to have_content(File.read(@no_extension_file_path))
65
+ end
66
+
59
67
  it "should not break when using HTML5 multiple file input" do
60
68
  @session.attach_file "Multiple Documents", @test_file_path
61
69
  @session.click_button('Upload Multiple')
@@ -64,7 +72,7 @@ Capybara::SpecHelper.spec "#attach_file" do
64
72
  end
65
73
 
66
74
  it "should not break when using HTML5 multiple file input uploading multiple files" do
67
- pending "Selenium is buggy on this, see http://code.google.com/p/selenium/issues/detail?id=2239" if @session.respond_to?(:mode) && @session.mode.to_s =~ /^selenium/
75
+ pending "Selenium is buggy on this, see http://code.google.com/p/selenium/issues/detail?id=2239" if @session.respond_to?(:mode) && @session.mode.to_s =~ /^selenium_(firefox|marionette)/
68
76
  @session.attach_file "Multiple Documents", [@test_file_path, @another_test_file_path]
69
77
  @session.click_button('Upload Multiple')
70
78
  expect(@session.body).to include("2 | ")#number of files
@@ -80,7 +88,7 @@ Capybara::SpecHelper.spec "#attach_file" do
80
88
 
81
89
  context "with a locator that doesn't exist" do
82
90
  it "should raise an error" do
83
- msg = "Unable to find file field \"does not exist\""
91
+ msg = "Unable to find visible file field \"does not exist\" that is not disabled"
84
92
  expect do
85
93
  @session.attach_file('does not exist', @test_file_path)
86
94
  end.to raise_error(Capybara::ElementNotFound, msg)
@@ -95,15 +103,45 @@ Capybara::SpecHelper.spec "#attach_file" do
95
103
 
96
104
  context "with :exact option" do
97
105
  it "should set a file path by partial label when false" do
98
- @session.attach_file "Imag", __FILE__, :exact => false
106
+ @session.attach_file "Imag", __FILE__, exact: false
99
107
  @session.click_button('awesome')
100
108
  expect(extract_results(@session)['image']).to eq(File.basename(__FILE__))
101
109
  end
102
110
 
103
111
  it "not allow partial matches when true" do
104
112
  expect do
105
- @session.attach_file "Imag", __FILE__, :exact => true
113
+ @session.attach_file "Imag", __FILE__, exact: true
106
114
  end.to raise_error(Capybara::ElementNotFound)
107
115
  end
108
116
  end
117
+
118
+ context "with :make_visible option", requires: [:js, :es_args] do
119
+ it "applies a default style change when true" do
120
+ @session.visit('/with_js')
121
+ expect { @session.attach_file("hidden_file", __FILE__) }.to raise_error Capybara::ElementNotFound
122
+ expect {
123
+ @session.attach_file("hidden_file", __FILE__, make_visible: true)
124
+ }.not_to raise_error
125
+ end
126
+
127
+ it "accepts a hash of styles to be applied" do
128
+ @session.visit('/with_js')
129
+ expect {
130
+ @session.attach_file("hidden_file", __FILE__, make_visible: { opacity: 1, display: 'block' })
131
+ }.not_to raise_error
132
+ end
133
+
134
+ it "raises an error when the file input is not made visible" do
135
+ @session.visit('/with_js')
136
+ expect {
137
+ @session.attach_file("hidden_file", __FILE__, make_visible: { color: 'red' })
138
+ }.to raise_error(Capybara::ExpectationNotMet)
139
+ end
140
+
141
+ it "resets the style when done" do
142
+ @session.visit('/with_js')
143
+ @session.attach_file("hidden_file", __FILE__, make_visible: true)
144
+ expect(@session.evaluate_script("arguments[0].style.display", @session.find(:css, '#hidden_file', visible: :all))).to eq 'none'
145
+ end
146
+ end
109
147
  end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  Capybara::SpecHelper.spec '#body' do
2
3
  it "should return the unmodified page body" do
3
4
  @session.visit('/')
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  Capybara::SpecHelper.spec "#check" do
2
3
  before do
3
4
  @session.visit('/form')
@@ -14,7 +15,7 @@ Capybara::SpecHelper.spec "#check" do
14
15
  end
15
16
  end
16
17
 
17
- it "should trigger associated events", :requires => [:js] do
18
+ it "should trigger associated events", requires: [:js] do
18
19
  @session.visit('/with_js')
19
20
  @session.check('checkbox_with_event')
20
21
  expect(@session).to have_css('#checkbox_event_triggered');
@@ -22,29 +23,29 @@ Capybara::SpecHelper.spec "#check" do
22
23
 
23
24
  describe "checking" do
24
25
  it "should not change an already checked checkbox" do
25
- expect(@session.find(:xpath, "//input[@id='form_pets_dog']")['checked']).to be_truthy
26
+ expect(@session.find(:xpath, "//input[@id='form_pets_dog']")).to be_checked
26
27
  @session.check('form_pets_dog')
27
- expect(@session.find(:xpath, "//input[@id='form_pets_dog']")['checked']).to be_truthy
28
+ expect(@session.find(:xpath, "//input[@id='form_pets_dog']")).to be_checked
28
29
  end
29
30
 
30
31
  it "should check an unchecked checkbox" do
31
- expect(@session.find(:xpath, "//input[@id='form_pets_cat']")['checked']).to be_falsey
32
+ expect(@session.find(:xpath, "//input[@id='form_pets_cat']")).not_to be_checked
32
33
  @session.check('form_pets_cat')
33
- expect(@session.find(:xpath, "//input[@id='form_pets_cat']")['checked']).to be_truthy
34
+ expect(@session.find(:xpath, "//input[@id='form_pets_cat']")).to be_checked
34
35
  end
35
36
  end
36
37
 
37
38
  describe "unchecking" do
38
39
  it "should not change an already unchecked checkbox" do
39
- expect(@session.find(:xpath, "//input[@id='form_pets_cat']")['checked']).to be_falsey
40
+ expect(@session.find(:xpath, "//input[@id='form_pets_cat']")).not_to be_checked
40
41
  @session.uncheck('form_pets_cat')
41
- expect(@session.find(:xpath, "//input[@id='form_pets_cat']")['checked']).to be_falsey
42
+ expect(@session.find(:xpath, "//input[@id='form_pets_cat']")).not_to be_checked
42
43
  end
43
44
 
44
45
  it "should uncheck a checked checkbox" do
45
- expect(@session.find(:xpath, "//input[@id='form_pets_dog']")['checked']).to be_truthy
46
+ expect(@session.find(:xpath, "//input[@id='form_pets_dog']")).to be_checked
46
47
  @session.uncheck('form_pets_dog')
47
- expect(@session.find(:xpath, "//input[@id='form_pets_dog']")['checked']).to be_falsey
48
+ expect(@session.find(:xpath, "//input[@id='form_pets_dog']")).not_to be_checked
48
49
  end
49
50
  end
50
51
 
@@ -68,7 +69,7 @@ Capybara::SpecHelper.spec "#check" do
68
69
 
69
70
  context "with a locator that doesn't exist" do
70
71
  it "should raise an error" do
71
- msg = "Unable to find checkbox \"does not exist\""
72
+ msg = "Unable to find visible checkbox \"does not exist\" that is not disabled"
72
73
  expect do
73
74
  @session.check('does not exist')
74
75
  end.to raise_error(Capybara::ElementNotFound, msg)
@@ -85,29 +86,104 @@ Capybara::SpecHelper.spec "#check" do
85
86
 
86
87
  context "with :exact option" do
87
88
  it "should accept partial matches when false" do
88
- @session.check('Ham', :exact => false)
89
+ @session.check('Ham', exact: false)
89
90
  @session.click_button('awesome')
90
91
  expect(extract_results(@session)['pets']).to include('hamster')
91
92
  end
92
93
 
93
94
  it "should not accept partial matches when true" do
94
95
  expect do
95
- @session.check('Ham', :exact => true)
96
+ @session.check('Ham', exact: true)
96
97
  end.to raise_error(Capybara::ElementNotFound)
97
98
  end
98
99
  end
99
100
 
100
101
  context "with `option` option" do
101
102
  it "can check boxes by their value" do
102
- @session.check('form[pets][]', :option => "cat")
103
+ @session.check('form[pets][]', option: "cat")
103
104
  @session.click_button('awesome')
104
105
  expect(extract_results(@session)['pets']).to include('cat')
105
106
  end
106
107
 
107
108
  it "should raise an error if option not found" do
108
109
  expect do
109
- @session.check('form[pets][]', :option => "elephant")
110
+ @session.check('form[pets][]', option: "elephant")
110
111
  end.to raise_error(Capybara::ElementNotFound)
111
112
  end
112
113
  end
114
+
115
+ context "when checkbox hidden" do
116
+ context "with Capybara.automatic_label_click == true" do
117
+ around do |spec|
118
+ old_click_label, Capybara.automatic_label_click = Capybara.automatic_label_click, true
119
+ spec.run
120
+ Capybara.automatic_label_click = old_click_label
121
+ end
122
+
123
+ it "should check via clicking the label with :for attribute if possible" do
124
+ expect(@session.find(:checkbox, 'form_cars_tesla', unchecked: true, visible: :hidden)).to be
125
+ @session.check('form_cars_tesla')
126
+ @session.click_button('awesome')
127
+ expect(extract_results(@session)['cars']).to include('tesla')
128
+ end
129
+
130
+ it "should check via clicking the wrapping label if possible" do
131
+ expect(@session.find(:checkbox, 'form_cars_mclaren', unchecked: true, visible: :hidden)).to be
132
+ @session.check('form_cars_mclaren')
133
+ @session.click_button('awesome')
134
+ expect(extract_results(@session)['cars']).to include('mclaren')
135
+ end
136
+
137
+ it "should not click the label if unneeded" do
138
+ expect(@session.find(:checkbox, 'form_cars_jaguar', checked: true, visible: :hidden)).to be
139
+ @session.check('form_cars_jaguar')
140
+ @session.click_button('awesome')
141
+ expect(extract_results(@session)['cars']).to include('jaguar')
142
+ end
143
+
144
+ it "should raise original error when no label available" do
145
+ expect { @session.check('form_cars_ariel') }.to raise_error(Capybara::ElementNotFound, 'Unable to find visible checkbox "form_cars_ariel" that is not disabled')
146
+ end
147
+
148
+ it "should raise error if not allowed to click label" do
149
+ expect{@session.check('form_cars_mclaren', allow_label_click: false)}.to raise_error(Capybara::ElementNotFound, 'Unable to find visible checkbox "form_cars_mclaren" that is not disabled')
150
+ end
151
+ end
152
+
153
+ context "with Capybara.automatic_label_click == false" do
154
+ around do |spec|
155
+ old_label_click, Capybara.automatic_label_click = Capybara.automatic_label_click, false
156
+ spec.run
157
+ Capybara.automatic_label_click = old_label_click
158
+ end
159
+
160
+ it "should raise error if checkbox not visible" do
161
+ expect{@session.check('form_cars_mclaren')}.to raise_error(Capybara::ElementNotFound, 'Unable to find visible checkbox "form_cars_mclaren" that is not disabled')
162
+ end
163
+
164
+ context "with allow_label_click == true" do
165
+ it "should check via the label if input is hidden" do
166
+ expect(@session.find(:checkbox, 'form_cars_tesla', unchecked: true, visible: :hidden)).to be
167
+ @session.check('form_cars_tesla', allow_label_click: true)
168
+ @session.click_button('awesome')
169
+ expect(extract_results(@session)['cars']).to include('tesla')
170
+ end
171
+
172
+ it "should not wait the full time if label can be clicked" do
173
+ expect(@session.find(:checkbox, 'form_cars_tesla', unchecked: true, visible: :hidden)).to be
174
+ start_time = Time.now
175
+ @session.check('form_cars_tesla', allow_label_click: true, wait: 10)
176
+ end_time = Time.now
177
+ expect(end_time - start_time).to be < 10
178
+ end
179
+
180
+ it "should check via the label if input is moved off the left edge of the page" do
181
+ expect(@session.find(:checkbox, 'form_cars_pagani', unchecked: true, visible: :all)).to be
182
+ @session.check('form_cars_pagani', allow_label_click: true)
183
+ @session.click_button('awesome')
184
+ expect(extract_results(@session)['cars']).to include('pagani')
185
+ end
186
+ end
187
+ end
188
+ end
113
189
  end