capybara 3.13.2 → 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.
- checksums.yaml +4 -4
- data/.yardopts +1 -0
- data/History.md +587 -16
- data/README.md +240 -90
- data/lib/capybara/config.rb +24 -11
- data/lib/capybara/cucumber.rb +1 -1
- data/lib/capybara/driver/base.rb +8 -0
- data/lib/capybara/driver/node.rb +20 -4
- data/lib/capybara/dsl.rb +5 -3
- data/lib/capybara/helpers.rb +25 -4
- data/lib/capybara/minitest/spec.rb +174 -90
- data/lib/capybara/minitest.rb +256 -142
- data/lib/capybara/node/actions.rb +123 -77
- data/lib/capybara/node/base.rb +20 -12
- data/lib/capybara/node/document.rb +2 -2
- data/lib/capybara/node/document_matchers.rb +3 -3
- data/lib/capybara/node/element.rb +223 -117
- data/lib/capybara/node/finders.rb +81 -71
- data/lib/capybara/node/matchers.rb +271 -134
- data/lib/capybara/node/simple.rb +18 -5
- data/lib/capybara/node/whitespace_normalizer.rb +81 -0
- data/lib/capybara/queries/active_element_query.rb +18 -0
- data/lib/capybara/queries/ancestor_query.rb +8 -9
- data/lib/capybara/queries/base_query.rb +3 -2
- data/lib/capybara/queries/current_path_query.rb +15 -5
- data/lib/capybara/queries/selector_query.rb +364 -54
- data/lib/capybara/queries/sibling_query.rb +8 -6
- data/lib/capybara/queries/style_query.rb +2 -2
- data/lib/capybara/queries/text_query.rb +13 -1
- data/lib/capybara/queries/title_query.rb +1 -1
- data/lib/capybara/rack_test/browser.rb +76 -11
- data/lib/capybara/rack_test/driver.rb +10 -5
- data/lib/capybara/rack_test/errors.rb +6 -0
- data/lib/capybara/rack_test/form.rb +31 -9
- data/lib/capybara/rack_test/node.rb +74 -23
- data/lib/capybara/registration_container.rb +41 -0
- data/lib/capybara/registrations/drivers.rb +42 -0
- data/lib/capybara/registrations/patches/puma_ssl.rb +29 -0
- data/lib/capybara/registrations/servers.rb +66 -0
- data/lib/capybara/result.rb +44 -20
- data/lib/capybara/rspec/matcher_proxies.rb +13 -11
- data/lib/capybara/rspec/matchers/base.rb +31 -16
- data/lib/capybara/rspec/matchers/compound.rb +1 -1
- data/lib/capybara/rspec/matchers/count_sugar.rb +37 -0
- data/lib/capybara/rspec/matchers/have_ancestor.rb +28 -0
- data/lib/capybara/rspec/matchers/have_current_path.rb +2 -2
- data/lib/capybara/rspec/matchers/have_selector.rb +21 -21
- data/lib/capybara/rspec/matchers/have_sibling.rb +27 -0
- data/lib/capybara/rspec/matchers/have_text.rb +4 -4
- data/lib/capybara/rspec/matchers/have_title.rb +2 -2
- data/lib/capybara/rspec/matchers/match_selector.rb +3 -3
- data/lib/capybara/rspec/matchers/match_style.rb +7 -2
- data/lib/capybara/rspec/matchers/spatial_sugar.rb +39 -0
- data/lib/capybara/rspec/matchers.rb +111 -68
- data/lib/capybara/rspec.rb +2 -0
- data/lib/capybara/selector/builders/css_builder.rb +11 -7
- data/lib/capybara/selector/builders/xpath_builder.rb +5 -3
- data/lib/capybara/selector/css.rb +11 -9
- data/lib/capybara/selector/definition/button.rb +68 -0
- data/lib/capybara/selector/definition/checkbox.rb +26 -0
- data/lib/capybara/selector/definition/css.rb +10 -0
- data/lib/capybara/selector/definition/datalist_input.rb +35 -0
- data/lib/capybara/selector/definition/datalist_option.rb +25 -0
- data/lib/capybara/selector/definition/element.rb +28 -0
- data/lib/capybara/selector/definition/field.rb +40 -0
- data/lib/capybara/selector/definition/fieldset.rb +14 -0
- data/lib/capybara/selector/definition/file_field.rb +13 -0
- data/lib/capybara/selector/definition/fillable_field.rb +33 -0
- data/lib/capybara/selector/definition/frame.rb +17 -0
- data/lib/capybara/selector/definition/id.rb +6 -0
- data/lib/capybara/selector/definition/label.rb +62 -0
- data/lib/capybara/selector/definition/link.rb +55 -0
- data/lib/capybara/selector/definition/link_or_button.rb +16 -0
- data/lib/capybara/selector/definition/option.rb +27 -0
- data/lib/capybara/selector/definition/radio_button.rb +27 -0
- data/lib/capybara/selector/definition/select.rb +81 -0
- data/lib/capybara/selector/definition/table.rb +109 -0
- data/lib/capybara/selector/definition/table_row.rb +21 -0
- data/lib/capybara/selector/definition/xpath.rb +5 -0
- data/lib/capybara/selector/definition.rb +280 -0
- data/lib/capybara/selector/filter_set.rb +19 -18
- data/lib/capybara/selector/filters/base.rb +11 -2
- data/lib/capybara/selector/filters/locator_filter.rb +13 -3
- data/lib/capybara/selector/regexp_disassembler.rb +11 -7
- data/lib/capybara/selector/selector.rb +50 -440
- data/lib/capybara/selector/xpath_extensions.rb +17 -0
- data/lib/capybara/selector.rb +473 -482
- data/lib/capybara/selenium/atoms/getAttribute.min.js +1 -0
- data/lib/capybara/selenium/atoms/isDisplayed.min.js +1 -0
- data/lib/capybara/selenium/atoms/src/getAttribute.js +161 -0
- data/lib/capybara/selenium/atoms/src/isDisplayed.js +454 -0
- data/lib/capybara/selenium/driver.rb +174 -62
- data/lib/capybara/selenium/driver_specializations/chrome_driver.rb +74 -18
- data/lib/capybara/selenium/driver_specializations/edge_driver.rb +128 -0
- data/lib/capybara/selenium/driver_specializations/firefox_driver.rb +37 -3
- data/lib/capybara/selenium/driver_specializations/internet_explorer_driver.rb +14 -1
- data/lib/capybara/selenium/driver_specializations/safari_driver.rb +24 -0
- data/lib/capybara/selenium/extensions/file_input_click_emulation.rb +34 -0
- data/lib/capybara/selenium/extensions/find.rb +68 -45
- data/lib/capybara/selenium/extensions/html5_drag.rb +192 -22
- data/lib/capybara/selenium/extensions/modifier_keys_stack.rb +28 -0
- data/lib/capybara/selenium/extensions/scroll.rb +8 -10
- data/lib/capybara/selenium/node.rb +268 -72
- data/lib/capybara/selenium/nodes/chrome_node.rb +105 -9
- data/lib/capybara/selenium/nodes/edge_node.rb +110 -0
- data/lib/capybara/selenium/nodes/firefox_node.rb +51 -61
- data/lib/capybara/selenium/nodes/ie_node.rb +22 -0
- data/lib/capybara/selenium/nodes/safari_node.rb +118 -0
- data/lib/capybara/selenium/patches/atoms.rb +18 -0
- data/lib/capybara/selenium/patches/is_displayed.rb +16 -0
- data/lib/capybara/selenium/patches/logs.rb +45 -0
- data/lib/capybara/selenium/patches/pause_duration_fix.rb +1 -1
- data/lib/capybara/selenium/patches/persistent_client.rb +20 -0
- data/lib/capybara/server/animation_disabler.rb +43 -21
- data/lib/capybara/server/checker.rb +6 -2
- data/lib/capybara/server/middleware.rb +25 -13
- data/lib/capybara/server.rb +20 -4
- data/lib/capybara/session/config.rb +15 -11
- data/lib/capybara/session/matchers.rb +11 -11
- data/lib/capybara/session.rb +162 -131
- data/lib/capybara/spec/public/offset.js +6 -0
- data/lib/capybara/spec/public/test.js +105 -6
- data/lib/capybara/spec/session/accept_alert_spec.rb +1 -1
- data/lib/capybara/spec/session/active_element_spec.rb +31 -0
- data/lib/capybara/spec/session/all_spec.rb +89 -15
- data/lib/capybara/spec/session/ancestor_spec.rb +5 -0
- data/lib/capybara/spec/session/assert_current_path_spec.rb +5 -2
- data/lib/capybara/spec/session/assert_text_spec.rb +26 -22
- data/lib/capybara/spec/session/attach_file_spec.rb +64 -31
- data/lib/capybara/spec/session/check_spec.rb +26 -4
- data/lib/capybara/spec/session/choose_spec.rb +14 -2
- data/lib/capybara/spec/session/click_button_spec.rb +109 -61
- data/lib/capybara/spec/session/click_link_or_button_spec.rb +9 -0
- data/lib/capybara/spec/session/click_link_spec.rb +23 -1
- data/lib/capybara/spec/session/current_scope_spec.rb +1 -1
- data/lib/capybara/spec/session/current_url_spec.rb +11 -1
- data/lib/capybara/spec/session/element/matches_selector_spec.rb +40 -39
- data/lib/capybara/spec/session/evaluate_script_spec.rb +12 -0
- data/lib/capybara/spec/session/fill_in_spec.rb +46 -5
- data/lib/capybara/spec/session/find_link_spec.rb +10 -0
- data/lib/capybara/spec/session/find_spec.rb +80 -7
- data/lib/capybara/spec/session/first_spec.rb +2 -2
- data/lib/capybara/spec/session/frame/switch_to_frame_spec.rb +14 -1
- data/lib/capybara/spec/session/frame/within_frame_spec.rb +14 -1
- data/lib/capybara/spec/session/has_all_selectors_spec.rb +5 -5
- data/lib/capybara/spec/session/has_ancestor_spec.rb +46 -0
- data/lib/capybara/spec/session/has_any_selectors_spec.rb +6 -2
- data/lib/capybara/spec/session/has_button_spec.rb +81 -0
- data/lib/capybara/spec/session/has_css_spec.rb +45 -8
- data/lib/capybara/spec/session/has_current_path_spec.rb +22 -7
- data/lib/capybara/spec/session/has_element_spec.rb +47 -0
- data/lib/capybara/spec/session/has_field_spec.rb +59 -1
- data/lib/capybara/spec/session/has_link_spec.rb +40 -0
- data/lib/capybara/spec/session/has_none_selectors_spec.rb +7 -7
- data/lib/capybara/spec/session/has_select_spec.rb +42 -8
- data/lib/capybara/spec/session/has_selector_spec.rb +19 -4
- data/lib/capybara/spec/session/has_sibling_spec.rb +50 -0
- data/lib/capybara/spec/session/has_table_spec.rb +177 -0
- data/lib/capybara/spec/session/has_text_spec.rb +31 -3
- data/lib/capybara/spec/session/html_spec.rb +1 -1
- data/lib/capybara/spec/session/matches_style_spec.rb +6 -4
- data/lib/capybara/spec/session/node_spec.rb +697 -23
- data/lib/capybara/spec/session/node_wrapper_spec.rb +1 -1
- data/lib/capybara/spec/session/refresh_spec.rb +2 -1
- data/lib/capybara/spec/session/reset_session_spec.rb +21 -7
- data/lib/capybara/spec/session/save_and_open_screenshot_spec.rb +2 -2
- data/lib/capybara/spec/session/save_page_spec.rb +4 -4
- data/lib/capybara/spec/session/save_screenshot_spec.rb +4 -4
- data/lib/capybara/spec/session/scroll_spec.rb +9 -7
- data/lib/capybara/spec/session/select_spec.rb +5 -10
- data/lib/capybara/spec/session/selectors_spec.rb +24 -3
- data/lib/capybara/spec/session/uncheck_spec.rb +3 -3
- data/lib/capybara/spec/session/unselect_spec.rb +1 -1
- data/lib/capybara/spec/session/visit_spec.rb +20 -0
- data/lib/capybara/spec/session/window/become_closed_spec.rb +20 -17
- data/lib/capybara/spec/session/window/switch_to_window_spec.rb +1 -1
- data/lib/capybara/spec/session/window/window_opened_by_spec.rb +1 -1
- data/lib/capybara/spec/session/window/window_spec.rb +54 -57
- data/lib/capybara/spec/session/window/windows_spec.rb +2 -2
- data/lib/capybara/spec/session/within_spec.rb +36 -0
- data/lib/capybara/spec/spec_helper.rb +30 -19
- data/lib/capybara/spec/test_app.rb +122 -34
- data/lib/capybara/spec/views/animated.erb +49 -0
- data/lib/capybara/spec/views/form.erb +86 -8
- data/lib/capybara/spec/views/frame_child.erb +3 -2
- data/lib/capybara/spec/views/frame_one.erb +2 -1
- data/lib/capybara/spec/views/frame_parent.erb +1 -1
- data/lib/capybara/spec/views/frame_two.erb +1 -1
- data/lib/capybara/spec/views/initial_alert.erb +2 -1
- data/lib/capybara/spec/views/layout.erb +10 -0
- data/lib/capybara/spec/views/obscured.erb +10 -10
- data/lib/capybara/spec/views/offset.erb +33 -0
- data/lib/capybara/spec/views/path.erb +2 -2
- data/lib/capybara/spec/views/popup_one.erb +1 -1
- data/lib/capybara/spec/views/popup_two.erb +1 -1
- data/lib/capybara/spec/views/react.erb +45 -0
- data/lib/capybara/spec/views/scroll.erb +2 -1
- data/lib/capybara/spec/views/spatial.erb +31 -0
- data/lib/capybara/spec/views/tables.erb +67 -0
- data/lib/capybara/spec/views/with_animation.erb +39 -4
- data/lib/capybara/spec/views/with_base_tag.erb +2 -2
- data/lib/capybara/spec/views/with_dragula.erb +24 -0
- data/lib/capybara/spec/views/with_fixed_header_footer.erb +2 -1
- data/lib/capybara/spec/views/with_hover.erb +3 -2
- data/lib/capybara/spec/views/with_hover1.erb +10 -0
- data/lib/capybara/spec/views/with_html.erb +34 -6
- data/lib/capybara/spec/views/with_jquery_animation.erb +24 -0
- data/lib/capybara/spec/views/with_js.erb +7 -4
- data/lib/capybara/spec/views/with_jstree.erb +26 -0
- data/lib/capybara/spec/views/with_namespace.erb +1 -0
- data/lib/capybara/spec/views/with_scope.erb +2 -2
- data/lib/capybara/spec/views/with_scope_other.erb +6 -0
- data/lib/capybara/spec/views/with_shadow.erb +31 -0
- data/lib/capybara/spec/views/with_slow_unload.erb +2 -1
- data/lib/capybara/spec/views/with_sortable_js.erb +21 -0
- data/lib/capybara/spec/views/with_unload_alert.erb +1 -0
- data/lib/capybara/spec/views/with_windows.erb +1 -1
- data/lib/capybara/spec/views/within_frames.erb +1 -1
- data/lib/capybara/version.rb +1 -1
- data/lib/capybara/window.rb +14 -18
- data/lib/capybara.rb +91 -126
- data/spec/basic_node_spec.rb +30 -16
- data/spec/capybara_spec.rb +40 -28
- data/spec/counter_spec.rb +35 -0
- data/spec/css_builder_spec.rb +3 -1
- data/spec/css_splitter_spec.rb +1 -1
- data/spec/dsl_spec.rb +33 -22
- data/spec/filter_set_spec.rb +5 -5
- data/spec/fixtures/selenium_driver_rspec_failure.rb +3 -3
- data/spec/fixtures/selenium_driver_rspec_success.rb +3 -3
- data/spec/minitest_spec.rb +24 -2
- data/spec/minitest_spec_spec.rb +60 -45
- data/spec/per_session_config_spec.rb +1 -1
- data/spec/rack_test_spec.rb +131 -98
- data/spec/regexp_dissassembler_spec.rb +53 -39
- data/spec/result_spec.rb +68 -66
- data/spec/rspec/features_spec.rb +9 -4
- data/spec/rspec/scenarios_spec.rb +6 -2
- data/spec/rspec/shared_spec_matchers.rb +137 -98
- data/spec/rspec_matchers_spec.rb +25 -0
- data/spec/rspec_spec.rb +23 -21
- data/spec/sauce_spec_chrome.rb +43 -0
- data/spec/selector_spec.rb +77 -21
- data/spec/selenium_spec_chrome.rb +141 -39
- data/spec/selenium_spec_chrome_remote.rb +32 -17
- data/spec/selenium_spec_edge.rb +36 -8
- data/spec/selenium_spec_firefox.rb +110 -68
- data/spec/selenium_spec_firefox_remote.rb +22 -15
- data/spec/selenium_spec_ie.rb +29 -22
- data/spec/selenium_spec_safari.rb +162 -0
- data/spec/server_spec.rb +153 -81
- data/spec/session_spec.rb +11 -4
- data/spec/shared_selenium_node.rb +79 -0
- data/spec/shared_selenium_session.rb +179 -74
- data/spec/spec_helper.rb +80 -5
- data/spec/whitespace_normalizer_spec.rb +54 -0
- data/spec/xpath_builder_spec.rb +3 -1
- metadata +218 -30
- data/lib/capybara/spec/session/source_spec.rb +0 -0
- data/lib/capybara/spec/views/with_title.erb +0 -5
@@ -89,29 +89,29 @@ RSpec.shared_examples Capybara::RSpecMatchers do |session, _mode|
|
|
89
89
|
|
90
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
95
|
context 'with should' do
|
96
96
|
it 'passes if has_css? returns true' do
|
97
|
-
expect(
|
97
|
+
expect(session).to have_css('h1')
|
98
98
|
end
|
99
99
|
|
100
100
|
it 'fails if has_css? returns false' do
|
101
101
|
expect do
|
102
|
-
expect(
|
102
|
+
expect(session).to have_css('h1#doesnotexist')
|
103
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
107
|
context 'with should_not' do
|
108
108
|
it 'passes if has_no_css? returns true' do
|
109
|
-
expect(
|
109
|
+
expect(session).not_to have_css('h1#doesnotexist')
|
110
110
|
end
|
111
111
|
|
112
112
|
it 'fails if has_no_css? returns false' do
|
113
113
|
expect do
|
114
|
-
expect(
|
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
|
@@ -120,7 +120,7 @@ RSpec.shared_examples Capybara::RSpecMatchers do |session, _mode|
|
|
120
120
|
|
121
121
|
describe 'have_xpath matcher' do
|
122
122
|
it 'gives proper description' do
|
123
|
-
expect(have_xpath('//h1').description).to eq(
|
123
|
+
expect(have_xpath('//h1').description).to eq('have visible xpath "//h1"')
|
124
124
|
end
|
125
125
|
|
126
126
|
context 'on a string' do
|
@@ -158,29 +158,29 @@ RSpec.shared_examples Capybara::RSpecMatchers do |session, _mode|
|
|
158
158
|
|
159
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
164
|
context 'with should' do
|
165
165
|
it 'passes if has_xpath? returns true' do
|
166
|
-
expect(
|
166
|
+
expect(session).to have_xpath('//h1')
|
167
167
|
end
|
168
168
|
|
169
169
|
it 'fails if has_xpath? returns false' do
|
170
170
|
expect do
|
171
|
-
expect(
|
171
|
+
expect(session).to have_xpath("//h1[@id='doesnotexist']")
|
172
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
176
|
context 'with should_not' do
|
177
177
|
it 'passes if has_no_xpath? returns true' do
|
178
|
-
expect(
|
178
|
+
expect(session).not_to have_xpath('//h1[@id="doesnotexist"]')
|
179
179
|
end
|
180
180
|
|
181
181
|
it 'fails if has_no_xpath? returns false' do
|
182
182
|
expect do
|
183
|
-
expect(
|
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
|
@@ -222,35 +222,35 @@ RSpec.shared_examples Capybara::RSpecMatchers do |session, _mode|
|
|
222
222
|
|
223
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
228
|
context 'with should' do
|
229
229
|
it 'passes if has_selector? returns true' do
|
230
|
-
expect(
|
230
|
+
expect(session).to have_selector('//h1', text: 'test')
|
231
231
|
end
|
232
232
|
|
233
233
|
it 'fails if has_selector? returns false' do
|
234
234
|
expect do
|
235
|
-
expect(
|
235
|
+
expect(session).to have_selector("//h1[@id='doesnotexist']")
|
236
236
|
end.to raise_error(%r{expected to find xpath "//h1\[@id='doesnotexist'\]" but there were no matches})
|
237
237
|
end
|
238
238
|
|
239
239
|
it 'includes text in error message' do
|
240
240
|
expect do
|
241
|
-
expect(
|
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
246
|
context 'with should_not' do
|
247
247
|
it 'passes if has_no_css? returns true' do
|
248
|
-
expect(
|
248
|
+
expect(session).not_to have_selector(:css, 'h1#doesnotexist')
|
249
249
|
end
|
250
250
|
|
251
251
|
it 'fails if has_no_selector? returns false' do
|
252
252
|
expect do
|
253
|
-
expect(
|
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
|
@@ -265,7 +265,7 @@ RSpec.shared_examples Capybara::RSpecMatchers do |session, _mode|
|
|
265
265
|
|
266
266
|
describe 'have_content matcher' do
|
267
267
|
it 'gives proper description' do
|
268
|
-
expect(have_content('Text').description).to eq('text "Text"')
|
268
|
+
expect(have_content('Text').description).to eq('have text "Text"')
|
269
269
|
end
|
270
270
|
|
271
271
|
context 'on a string' do
|
@@ -304,21 +304,21 @@ RSpec.shared_examples Capybara::RSpecMatchers do |session, _mode|
|
|
304
304
|
|
305
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
310
|
context 'with should' do
|
311
311
|
it 'passes if has_content? returns true' do
|
312
|
-
expect(
|
312
|
+
expect(session).to have_content('This is a test')
|
313
313
|
end
|
314
314
|
|
315
315
|
it 'passes if has_content? returns true using regexp' do
|
316
|
-
expect(
|
316
|
+
expect(session).to have_content(/test/)
|
317
317
|
end
|
318
318
|
|
319
319
|
it 'fails if has_content? returns false' do
|
320
320
|
expect do
|
321
|
-
expect(
|
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
|
|
@@ -329,7 +329,7 @@ RSpec.shared_examples Capybara::RSpecMatchers do |session, _mode|
|
|
329
329
|
|
330
330
|
it 'fails if has_content? returns false' do
|
331
331
|
expect do
|
332
|
-
expect(
|
332
|
+
expect(session).to have_content('No such Text')
|
333
333
|
end.to raise_error(/expected to find text "No such Text" in "(.*)This is a test(.*)"/)
|
334
334
|
end
|
335
335
|
end
|
@@ -337,14 +337,26 @@ RSpec.shared_examples Capybara::RSpecMatchers do |session, _mode|
|
|
337
337
|
|
338
338
|
context 'with should_not' do
|
339
339
|
it 'passes if has_no_content? returns true' do
|
340
|
-
expect(
|
340
|
+
expect(session).not_to have_content('No such Text')
|
341
341
|
end
|
342
342
|
|
343
343
|
it 'fails if has_no_content? returns false' do
|
344
344
|
expect do
|
345
|
-
expect(
|
345
|
+
expect(session).not_to have_content('This is a test')
|
346
346
|
end.to raise_error(/expected not to find text "This is a test"/)
|
347
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
|
348
360
|
end
|
349
361
|
end
|
350
362
|
|
@@ -357,7 +369,7 @@ RSpec.shared_examples Capybara::RSpecMatchers do |session, _mode|
|
|
357
369
|
|
358
370
|
describe 'have_text matcher' do
|
359
371
|
it 'gives proper description' do
|
360
|
-
expect(have_text('Text').description).to eq('text "Text"')
|
372
|
+
expect(have_text('Text').description).to eq('have text "Text"')
|
361
373
|
end
|
362
374
|
|
363
375
|
context 'on a string' do
|
@@ -432,30 +444,30 @@ RSpec.shared_examples Capybara::RSpecMatchers do |session, _mode|
|
|
432
444
|
|
433
445
|
context 'on a page or node' do
|
434
446
|
before do
|
435
|
-
visit('/with_html')
|
447
|
+
session.visit('/with_html')
|
436
448
|
end
|
437
449
|
|
438
450
|
context 'with should' do
|
439
451
|
it 'passes if has_text? returns true' do
|
440
|
-
expect(
|
452
|
+
expect(session).to have_text('This is a test')
|
441
453
|
end
|
442
454
|
|
443
455
|
it 'passes if has_text? returns true using regexp' do
|
444
|
-
expect(
|
456
|
+
expect(session).to have_text(/test/)
|
445
457
|
end
|
446
458
|
|
447
459
|
it 'can check for all text' do
|
448
|
-
expect(
|
460
|
+
expect(session).to have_text(:all, 'Some of this text is hidden!')
|
449
461
|
end
|
450
462
|
|
451
463
|
it 'can check for visible text' do
|
452
|
-
expect(
|
453
|
-
expect(
|
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!')
|
454
466
|
end
|
455
467
|
|
456
468
|
it 'fails if has_text? returns false' do
|
457
469
|
expect do
|
458
|
-
expect(
|
470
|
+
expect(session).to have_text('No such Text')
|
459
471
|
end.to raise_error(/expected to find text "No such Text" in "(.*)This is a test(.*)"/)
|
460
472
|
end
|
461
473
|
|
@@ -466,7 +478,7 @@ RSpec.shared_examples Capybara::RSpecMatchers do |session, _mode|
|
|
466
478
|
|
467
479
|
it 'fails if has_text? returns false' do
|
468
480
|
expect do
|
469
|
-
expect(
|
481
|
+
expect(session).to have_text('No such Text')
|
470
482
|
end.to raise_error(/expected to find text "No such Text" in "(.*)This is a test(.*)"/)
|
471
483
|
end
|
472
484
|
end
|
@@ -474,12 +486,12 @@ RSpec.shared_examples Capybara::RSpecMatchers do |session, _mode|
|
|
474
486
|
|
475
487
|
context 'with should_not' do
|
476
488
|
it 'passes if has_no_text? returns true' do
|
477
|
-
expect(
|
489
|
+
expect(session).not_to have_text('No such Text')
|
478
490
|
end
|
479
491
|
|
480
492
|
it 'fails if has_no_text? returns false' do
|
481
493
|
expect do
|
482
|
-
expect(
|
494
|
+
expect(session).not_to have_text('This is a test')
|
483
495
|
end.to raise_error(/expected not to find text "This is a test"/)
|
484
496
|
end
|
485
497
|
end
|
@@ -491,6 +503,30 @@ RSpec.shared_examples Capybara::RSpecMatchers do |session, _mode|
|
|
491
503
|
end
|
492
504
|
end
|
493
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')
|
527
|
+
end
|
528
|
+
end
|
529
|
+
|
494
530
|
describe 'have_link matcher' do
|
495
531
|
let(:html) { '<a href="#">Just a link</a><a href="#">Another link</a>' }
|
496
532
|
|
@@ -542,34 +578,33 @@ RSpec.shared_examples Capybara::RSpecMatchers do |session, _mode|
|
|
542
578
|
|
543
579
|
context 'on a page or node' do
|
544
580
|
it 'passes if there is such a title' do
|
545
|
-
visit('/with_js')
|
546
|
-
expect(
|
581
|
+
session.visit('/with_js')
|
582
|
+
expect(session).to have_title('with_js')
|
547
583
|
end
|
548
584
|
|
549
585
|
it 'fails if there is no such title' do
|
550
|
-
visit('/with_js')
|
586
|
+
session.visit('/with_js')
|
551
587
|
expect do
|
552
|
-
expect(
|
553
|
-
end.to raise_error(
|
588
|
+
expect(session).to have_title('No such title')
|
589
|
+
end.to raise_error(/ to include "No such title"/)
|
554
590
|
end
|
555
591
|
|
556
592
|
context 'with wait' do
|
557
593
|
before do
|
558
|
-
|
559
|
-
@session.visit('/with_js')
|
594
|
+
session.visit('/with_js')
|
560
595
|
end
|
561
596
|
|
562
597
|
it 'waits if wait time is more than timeout' do
|
563
|
-
|
564
|
-
using_wait_time 0 do
|
565
|
-
expect(
|
598
|
+
session.click_link('Change title')
|
599
|
+
session.using_wait_time 0 do
|
600
|
+
expect(session).to have_title('changed title', wait: 2)
|
566
601
|
end
|
567
602
|
end
|
568
603
|
|
569
604
|
it "doesn't wait if wait time is less than timeout" do
|
570
|
-
|
571
|
-
using_wait_time 3 do
|
572
|
-
expect(
|
605
|
+
session.click_link('Change title')
|
606
|
+
session.using_wait_time 3 do
|
607
|
+
expect(session).not_to have_title('changed title', wait: 0)
|
573
608
|
end
|
574
609
|
end
|
575
610
|
end
|
@@ -587,50 +622,53 @@ RSpec.shared_examples Capybara::RSpecMatchers do |session, _mode|
|
|
587
622
|
|
588
623
|
context 'on a page or node' do
|
589
624
|
it 'passes if there is such a current path' do
|
590
|
-
visit('/with_js')
|
591
|
-
expect(
|
625
|
+
session.visit('/with_js')
|
626
|
+
expect(session).to have_current_path('/with_js')
|
592
627
|
end
|
593
628
|
|
594
629
|
it 'fails if there is no such current_path' do
|
595
630
|
visit('/with_js')
|
596
631
|
expect do
|
597
|
-
expect(
|
598
|
-
end.to raise_error(
|
632
|
+
expect(session).to have_current_path('/not_with_js')
|
633
|
+
end.to raise_error(%r{to equal "/not_with_js"})
|
599
634
|
end
|
600
635
|
|
601
636
|
context 'with wait' do
|
602
637
|
before do
|
603
|
-
|
604
|
-
@session.visit('/with_js')
|
638
|
+
session.visit('/with_js')
|
605
639
|
end
|
606
640
|
|
607
641
|
it 'waits if wait time is more than timeout' do
|
608
|
-
|
609
|
-
using_wait_time 0 do
|
610
|
-
expect(
|
642
|
+
session.click_link('Change page')
|
643
|
+
session.using_wait_time 0 do
|
644
|
+
expect(session).to have_current_path('/with_html', wait: 2)
|
611
645
|
end
|
612
646
|
end
|
613
647
|
|
614
648
|
it "doesn't wait if wait time is less than timeout" do
|
615
|
-
|
616
|
-
using_wait_time 0 do
|
617
|
-
expect(
|
649
|
+
session.click_link('Change page')
|
650
|
+
session.using_wait_time 0 do
|
651
|
+
expect(session).not_to have_current_path('/with_html')
|
618
652
|
end
|
619
653
|
end
|
620
654
|
end
|
621
655
|
end
|
622
656
|
|
623
657
|
it 'supports compounding' do
|
624
|
-
visit('/with_html')
|
625
|
-
expect(
|
658
|
+
session.visit('/with_html')
|
659
|
+
expect(session).to have_current_path('/not_with_html').or have_current_path('/with_html')
|
626
660
|
end
|
627
661
|
end
|
628
662
|
|
629
663
|
describe 'have_button matcher' do
|
630
664
|
let(:html) { '<button>A button</button><input type="submit" value="Another button"/>' }
|
631
665
|
|
632
|
-
it 'gives proper description' do
|
633
|
-
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')
|
668
|
+
end
|
669
|
+
|
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"')
|
634
672
|
end
|
635
673
|
|
636
674
|
it 'passes if there is such a button' do
|
@@ -680,12 +718,12 @@ RSpec.shared_examples Capybara::RSpecMatchers do |session, _mode|
|
|
680
718
|
end
|
681
719
|
|
682
720
|
it 'treats a given value as a string' do
|
683
|
-
|
721
|
+
foo = Class.new do
|
684
722
|
def to_s
|
685
723
|
'some value'
|
686
724
|
end
|
687
725
|
end
|
688
|
-
expect(html).to have_field('Text field', with:
|
726
|
+
expect(html).to have_field('Text field', with: foo.new)
|
689
727
|
end
|
690
728
|
|
691
729
|
it 'supports compounding' do
|
@@ -700,7 +738,7 @@ RSpec.shared_examples Capybara::RSpecMatchers do |session, _mode|
|
|
700
738
|
end
|
701
739
|
|
702
740
|
it 'gives proper description' do
|
703
|
-
expect(have_checked_field('it is checked').description).to eq('have visible field "it is checked" that is
|
741
|
+
expect(have_checked_field('it is checked').description).to eq('have visible field "it is checked" that is not disabled that is checked')
|
704
742
|
end
|
705
743
|
|
706
744
|
context 'with should' do
|
@@ -749,7 +787,7 @@ RSpec.shared_examples Capybara::RSpecMatchers do |session, _mode|
|
|
749
787
|
end
|
750
788
|
|
751
789
|
it 'gives proper description' do
|
752
|
-
expect(have_unchecked_field('unchecked field').description).to eq('have visible field "unchecked field" that is not
|
790
|
+
expect(have_unchecked_field('unchecked field').description).to eq('have visible field "unchecked field" that is not disabled that is not checked')
|
753
791
|
end
|
754
792
|
|
755
793
|
context 'with should' do
|
@@ -826,10 +864,10 @@ RSpec.shared_examples Capybara::RSpecMatchers do |session, _mode|
|
|
826
864
|
end
|
827
865
|
|
828
866
|
it 'gives proper description when :visible option passed' do
|
829
|
-
expect(have_table('Lovely table', visible: true).description).to eq('have visible table "Lovely table"')
|
867
|
+
expect(have_table('Lovely table', visible: true).description).to eq('have visible table "Lovely table"') # rubocop:disable Capybara/VisibilityMatcher
|
830
868
|
expect(have_table('Lovely table', visible: :hidden).description).to eq('have non-visible table "Lovely table"')
|
831
869
|
expect(have_table('Lovely table', visible: :all).description).to eq('have table "Lovely table"')
|
832
|
-
expect(have_table('Lovely table', visible: false).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
|
833
871
|
end
|
834
872
|
|
835
873
|
it 'passes if there is such a table' do
|
@@ -848,94 +886,95 @@ RSpec.shared_examples Capybara::RSpecMatchers do |session, _mode|
|
|
848
886
|
end
|
849
887
|
|
850
888
|
context 'compounding timing' do
|
889
|
+
let(:session) { session }
|
890
|
+
let(:el) { session.find(:css, '#reload-me') }
|
891
|
+
|
851
892
|
before do
|
852
|
-
|
853
|
-
@session.visit('/with_js')
|
854
|
-
@el = @session.find(:css, '#reload-me')
|
893
|
+
session.visit('/with_js')
|
855
894
|
end
|
856
895
|
|
857
|
-
|
896
|
+
describe '#and' do
|
858
897
|
it "should run 'concurrently'" do
|
859
|
-
|
898
|
+
session.using_wait_time(2) do
|
860
899
|
matcher = have_text('this is not there').and have_text('neither is this')
|
861
900
|
expect(Benchmark.realtime do
|
862
901
|
expect do
|
863
|
-
expect(
|
902
|
+
expect(el).to matcher
|
864
903
|
end.to raise_error RSpec::Expectations::ExpectationNotMetError
|
865
904
|
end).to be_between(2, 3)
|
866
905
|
end
|
867
906
|
end
|
868
907
|
|
869
908
|
it "should run 'concurrently' and retry" do
|
870
|
-
|
871
|
-
|
909
|
+
session.click_link('reload-link')
|
910
|
+
session.using_wait_time(2) do
|
872
911
|
expect(Benchmark.realtime do
|
873
912
|
expect do
|
874
|
-
expect(
|
913
|
+
expect(el).to have_text('waiting to be reloaded').and(have_text('has been reloaded'))
|
875
914
|
end.to raise_error RSpec::Expectations::ExpectationNotMetError, /expected to find text "waiting to be reloaded" in "has been reloaded"/
|
876
915
|
end).to be_between(2, 3)
|
877
916
|
end
|
878
917
|
end
|
879
918
|
|
880
919
|
it 'should ignore :wait options' do
|
881
|
-
|
920
|
+
session.using_wait_time(2) do
|
882
921
|
matcher = have_text('this is not there', wait: 5).and have_text('neither is this', wait: 6)
|
883
922
|
expect(Benchmark.realtime do
|
884
923
|
expect do
|
885
|
-
expect(
|
924
|
+
expect(el).to matcher
|
886
925
|
end.to raise_error RSpec::Expectations::ExpectationNotMetError
|
887
926
|
end).to be_between(2, 3)
|
888
927
|
end
|
889
928
|
end
|
890
929
|
|
891
930
|
it 'should work on the session' do
|
892
|
-
|
893
|
-
|
894
|
-
expect(
|
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')
|
895
934
|
end
|
896
935
|
end
|
897
936
|
end
|
898
937
|
|
899
|
-
|
938
|
+
describe '#and_then' do
|
900
939
|
it 'should run sequentially' do
|
901
|
-
|
902
|
-
expect(
|
940
|
+
session.click_link('reload-link')
|
941
|
+
expect(el).to have_text('waiting to be reloaded').and_then have_text('has been reloaded')
|
903
942
|
end
|
904
943
|
end
|
905
944
|
|
906
|
-
|
945
|
+
describe '#or' do
|
907
946
|
it "should run 'concurrently'" do
|
908
|
-
|
947
|
+
session.using_wait_time(3) do
|
909
948
|
expect(Benchmark.realtime do
|
910
|
-
expect(
|
949
|
+
expect(el).to have_text('has been reloaded').or have_text('waiting to be reloaded')
|
911
950
|
end).to be < 1
|
912
951
|
end
|
913
952
|
end
|
914
953
|
|
915
954
|
it 'should retry' do
|
916
|
-
|
955
|
+
session.using_wait_time(3) do
|
917
956
|
expect(Benchmark.realtime do
|
918
957
|
expect do
|
919
|
-
expect(
|
958
|
+
expect(el).to have_text('has been reloaded').or have_text('random stuff')
|
920
959
|
end.to raise_error RSpec::Expectations::ExpectationNotMetError
|
921
960
|
end).to be > 3
|
922
961
|
end
|
923
962
|
end
|
924
963
|
|
925
964
|
it 'should ignore :wait options' do
|
926
|
-
|
965
|
+
session.using_wait_time(2) do
|
927
966
|
expect(Benchmark.realtime do
|
928
967
|
expect do
|
929
|
-
expect(
|
968
|
+
expect(el).to have_text('this is not there', wait: 10).or have_text('neither is this', wait: 15)
|
930
969
|
end.to raise_error RSpec::Expectations::ExpectationNotMetError
|
931
970
|
end).to be_between(2, 3)
|
932
971
|
end
|
933
972
|
end
|
934
973
|
|
935
974
|
it 'should work on the session' do
|
936
|
-
|
937
|
-
|
938
|
-
expect(
|
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')
|
939
978
|
end
|
940
979
|
end
|
941
980
|
end
|
data/spec/rspec_matchers_spec.rb
CHANGED
@@ -56,6 +56,31 @@ RSpec.describe 'Capybara RSpec Matchers', type: :feature do
|
|
56
56
|
end
|
57
57
|
end
|
58
58
|
|
59
|
+
context 'with a filter block' do
|
60
|
+
it 'applies the filter' do
|
61
|
+
visit('/with_html')
|
62
|
+
expect(page).to have_selector(:css, 'input#test_field')
|
63
|
+
|
64
|
+
expect(page).to have_selector(:css, 'input', count: 1) { |input| input.value == 'monkey' }
|
65
|
+
expect(page).to have_selector(:css, 'input', count: 1) do |input|
|
66
|
+
input.value == 'monkey'
|
67
|
+
end
|
68
|
+
expect(page).to have_no_selector(:css, 'input#test_field') { |input| input.value == 'not a monkey' }
|
69
|
+
expect(page).to have_no_selector(:css, 'input#test_field') do |input|
|
70
|
+
input.value == 'not a monkey'
|
71
|
+
end
|
72
|
+
|
73
|
+
expect(page).not_to have_selector(:css, 'input#test_field') { |input| input.value == 'not a monkey' }
|
74
|
+
expect(page).not_to have_selector(:css, 'input#test_field') do |input|
|
75
|
+
input.value == 'not a monkey'
|
76
|
+
end
|
77
|
+
expect(page).not_to have_no_selector(:css, 'input', count: 1) { |input| input.value == 'monkey' }
|
78
|
+
expect(page).not_to have_no_selector(:css, 'input#test_field', count: 1) do |input|
|
79
|
+
input.value == 'monkey'
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
59
84
|
def error_msg_for(&block)
|
60
85
|
expect(&block).to(raise_error { |e| return e.message })
|
61
86
|
end
|