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,14 +1,17 @@
1
+ # frozen_string_literal: true
1
2
  require 'spec_helper'
2
3
  require 'capybara/dsl'
3
4
  require 'capybara/rspec/matchers'
5
+ require 'benchmark'
6
+
7
+ RSpec.shared_examples Capybara::RSpecMatchers do |session, mode|
4
8
 
5
- RSpec.describe Capybara::RSpecMatchers do
6
9
  include Capybara::DSL
7
10
  include Capybara::RSpecMatchers
8
11
 
9
12
  describe "have_css matcher" do
10
13
  it "gives proper description" do
11
- expect(have_css('h1').description).to eq("have css \"h1\"")
14
+ expect(have_css('h1').description).to eq("have visible css \"h1\"")
12
15
  end
13
16
 
14
17
  context "on a string" do
@@ -20,35 +23,35 @@ RSpec.describe Capybara::RSpecMatchers do
20
23
  it "fails if has_css? returns false" do
21
24
  expect do
22
25
  expect("<h1>Text</h1>").to have_css('h2')
23
- end.to raise_error(/expected to find css "h2" but there were no matches/)
26
+ end.to raise_error(/expected to find visible css "h2" but there were no matches/)
24
27
  end
25
28
 
26
29
  it "passes if matched node count equals expected count" do
27
- expect("<h1>Text</h1>").to have_css('h1', :count => 1)
30
+ expect("<h1>Text</h1>").to have_css('h1', count: 1)
28
31
  end
29
32
 
30
33
  it "fails if matched node count does not equal expected count" do
31
34
  expect do
32
35
  expect("<h1>Text</h1>").to have_css('h1', count: 2)
33
- end.to raise_error("expected to find css \"h1\" 2 times, found 1 match: \"Text\"")
36
+ end.to raise_error("expected to find visible css \"h1\" 2 times, found 1 match: \"Text\"")
34
37
  end
35
38
 
36
39
  it "fails if matched node count is less than expected minimum count" do
37
40
  expect do
38
41
  expect("<h1>Text</h1>").to have_css('p', minimum: 1)
39
- end.to raise_error("expected to find css \"p\" at least 1 time but there were no matches")
42
+ end.to raise_error("expected to find visible css \"p\" at least 1 time but there were no matches")
40
43
  end
41
44
 
42
45
  it "fails if matched node count is more than expected maximum count" do
43
46
  expect do
44
47
  expect("<h1>Text</h1><h1>Text</h1><h1>Text</h1>").to have_css('h1', maximum: 2)
45
- end.to raise_error('expected to find css "h1" at most 2 times, found 3 matches: "Text", "Text", "Text"')
48
+ end.to raise_error('expected to find visible css "h1" at most 2 times, found 3 matches: "Text", "Text", "Text"')
46
49
  end
47
50
 
48
51
  it "fails if matched node count does not belong to expected range" do
49
52
  expect do
50
53
  expect("<h1>Text</h1>").to have_css('h1', between: 2..3)
51
- end.to raise_error("expected to find css \"h1\" between 2 and 3 times, found 1 match: \"Text\"")
54
+ end.to raise_error("expected to find visible css \"h1\" between 2 and 3 times, found 1 match: \"Text\"")
52
55
  end
53
56
 
54
57
  end
@@ -61,17 +64,17 @@ RSpec.describe Capybara::RSpecMatchers do
61
64
  it "fails if has_no_css? returns false" do
62
65
  expect do
63
66
  expect("<h1>Text</h1>").not_to have_css('h1')
64
- end.to raise_error(/expected not to find css "h1"/)
67
+ end.to raise_error(/expected not to find visible css "h1"/)
65
68
  end
66
69
 
67
70
  it "passes if matched node count does not equal expected count" do
68
- expect("<h1>Text</h1>").not_to have_css('h1', :count => 2)
71
+ expect("<h1>Text</h1>").not_to have_css('h1', count: 2)
69
72
  end
70
73
 
71
74
  it "fails if matched node count equals expected count" do
72
75
  expect do
73
- expect("<h1>Text</h1>").not_to have_css('h1', :count => 1)
74
- end.to raise_error(/expected not to find css "h1"/)
76
+ expect("<h1>Text</h1>").not_to have_css('h1', count: 1)
77
+ end.to raise_error(/expected not to find visible css "h1"/)
75
78
  end
76
79
  end
77
80
 
@@ -94,7 +97,7 @@ RSpec.describe Capybara::RSpecMatchers do
94
97
  it "fails if has_css? returns false" do
95
98
  expect do
96
99
  expect(page).to have_css('h1#doesnotexist')
97
- end.to raise_error(/expected to find css "h1#doesnotexist" but there were no matches/)
100
+ end.to raise_error(/expected to find visible css "h1#doesnotexist" but there were no matches/)
98
101
  end
99
102
  end
100
103
 
@@ -106,7 +109,7 @@ RSpec.describe Capybara::RSpecMatchers do
106
109
  it "fails if has_no_css? returns false" do
107
110
  expect do
108
111
  expect(page).not_to have_css('h1')
109
- end.to raise_error(/expected not to find css "h1"/)
112
+ end.to raise_error(/expected not to find visible css "h1"/)
110
113
  end
111
114
  end
112
115
  end
@@ -114,7 +117,7 @@ RSpec.describe Capybara::RSpecMatchers do
114
117
 
115
118
  describe "have_xpath matcher" do
116
119
  it "gives proper description" do
117
- expect(have_xpath('//h1').description).to eq("have xpath \"\/\/h1\"")
120
+ expect(have_xpath('//h1').description).to eq("have visible xpath \"\/\/h1\"")
118
121
  end
119
122
 
120
123
  context "on a string" do
@@ -126,7 +129,7 @@ RSpec.describe Capybara::RSpecMatchers do
126
129
  it "fails if has_xpath? returns false" do
127
130
  expect do
128
131
  expect("<h1>Text</h1>").to have_xpath('//h2')
129
- end.to raise_error(%r(expected to find xpath "//h2" but there were no matches))
132
+ end.to raise_error(%r(expected to find visible xpath "//h2" but there were no matches))
130
133
  end
131
134
  end
132
135
 
@@ -138,7 +141,7 @@ RSpec.describe Capybara::RSpecMatchers do
138
141
  it "fails if has_no_xpath? returns false" do
139
142
  expect do
140
143
  expect("<h1>Text</h1>").not_to have_xpath('//h1')
141
- end.to raise_error(%r(expected not to find xpath "//h1"))
144
+ end.to raise_error(%r(expected not to find visible xpath "//h1"))
142
145
  end
143
146
  end
144
147
 
@@ -161,7 +164,7 @@ RSpec.describe Capybara::RSpecMatchers do
161
164
  it "fails if has_xpath? returns false" do
162
165
  expect do
163
166
  expect(page).to have_xpath("//h1[@id='doesnotexist']")
164
- end.to raise_error(%r(expected to find xpath "//h1\[@id='doesnotexist'\]" but there were no matches))
167
+ end.to raise_error(%r(expected to find visible xpath "//h1\[@id='doesnotexist'\]" but there were no matches))
165
168
  end
166
169
  end
167
170
 
@@ -173,7 +176,7 @@ RSpec.describe Capybara::RSpecMatchers do
173
176
  it "fails if has_no_xpath? returns false" do
174
177
  expect do
175
178
  expect(page).not_to have_xpath('//h1')
176
- end.to raise_error(%r(expected not to find xpath "//h1"))
179
+ end.to raise_error(%r(expected not to find visible xpath "//h1"))
177
180
  end
178
181
  end
179
182
  end
@@ -183,7 +186,7 @@ RSpec.describe Capybara::RSpecMatchers do
183
186
  it "gives proper description" do
184
187
  matcher = have_selector('//h1')
185
188
  expect("<h1>Text</h1>").to matcher
186
- expect(matcher.description).to eq("have xpath \"//h1\"")
189
+ expect(matcher.description).to eq("have visible xpath \"//h1\"")
187
190
  end
188
191
 
189
192
  context "on a string" do
@@ -195,7 +198,7 @@ RSpec.describe Capybara::RSpecMatchers do
195
198
  it "fails if has_selector? returns false" do
196
199
  expect do
197
200
  expect("<h1>Text</h1>").to have_selector('//h2')
198
- end.to raise_error(%r(expected to find xpath "//h2" but there were no matches))
201
+ end.to raise_error(%r(expected to find visible xpath "//h2" but there were no matches))
199
202
  end
200
203
  end
201
204
 
@@ -207,7 +210,7 @@ RSpec.describe Capybara::RSpecMatchers do
207
210
  it "fails if has_no_selector? returns false" do
208
211
  expect do
209
212
  expect("<h1>Text</h1>").not_to have_selector(:css, 'h1')
210
- end.to raise_error(%r(expected not to find css "h1"))
213
+ end.to raise_error(%r(expected not to find visible css "h1"))
211
214
  end
212
215
  end
213
216
  end
@@ -219,19 +222,19 @@ RSpec.describe Capybara::RSpecMatchers do
219
222
 
220
223
  context "with should" do
221
224
  it "passes if has_selector? returns true" do
222
- expect(page).to have_selector('//h1', :text => 'test')
225
+ expect(page).to have_selector('//h1', text: 'test')
223
226
  end
224
227
 
225
228
  it "fails if has_selector? returns false" do
226
229
  expect do
227
230
  expect(page).to have_selector("//h1[@id='doesnotexist']")
228
- end.to raise_error(%r(expected to find xpath "//h1\[@id='doesnotexist'\]" but there were no matches))
231
+ end.to raise_error(%r(expected to find visible xpath "//h1\[@id='doesnotexist'\]" but there were no matches))
229
232
  end
230
233
 
231
234
  it "includes text in error message" do
232
235
  expect do
233
- expect(page).to have_selector("//h1", :text => 'wrong text')
234
- end.to raise_error(%r(expected to find xpath "//h1" with text "wrong text" but there were no matches))
236
+ expect(page).to have_selector("//h1", text: 'wrong text')
237
+ end.to raise_error(%r(expected to find visible xpath "//h1" with text "wrong text" but there were no matches))
235
238
  end
236
239
  end
237
240
 
@@ -242,8 +245,8 @@ RSpec.describe Capybara::RSpecMatchers do
242
245
 
243
246
  it "fails if has_no_selector? returns false" do
244
247
  expect do
245
- expect(page).not_to have_selector(:css, 'h1', :text => 'test')
246
- end.to raise_error(%r(expected not to find css "h1" with text "test"))
248
+ expect(page).not_to have_selector(:css, 'h1', text: 'test')
249
+ end.to raise_error(%r(expected not to find visible css "h1" with text "test"))
247
250
  end
248
251
  end
249
252
  end
@@ -370,7 +373,7 @@ RSpec.describe Capybara::RSpecMatchers do
370
373
  end.to raise_error('expected to find text matching /No such Text/ in "Text"')
371
374
  end
372
375
 
373
- it "casts Fixnum to string" do
376
+ it "casts Integer to string" do
374
377
  expect do
375
378
  expect("<h1>Text</h1>").to have_text(3)
376
379
  end.to raise_error(/expected to find text "3" in "Text"/)
@@ -481,7 +484,7 @@ RSpec.describe Capybara::RSpecMatchers do
481
484
  let(:html) { '<a href="#">Just a link</a><a href="#">Another link</a>' }
482
485
 
483
486
  it "gives proper description" do
484
- expect(have_link('Just a link').description).to eq("have link \"Just a link\"")
487
+ expect(have_link('Just a link').description).to eq("have visible link \"Just a link\"")
485
488
  end
486
489
 
487
490
  it "passes if there is such a button" do
@@ -491,7 +494,7 @@ RSpec.describe Capybara::RSpecMatchers do
491
494
  it "fails if there is no such button" do
492
495
  expect do
493
496
  expect(html).to have_link('No such Link')
494
- end.to raise_error(/expected to find link "No such Link"/)
497
+ end.to raise_error(/expected to find visible link "No such Link"/)
495
498
  end
496
499
 
497
500
  it "supports compounding" do
@@ -540,7 +543,7 @@ RSpec.describe Capybara::RSpecMatchers do
540
543
 
541
544
  context 'with wait' do
542
545
  before(:each) do
543
- @session = TestSessions::Selenium
546
+ @session = session
544
547
  @session.visit('/with_js')
545
548
  end
546
549
 
@@ -553,8 +556,8 @@ RSpec.describe Capybara::RSpecMatchers do
553
556
 
554
557
  it "doesn't wait if wait time is less than timeout" do
555
558
  @session.click_link("Change title")
556
- using_wait_time 0 do
557
- expect(@session).not_to have_title('changed title')
559
+ using_wait_time 3 do
560
+ expect(@session).not_to have_title('changed title', wait: 0)
558
561
  end
559
562
  end
560
563
  end
@@ -585,7 +588,7 @@ RSpec.describe Capybara::RSpecMatchers do
585
588
 
586
589
  context 'with wait' do
587
590
  before(:each) do
588
- @session = TestSessions::Selenium
591
+ @session = session
589
592
  @session.visit('/with_js')
590
593
  end
591
594
 
@@ -615,7 +618,7 @@ RSpec.describe Capybara::RSpecMatchers do
615
618
  let(:html) { '<button>A button</button><input type="submit" value="Another button"/>' }
616
619
 
617
620
  it "gives proper description" do
618
- expect(have_button('A button').description).to eq("have button \"A button\"")
621
+ expect(have_button('A button').description).to eq("have visible button \"A button\"")
619
622
  end
620
623
 
621
624
  it "passes if there is such a button" do
@@ -625,7 +628,7 @@ RSpec.describe Capybara::RSpecMatchers do
625
628
  it "fails if there is no such button" do
626
629
  expect do
627
630
  expect(html).to have_button('No such Button')
628
- end.to raise_error(/expected to find button "No such Button"/)
631
+ end.to raise_error(/expected to find visible button "No such Button"/)
629
632
  end
630
633
 
631
634
  it "supports compounding" do
@@ -637,11 +640,11 @@ RSpec.describe Capybara::RSpecMatchers do
637
640
  let(:html) { '<p><label>Text field<input type="text" value="some value"/></label></p>' }
638
641
 
639
642
  it "gives proper description" do
640
- expect(have_field('Text field').description).to eq("have field \"Text field\"")
643
+ expect(have_field('Text field').description).to eq("have visible field \"Text field\" that is not disabled")
641
644
  end
642
645
 
643
646
  it "gives proper description for a given value" do
644
- expect(have_field('Text field', with: 'some value').description).to eq("have field \"Text field\" with value \"some value\"")
647
+ expect(have_field('Text field', with: 'some value').description).to eq("have visible field \"Text field\" that is not disabled with value \"some value\"")
645
648
  end
646
649
 
647
650
  it "passes if there is such a field" do
@@ -655,13 +658,13 @@ RSpec.describe Capybara::RSpecMatchers do
655
658
  it "fails if there is no such field" do
656
659
  expect do
657
660
  expect(html).to have_field('No such Field')
658
- end.to raise_error(/expected to find field "No such Field"/)
661
+ end.to raise_error(/expected to find visible field "No such Field"/)
659
662
  end
660
663
 
661
664
  it "fails if there is such field but with false value" do
662
665
  expect do
663
666
  expect(html).to have_field('Text field', with: 'false value')
664
- end.to raise_error(/expected to find field "Text field"/)
667
+ end.to raise_error(/expected to find visible field "Text field"/)
665
668
  end
666
669
 
667
670
  it "treats a given value as a string" do
@@ -685,7 +688,7 @@ RSpec.describe Capybara::RSpecMatchers do
685
688
  end
686
689
 
687
690
  it "gives proper description" do
688
- expect(have_checked_field('it is checked').description).to eq("have field \"it is checked\" that is checked")
691
+ expect(have_checked_field('it is checked').description).to eq("have visible field \"it is checked\" that is checked and not disabled")
689
692
  end
690
693
 
691
694
  context "with should" do
@@ -696,13 +699,13 @@ RSpec.describe Capybara::RSpecMatchers do
696
699
  it "fails if there is such a field but it is not checked" do
697
700
  expect do
698
701
  expect(html).to have_checked_field('unchecked field')
699
- end.to raise_error(/expected to find field "unchecked field"/)
702
+ end.to raise_error(/expected to find visible field "unchecked field"/)
700
703
  end
701
704
 
702
705
  it "fails if there is no such field" do
703
706
  expect do
704
707
  expect(html).to have_checked_field('no such field')
705
- end.to raise_error(/expected to find field "no such field"/)
708
+ end.to raise_error(/expected to find visible field "no such field"/)
706
709
  end
707
710
  end
708
711
 
@@ -710,7 +713,7 @@ RSpec.describe Capybara::RSpecMatchers do
710
713
  it "fails if there is such a field and it is checked" do
711
714
  expect do
712
715
  expect(html).not_to have_checked_field('it is checked')
713
- end.to raise_error(/expected not to find field "it is checked"/)
716
+ end.to raise_error(/expected not to find visible field "it is checked"/)
714
717
  end
715
718
 
716
719
  it "passes if there is such a field but it is not checked" do
@@ -734,7 +737,7 @@ RSpec.describe Capybara::RSpecMatchers do
734
737
  end
735
738
 
736
739
  it "gives proper description" do
737
- expect(have_unchecked_field('unchecked field').description).to eq("have field \"unchecked field\" that is not checked")
740
+ expect(have_unchecked_field('unchecked field').description).to eq("have visible field \"unchecked field\" that is not checked and not disabled")
738
741
  end
739
742
 
740
743
  context "with should" do
@@ -745,13 +748,13 @@ RSpec.describe Capybara::RSpecMatchers do
745
748
  it "fails if there is such a field but it is checked" do
746
749
  expect do
747
750
  expect(html).to have_unchecked_field('it is checked')
748
- end.to raise_error(/expected to find field "it is checked"/)
751
+ end.to raise_error(/expected to find visible field "it is checked"/)
749
752
  end
750
753
 
751
754
  it "fails if there is no such field" do
752
755
  expect do
753
756
  expect(html).to have_unchecked_field('no such field')
754
- end.to raise_error(/expected to find field "no such field"/)
757
+ end.to raise_error(/expected to find visible field "no such field"/)
755
758
  end
756
759
  end
757
760
 
@@ -759,7 +762,7 @@ RSpec.describe Capybara::RSpecMatchers do
759
762
  it "fails if there is such a field and it is not checked" do
760
763
  expect do
761
764
  expect(html).not_to have_unchecked_field('unchecked field')
762
- end.to raise_error(/expected not to find field "unchecked field"/)
765
+ end.to raise_error(/expected not to find visible field "unchecked field"/)
763
766
  end
764
767
 
765
768
  it "passes if there is such a field but it is checked" do
@@ -780,11 +783,11 @@ RSpec.describe Capybara::RSpecMatchers do
780
783
  let(:html) { '<label>Select Box<select></select></label>' }
781
784
 
782
785
  it "gives proper description" do
783
- expect(have_select('Select Box').description).to eq("have select box \"Select Box\"")
786
+ expect(have_select('Select Box').description).to eq("have visible select box \"Select Box\" that is not disabled")
784
787
  end
785
788
 
786
789
  it "gives proper description for a given selected value" do
787
- expect(have_select('Select Box', selected: 'some value').description).to eq("have select box \"Select Box\" with \"some value\" selected")
790
+ 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')
788
791
  end
789
792
 
790
793
  it "passes if there is such a select" do
@@ -794,7 +797,7 @@ RSpec.describe Capybara::RSpecMatchers do
794
797
  it "fails if there is no such select" do
795
798
  expect do
796
799
  expect(html).to have_select('No such Select box')
797
- end.to raise_error(/expected to find select box "No such Select box"/)
800
+ end.to raise_error(/expected to find visible select box "No such Select box"/)
798
801
  end
799
802
 
800
803
  it "supports compounding" do
@@ -806,7 +809,14 @@ RSpec.describe Capybara::RSpecMatchers do
806
809
  let(:html) { '<table><caption>Lovely table</caption></table>' }
807
810
 
808
811
  it "gives proper description" do
809
- expect(have_table('Lovely table').description).to eq("have table \"Lovely table\"")
812
+ expect(have_table('Lovely table').description).to eq("have visible table \"Lovely table\"")
813
+ end
814
+
815
+ it "gives proper description when :visible option passed" do
816
+ expect(have_table('Lovely table', visible: true).description).to eq("have visible table \"Lovely table\"")
817
+ expect(have_table('Lovely table', visible: :hidden).description).to eq("have non-visible table \"Lovely table\"")
818
+ expect(have_table('Lovely table', visible: :all).description).to eq("have table \"Lovely table\"")
819
+ expect(have_table('Lovely table', visible: false).description).to eq("have table \"Lovely table\"")
810
820
  end
811
821
 
812
822
  it "passes if there is such a select" do
@@ -816,11 +826,107 @@ RSpec.describe Capybara::RSpecMatchers do
816
826
  it "fails if there is no such select" do
817
827
  expect do
818
828
  expect(html).to have_table('No such Table')
819
- end.to raise_error(/expected to find table "No such Table"/)
829
+ end.to raise_error(/expected to find visible table "No such Table"/)
820
830
  end
821
831
 
822
832
  it "supports compounding" do
823
833
  expect(html).to have_table('nope').or have_table('Lovely table')
824
834
  end if RSpec::Version::STRING.to_f >= 3.0
825
835
  end
836
+
837
+ if RSpec::Version::STRING.to_f >= 3.0
838
+ context "compounding", requires: [:js] do
839
+ before(:each) do
840
+ @session = session
841
+ @session.visit('/with_js')
842
+ @el = @session.find(:css, '#reload-me')
843
+ end
844
+
845
+ context "#and" do
846
+ it "should run 'concurrently'" do
847
+ Capybara.using_wait_time(2) do
848
+ matcher = have_text('this is not there').and have_text('neither is this')
849
+ expect(Benchmark.realtime do
850
+ expect {
851
+ expect(@el).to matcher
852
+ }.to raise_error RSpec::Expectations::ExpectationNotMetError
853
+ end).to be_between(2,3)
854
+ end
855
+ end
856
+
857
+ it "should run 'concurrently' and retry" do
858
+ @session.click_link('reload-link')
859
+ @session.using_wait_time(2) do
860
+ expect(Benchmark.realtime do
861
+ expect {
862
+ expect(@el).to have_text('waiting to be reloaded').and(have_text('has been reloaded'))
863
+ }.to raise_error RSpec::Expectations::ExpectationNotMetError, /expected to find text "waiting to be reloaded" in "has been reloaded"/
864
+ end).to be_between(2,3)
865
+ end
866
+ end
867
+
868
+ it "should ignore :wait options" do
869
+ @session.using_wait_time(2) do
870
+ matcher = have_text('this is not there', wait: 5).and have_text('neither is this', wait: 6)
871
+ expect(Benchmark.realtime do
872
+ expect {
873
+ expect(@el).to matcher
874
+ }.to raise_error RSpec::Expectations::ExpectationNotMetError
875
+ end).to be_between(2,3)
876
+ end
877
+ end
878
+
879
+ it "should work on the session" do
880
+ @session.using_wait_time(2) do
881
+ @session.click_link('reload-link')
882
+ expect(@session).to have_selector(:css, 'h1', text: 'FooBar').and have_text('has been reloaded')
883
+ end
884
+ end
885
+ end
886
+
887
+ context "#and_then" do
888
+ it "should run sequentially" do
889
+ @session.click_link('reload-link')
890
+ expect(@el).to have_text('waiting to be reloaded').and_then have_text('has been reloaded')
891
+ end
892
+ end
893
+
894
+ context "#or" do
895
+ it "should run 'concurrently'" do
896
+ @session.using_wait_time(3) do
897
+ expect(Benchmark.realtime do
898
+ expect(@el).to have_text('has been reloaded').or have_text('waiting to be reloaded')
899
+ end).to be < 1
900
+ end
901
+ end
902
+
903
+ it "should retry" do
904
+ @session.using_wait_time(3) do
905
+ expect(Benchmark.realtime do
906
+ expect {
907
+ expect(@el).to have_text('has been reloaded').or have_text('random stuff')
908
+ }.to raise_error RSpec::Expectations::ExpectationNotMetError
909
+ end).to be > 3
910
+ end
911
+ end
912
+
913
+ it "should ignore :wait options" do
914
+ @session.using_wait_time(2) do
915
+ expect(Benchmark.realtime do
916
+ expect {
917
+ expect(@el).to have_text('this is not there', wait: 10).or have_text('neither is this', wait: 15)
918
+ }.to raise_error RSpec::Expectations::ExpectationNotMetError
919
+ end).to be_between(2,3)
920
+ end
921
+ end
922
+
923
+ it "should work on the session" do
924
+ @session.using_wait_time(2) do
925
+ @session.click_link('reload-link')
926
+ expect(@session).to have_selector(:css, 'h1', text: 'Not on the page').or have_text('has been reloaded')
927
+ end
928
+ end
929
+ end
930
+ end
931
+ end
826
932
  end
@@ -1,7 +1,12 @@
1
+ # frozen_string_literal: true
1
2
  require 'spec_helper'
2
3
 
3
4
  RSpec.describe "capybara/rspec", type: :view do
4
5
  it "allows matchers to be used on strings" do
5
6
  expect(%{<h1>Test header</h1>}).to have_css("h1", text: "Test header")
6
7
  end
8
+
9
+ it "doesn't include RSpecMatcherProxies" do
10
+ expect(self.class.ancestors).not_to include(Capybara::RSpecMatcherProxies)
11
+ end
7
12
  end
@@ -0,0 +1,46 @@
1
+ # frozen_string_literal: true
2
+ require 'spec_helper'
3
+
4
+ RSpec.describe 'Capybara RSpec Matchers', :type => :feature do
5
+ context "after called on session" do
6
+ it "HaveSelector should allow getting a description of the matcher" do
7
+ visit('/with_html')
8
+ matcher = have_selector(:css, 'h2.head', minimum: 3)
9
+ expect(page).to matcher
10
+ expect { matcher.description }.not_to raise_error
11
+ end
12
+
13
+ it "HaveText should allow getting a description" do
14
+ visit('/with_html')
15
+ matcher = have_text("Lorem")
16
+ expect(page).to matcher
17
+ expect { matcher.description }.not_to raise_error
18
+ end
19
+ end
20
+
21
+ context "after called on element" do
22
+ it "HaveSelector should allow getting a description" do
23
+ visit('/with_html')
24
+ el = find(:css, '#first')
25
+ matcher = have_selector(:css, 'a#foo')
26
+ expect(el).to matcher
27
+ expect { matcher.description }.not_to raise_error
28
+ end
29
+
30
+ it "MatchSelector should allow getting a description" do
31
+ visit('/with_html')
32
+ el = find(:css, '#first')
33
+ matcher = match_selector(:css, '#first')
34
+ expect(el).to matcher
35
+ expect { matcher.description }.not_to raise_error
36
+ end
37
+
38
+ it "HaveText should allow getting a description" do
39
+ visit('/with_html')
40
+ el = find(:css, '#first')
41
+ matcher = have_text("Lorem")
42
+ expect(el).to matcher
43
+ expect { matcher.description }.not_to raise_error
44
+ end
45
+ end
46
+ end