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