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