capybara 2.7.0 → 3.35.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.yardopts +1 -0
- data/History.md +1147 -11
- data/License.txt +1 -1
- data/README.md +252 -131
- data/lib/capybara/config.rb +92 -0
- data/lib/capybara/cucumber.rb +3 -3
- data/lib/capybara/driver/base.rb +52 -21
- data/lib/capybara/driver/node.rb +48 -14
- data/lib/capybara/dsl.rb +16 -9
- data/lib/capybara/helpers.rb +72 -81
- data/lib/capybara/minitest/spec.rb +267 -0
- data/lib/capybara/minitest.rb +385 -0
- data/lib/capybara/node/actions.rb +337 -89
- data/lib/capybara/node/base.rb +50 -32
- data/lib/capybara/node/document.rb +19 -3
- data/lib/capybara/node/document_matchers.rb +22 -24
- data/lib/capybara/node/element.rb +388 -125
- data/lib/capybara/node/finders.rb +231 -121
- data/lib/capybara/node/matchers.rb +503 -217
- data/lib/capybara/node/simple.rb +64 -27
- data/lib/capybara/queries/ancestor_query.rb +27 -0
- data/lib/capybara/queries/base_query.rb +87 -11
- data/lib/capybara/queries/current_path_query.rb +24 -24
- data/lib/capybara/queries/match_query.rb +15 -10
- data/lib/capybara/queries/selector_query.rb +675 -81
- data/lib/capybara/queries/sibling_query.rb +26 -0
- data/lib/capybara/queries/style_query.rb +45 -0
- data/lib/capybara/queries/text_query.rb +88 -20
- data/lib/capybara/queries/title_query.rb +9 -11
- data/lib/capybara/rack_test/browser.rb +63 -39
- data/lib/capybara/rack_test/css_handlers.rb +6 -4
- data/lib/capybara/rack_test/driver.rb +26 -16
- data/lib/capybara/rack_test/errors.rb +6 -0
- data/lib/capybara/rack_test/form.rb +73 -58
- data/lib/capybara/rack_test/node.rb +187 -67
- data/lib/capybara/rails.rb +4 -8
- 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 +142 -14
- data/lib/capybara/rspec/features.rb +17 -42
- data/lib/capybara/rspec/matcher_proxies.rb +82 -0
- 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 +143 -244
- data/lib/capybara/rspec.rb +10 -12
- 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 +102 -0
- data/lib/capybara/selector/definition/button.rb +63 -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 +278 -0
- data/lib/capybara/selector/filter.rb +3 -46
- data/lib/capybara/selector/filter_set.rb +124 -0
- data/lib/capybara/selector/filters/base.rb +77 -0
- data/lib/capybara/selector/filters/expression_filter.rb +22 -0
- data/lib/capybara/selector/filters/locator_filter.rb +29 -0
- data/lib/capybara/selector/filters/node_filter.rb +31 -0
- data/lib/capybara/selector/regexp_disassembler.rb +214 -0
- data/lib/capybara/selector/selector.rb +155 -0
- data/lib/capybara/selector/xpath_extensions.rb +17 -0
- data/lib/capybara/selector.rb +232 -369
- 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 +380 -142
- 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 +528 -97
- 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 +63 -0
- data/lib/capybara/server/checker.rb +44 -0
- data/lib/capybara/server/middleware.rb +71 -0
- data/lib/capybara/server.rb +74 -71
- data/lib/capybara/session/config.rb +126 -0
- data/lib/capybara/session/matchers.rb +44 -27
- data/lib/capybara/session.rb +500 -297
- data/lib/capybara/spec/fixtures/no_extension +1 -0
- 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 +168 -14
- data/lib/capybara/spec/session/accept_alert_spec.rb +37 -14
- data/lib/capybara/spec/session/accept_confirm_spec.rb +7 -6
- data/lib/capybara/spec/session/accept_prompt_spec.rb +38 -10
- data/lib/capybara/spec/session/all_spec.rb +179 -59
- data/lib/capybara/spec/session/ancestor_spec.rb +88 -0
- data/lib/capybara/spec/session/assert_all_of_selectors_spec.rb +140 -0
- data/lib/capybara/spec/session/assert_current_path_spec.rb +75 -0
- 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_spec.rb +258 -0
- data/lib/capybara/spec/session/assert_title_spec.rb +93 -0
- data/lib/capybara/spec/session/attach_file_spec.rb +154 -48
- data/lib/capybara/spec/session/body_spec.rb +12 -13
- data/lib/capybara/spec/session/check_spec.rb +168 -41
- data/lib/capybara/spec/session/choose_spec.rb +75 -23
- data/lib/capybara/spec/session/click_button_spec.rb +243 -175
- data/lib/capybara/spec/session/click_link_or_button_spec.rb +57 -32
- data/lib/capybara/spec/session/click_link_spec.rb +100 -53
- data/lib/capybara/spec/session/current_scope_spec.rb +11 -10
- data/lib/capybara/spec/session/current_url_spec.rb +61 -35
- data/lib/capybara/spec/session/dismiss_confirm_spec.rb +7 -7
- data/lib/capybara/spec/session/dismiss_prompt_spec.rb +5 -4
- data/lib/capybara/spec/session/element/{assert_match_selector.rb → assert_match_selector_spec.rb} +13 -6
- data/lib/capybara/spec/session/element/match_css_spec.rb +21 -7
- data/lib/capybara/spec/session/element/match_xpath_spec.rb +9 -7
- data/lib/capybara/spec/session/element/matches_selector_spec.rb +91 -34
- data/lib/capybara/spec/session/evaluate_async_script_spec.rb +23 -0
- data/lib/capybara/spec/session/evaluate_script_spec.rb +45 -3
- data/lib/capybara/spec/session/execute_script_spec.rb +24 -4
- data/lib/capybara/spec/session/fill_in_spec.rb +166 -64
- data/lib/capybara/spec/session/find_button_spec.rb +37 -18
- data/lib/capybara/spec/session/find_by_id_spec.rb +10 -9
- data/lib/capybara/spec/session/find_field_spec.rb +57 -34
- data/lib/capybara/spec/session/find_link_spec.rb +47 -10
- data/lib/capybara/spec/session/find_spec.rb +290 -144
- data/lib/capybara/spec/session/first_spec.rb +91 -48
- data/lib/capybara/spec/session/frame/frame_title_spec.rb +23 -0
- data/lib/capybara/spec/session/frame/frame_url_spec.rb +23 -0
- data/lib/capybara/spec/session/frame/switch_to_frame_spec.rb +116 -0
- data/lib/capybara/spec/session/frame/within_frame_spec.rb +112 -0
- data/lib/capybara/spec/session/go_back_spec.rb +3 -2
- data/lib/capybara/spec/session/go_forward_spec.rb +3 -2
- data/lib/capybara/spec/session/has_all_selectors_spec.rb +69 -0
- data/lib/capybara/spec/session/has_ancestor_spec.rb +46 -0
- data/lib/capybara/spec/session/has_any_selectors_spec.rb +25 -0
- data/lib/capybara/spec/session/has_button_spec.rb +76 -19
- data/lib/capybara/spec/session/has_css_spec.rb +277 -131
- data/lib/capybara/spec/session/has_current_path_spec.rb +98 -26
- data/lib/capybara/spec/session/has_field_spec.rb +177 -107
- data/lib/capybara/spec/session/has_link_spec.rb +13 -12
- data/lib/capybara/spec/session/has_none_selectors_spec.rb +78 -0
- data/lib/capybara/spec/session/has_select_spec.rb +191 -95
- data/lib/capybara/spec/session/has_selector_spec.rb +128 -64
- data/lib/capybara/spec/session/has_sibling_spec.rb +50 -0
- data/lib/capybara/spec/session/has_table_spec.rb +172 -5
- data/lib/capybara/spec/session/has_text_spec.rb +126 -60
- data/lib/capybara/spec/session/has_title_spec.rb +35 -12
- data/lib/capybara/spec/session/has_xpath_spec.rb +74 -53
- data/lib/capybara/spec/session/{headers.rb → headers_spec.rb} +3 -2
- data/lib/capybara/spec/session/html_spec.rb +14 -6
- data/lib/capybara/spec/session/matches_style_spec.rb +35 -0
- data/lib/capybara/spec/session/node_spec.rb +1028 -131
- data/lib/capybara/spec/session/node_wrapper_spec.rb +39 -0
- data/lib/capybara/spec/session/refresh_spec.rb +34 -0
- data/lib/capybara/spec/session/reset_session_spec.rb +75 -34
- data/lib/capybara/spec/session/{response_code.rb → response_code_spec.rb} +2 -1
- data/lib/capybara/spec/session/save_and_open_page_spec.rb +3 -2
- data/lib/capybara/spec/session/save_and_open_screenshot_spec.rb +11 -15
- data/lib/capybara/spec/session/save_page_spec.rb +42 -55
- data/lib/capybara/spec/session/save_screenshot_spec.rb +16 -14
- 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 +112 -85
- data/lib/capybara/spec/session/selectors_spec.rb +71 -8
- data/lib/capybara/spec/session/sibling_spec.rb +52 -0
- data/lib/capybara/spec/session/text_spec.rb +38 -23
- data/lib/capybara/spec/session/title_spec.rb +17 -5
- data/lib/capybara/spec/session/uncheck_spec.rb +71 -12
- data/lib/capybara/spec/session/unselect_spec.rb +44 -43
- data/lib/capybara/spec/session/visit_spec.rb +99 -32
- data/lib/capybara/spec/session/window/become_closed_spec.rb +33 -29
- data/lib/capybara/spec/session/window/current_window_spec.rb +5 -3
- data/lib/capybara/spec/session/window/open_new_window_spec.rb +5 -3
- data/lib/capybara/spec/session/window/switch_to_window_spec.rb +39 -30
- data/lib/capybara/spec/session/window/window_opened_by_spec.rb +17 -10
- data/lib/capybara/spec/session/window/window_spec.rb +121 -73
- data/lib/capybara/spec/session/window/windows_spec.rb +12 -10
- data/lib/capybara/spec/session/window/within_window_spec.rb +52 -82
- data/lib/capybara/spec/session/within_spec.rb +76 -43
- data/lib/capybara/spec/spec_helper.rb +67 -33
- data/lib/capybara/spec/test_app.rb +85 -36
- data/lib/capybara/spec/views/animated.erb +49 -0
- data/lib/capybara/spec/views/buttons.erb +1 -1
- data/lib/capybara/spec/views/fieldsets.erb +1 -1
- data/lib/capybara/spec/views/form.erb +227 -20
- data/lib/capybara/spec/views/frame_child.erb +10 -2
- data/lib/capybara/spec/views/frame_one.erb +2 -1
- data/lib/capybara/spec/views/frame_parent.erb +2 -2
- data/lib/capybara/spec/views/frame_two.erb +1 -1
- data/lib/capybara/spec/views/header_links.erb +1 -1
- data/lib/capybara/spec/views/host_links.erb +1 -1
- data/lib/capybara/spec/views/initial_alert.erb +10 -0
- data/lib/capybara/spec/views/obscured.erb +47 -0
- data/lib/capybara/spec/views/offset.erb +32 -0
- data/lib/capybara/spec/views/path.erb +1 -1
- 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/postback.erb +1 -1
- data/lib/capybara/spec/views/react.erb +45 -0
- data/lib/capybara/spec/views/scroll.erb +20 -0
- data/lib/capybara/spec/views/spatial.erb +31 -0
- data/lib/capybara/spec/views/tables.erb +69 -2
- data/lib/capybara/spec/views/with_animation.erb +82 -0
- data/lib/capybara/spec/views/with_base_tag.erb +1 -1
- data/lib/capybara/spec/views/with_count.erb +1 -1
- data/lib/capybara/spec/views/with_dragula.erb +24 -0
- data/lib/capybara/spec/views/with_fixed_header_footer.erb +17 -0
- data/lib/capybara/spec/views/with_hover.erb +7 -1
- data/lib/capybara/spec/views/with_hover1.erb +10 -0
- data/lib/capybara/spec/views/with_html.erb +100 -10
- data/lib/capybara/spec/views/with_html5_svg.erb +20 -0
- data/lib/capybara/spec/views/with_html_entities.erb +1 -1
- data/lib/capybara/spec/views/with_jquery_animation.erb +24 -0
- data/lib/capybara/spec/views/with_js.erb +49 -3
- data/lib/capybara/spec/views/with_jstree.erb +26 -0
- data/lib/capybara/spec/views/with_namespace.erb +20 -0
- data/lib/capybara/spec/views/with_scope.erb +1 -1
- data/lib/capybara/spec/views/with_scope_other.erb +6 -0
- data/lib/capybara/spec/views/with_simple_html.erb +1 -1
- data/lib/capybara/spec/views/with_sortable_js.erb +21 -0
- data/lib/capybara/spec/views/with_title.erb +1 -1
- data/lib/capybara/spec/views/with_unload_alert.erb +3 -1
- data/lib/capybara/spec/views/with_windows.erb +7 -1
- data/lib/capybara/spec/views/within_frames.erb +6 -3
- data/lib/capybara/version.rb +2 -1
- data/lib/capybara/window.rb +39 -21
- data/lib/capybara.rb +208 -186
- data/spec/basic_node_spec.rb +52 -39
- data/spec/capybara_spec.rb +72 -50
- data/spec/css_builder_spec.rb +101 -0
- data/spec/css_splitter_spec.rb +38 -0
- data/spec/dsl_spec.rb +81 -61
- data/spec/filter_set_spec.rb +46 -0
- data/spec/fixtures/capybara.csv +1 -0
- data/spec/fixtures/certificate.pem +25 -0
- data/spec/fixtures/key.pem +27 -0
- data/spec/fixtures/selenium_driver_rspec_failure.rb +7 -3
- data/spec/fixtures/selenium_driver_rspec_success.rb +7 -3
- data/spec/minitest_spec.rb +164 -0
- data/spec/minitest_spec_spec.rb +162 -0
- data/spec/per_session_config_spec.rb +68 -0
- data/spec/rack_test_spec.rb +189 -96
- data/spec/regexp_dissassembler_spec.rb +250 -0
- data/spec/result_spec.rb +143 -13
- data/spec/rspec/features_spec.rb +38 -32
- data/spec/rspec/scenarios_spec.rb +9 -7
- data/spec/rspec/shared_spec_matchers.rb +959 -0
- data/spec/rspec/views_spec.rb +9 -3
- data/spec/rspec_matchers_spec.rb +62 -0
- data/spec/rspec_spec.rb +127 -30
- data/spec/sauce_spec_chrome.rb +43 -0
- data/spec/selector_spec.rb +458 -37
- data/spec/selenium_spec_chrome.rb +196 -9
- data/spec/selenium_spec_chrome_remote.rb +100 -0
- data/spec/selenium_spec_edge.rb +47 -0
- data/spec/selenium_spec_firefox.rb +210 -0
- data/spec/selenium_spec_firefox_remote.rb +80 -0
- data/spec/selenium_spec_ie.rb +150 -0
- data/spec/selenium_spec_safari.rb +148 -0
- data/spec/server_spec.rb +200 -101
- data/spec/session_spec.rb +91 -0
- data/spec/shared_selenium_node.rb +83 -0
- data/spec/shared_selenium_session.rb +558 -0
- data/spec/spec_helper.rb +94 -2
- data/spec/xpath_builder_spec.rb +93 -0
- metadata +420 -60
- data/lib/capybara/query.rb +0 -7
- data/lib/capybara/spec/session/assert_current_path.rb +0 -60
- data/lib/capybara/spec/session/assert_selector.rb +0 -148
- data/lib/capybara/spec/session/assert_text.rb +0 -196
- data/lib/capybara/spec/session/assert_title.rb +0 -70
- data/lib/capybara/spec/session/source_spec.rb +0 -0
- data/lib/capybara/spec/session/within_frame_spec.rb +0 -53
- data/spec/rspec/matchers_spec.rb +0 -827
- data/spec/selenium_spec.rb +0 -151
File without changes
|
@@ -1,53 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
Capybara::SpecHelper.spec '#within_frame', :requires => [:frames] do
|
3
|
-
before(:each) do
|
4
|
-
@session.visit('/within_frames')
|
5
|
-
end
|
6
|
-
|
7
|
-
it "should find the div in frameOne" do
|
8
|
-
@session.within_frame("frameOne") do
|
9
|
-
expect(@session.find("//*[@id='divInFrameOne']").text).to eql 'This is the text of divInFrameOne'
|
10
|
-
end
|
11
|
-
end
|
12
|
-
it "should find the div in FrameTwo" do
|
13
|
-
@session.within_frame("frameTwo") do
|
14
|
-
expect(@session.find("//*[@id='divInFrameTwo']").text).to eql 'This is the text of divInFrameTwo'
|
15
|
-
end
|
16
|
-
end
|
17
|
-
it "should find the text div in the main window after finding text in frameOne" do
|
18
|
-
@session.within_frame("frameOne") do
|
19
|
-
expect(@session.find("//*[@id='divInFrameOne']").text).to eql 'This is the text of divInFrameOne'
|
20
|
-
end
|
21
|
-
expect(@session.find("//*[@id='divInMainWindow']").text).to eql 'This is the text for divInMainWindow'
|
22
|
-
end
|
23
|
-
it "should find the text div in the main window after finding text in frameTwo" do
|
24
|
-
@session.within_frame("frameTwo") do
|
25
|
-
expect(@session.find("//*[@id='divInFrameTwo']").text).to eql 'This is the text of divInFrameTwo'
|
26
|
-
end
|
27
|
-
expect(@session.find("//*[@id='divInMainWindow']").text).to eql 'This is the text for divInMainWindow'
|
28
|
-
end
|
29
|
-
it "should return the result of executing the block" do
|
30
|
-
expect(@session.within_frame("frameOne") { "return value" }).to eql "return value"
|
31
|
-
end
|
32
|
-
it "should find the div given Element" do
|
33
|
-
element = @session.find(:id, 'frameOne')
|
34
|
-
@session.within_frame element do
|
35
|
-
expect(@session.find("//*[@id='divInFrameOne']").text).to eql 'This is the text of divInFrameOne'
|
36
|
-
end
|
37
|
-
end
|
38
|
-
it "should find multiple nested frames" do
|
39
|
-
@session.within_frame 'parentFrame' do
|
40
|
-
@session.within_frame 'childFrame' do
|
41
|
-
@session.within_frame 'grandchildFrame1' do end
|
42
|
-
@session.within_frame 'grandchildFrame2' do end
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
46
|
-
it "should reset scope when changing frames" do
|
47
|
-
@session.within(:css, '#divInMainWindow') do
|
48
|
-
@session.within_frame 'parentFrame' do
|
49
|
-
expect(@session.has_selector?(:css, "iframe#childFrame")).to be true
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
data/spec/rspec/matchers_spec.rb
DELETED
@@ -1,827 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
require 'spec_helper'
|
3
|
-
require 'capybara/dsl'
|
4
|
-
require 'capybara/rspec/matchers'
|
5
|
-
|
6
|
-
RSpec.describe Capybara::RSpecMatchers do
|
7
|
-
include Capybara::DSL
|
8
|
-
include Capybara::RSpecMatchers
|
9
|
-
|
10
|
-
describe "have_css matcher" do
|
11
|
-
it "gives proper description" do
|
12
|
-
expect(have_css('h1').description).to eq("have css \"h1\"")
|
13
|
-
end
|
14
|
-
|
15
|
-
context "on a string" do
|
16
|
-
context "with should" do
|
17
|
-
it "passes if has_css? returns true" do
|
18
|
-
expect("<h1>Text</h1>").to have_css('h1')
|
19
|
-
end
|
20
|
-
|
21
|
-
it "fails if has_css? returns false" do
|
22
|
-
expect do
|
23
|
-
expect("<h1>Text</h1>").to have_css('h2')
|
24
|
-
end.to raise_error(/expected to find css "h2" but there were no matches/)
|
25
|
-
end
|
26
|
-
|
27
|
-
it "passes if matched node count equals expected count" do
|
28
|
-
expect("<h1>Text</h1>").to have_css('h1', :count => 1)
|
29
|
-
end
|
30
|
-
|
31
|
-
it "fails if matched node count does not equal expected count" do
|
32
|
-
expect do
|
33
|
-
expect("<h1>Text</h1>").to have_css('h1', count: 2)
|
34
|
-
end.to raise_error("expected to find css \"h1\" 2 times, found 1 match: \"Text\"")
|
35
|
-
end
|
36
|
-
|
37
|
-
it "fails if matched node count is less than expected minimum count" do
|
38
|
-
expect do
|
39
|
-
expect("<h1>Text</h1>").to have_css('p', minimum: 1)
|
40
|
-
end.to raise_error("expected to find css \"p\" at least 1 time but there were no matches")
|
41
|
-
end
|
42
|
-
|
43
|
-
it "fails if matched node count is more than expected maximum count" do
|
44
|
-
expect do
|
45
|
-
expect("<h1>Text</h1><h1>Text</h1><h1>Text</h1>").to have_css('h1', maximum: 2)
|
46
|
-
end.to raise_error('expected to find css "h1" at most 2 times, found 3 matches: "Text", "Text", "Text"')
|
47
|
-
end
|
48
|
-
|
49
|
-
it "fails if matched node count does not belong to expected range" do
|
50
|
-
expect do
|
51
|
-
expect("<h1>Text</h1>").to have_css('h1', between: 2..3)
|
52
|
-
end.to raise_error("expected to find css \"h1\" between 2 and 3 times, found 1 match: \"Text\"")
|
53
|
-
end
|
54
|
-
|
55
|
-
end
|
56
|
-
|
57
|
-
context "with should_not" do
|
58
|
-
it "passes if has_no_css? returns true" do
|
59
|
-
expect("<h1>Text</h1>").not_to have_css('h2')
|
60
|
-
end
|
61
|
-
|
62
|
-
it "fails if has_no_css? returns false" do
|
63
|
-
expect do
|
64
|
-
expect("<h1>Text</h1>").not_to have_css('h1')
|
65
|
-
end.to raise_error(/expected not to find css "h1"/)
|
66
|
-
end
|
67
|
-
|
68
|
-
it "passes if matched node count does not equal expected count" do
|
69
|
-
expect("<h1>Text</h1>").not_to have_css('h1', :count => 2)
|
70
|
-
end
|
71
|
-
|
72
|
-
it "fails if matched node count equals expected count" do
|
73
|
-
expect do
|
74
|
-
expect("<h1>Text</h1>").not_to have_css('h1', :count => 1)
|
75
|
-
end.to raise_error(/expected not to find css "h1"/)
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
|
-
it "supports compounding" do
|
80
|
-
expect("<h1>Text</h1><h2>Text</h2>").to have_css('h1').and have_css('h2')
|
81
|
-
expect("<h1>Text</h1><h2>Text</h2>").to have_css('h3').or have_css('h1')
|
82
|
-
end if RSpec::Version::STRING.to_f >= 3.0
|
83
|
-
end
|
84
|
-
|
85
|
-
context "on a page or node" do
|
86
|
-
before do
|
87
|
-
visit('/with_html')
|
88
|
-
end
|
89
|
-
|
90
|
-
context "with should" do
|
91
|
-
it "passes if has_css? returns true" do
|
92
|
-
expect(page).to have_css('h1')
|
93
|
-
end
|
94
|
-
|
95
|
-
it "fails if has_css? returns false" do
|
96
|
-
expect do
|
97
|
-
expect(page).to have_css('h1#doesnotexist')
|
98
|
-
end.to raise_error(/expected to find css "h1#doesnotexist" but there were no matches/)
|
99
|
-
end
|
100
|
-
end
|
101
|
-
|
102
|
-
context "with should_not" do
|
103
|
-
it "passes if has_no_css? returns true" do
|
104
|
-
expect(page).not_to have_css('h1#doesnotexist')
|
105
|
-
end
|
106
|
-
|
107
|
-
it "fails if has_no_css? returns false" do
|
108
|
-
expect do
|
109
|
-
expect(page).not_to have_css('h1')
|
110
|
-
end.to raise_error(/expected not to find css "h1"/)
|
111
|
-
end
|
112
|
-
end
|
113
|
-
end
|
114
|
-
end
|
115
|
-
|
116
|
-
describe "have_xpath matcher" do
|
117
|
-
it "gives proper description" do
|
118
|
-
expect(have_xpath('//h1').description).to eq("have xpath \"\/\/h1\"")
|
119
|
-
end
|
120
|
-
|
121
|
-
context "on a string" do
|
122
|
-
context "with should" do
|
123
|
-
it "passes if has_xpath? returns true" do
|
124
|
-
expect("<h1>Text</h1>").to have_xpath('//h1')
|
125
|
-
end
|
126
|
-
|
127
|
-
it "fails if has_xpath? returns false" do
|
128
|
-
expect do
|
129
|
-
expect("<h1>Text</h1>").to have_xpath('//h2')
|
130
|
-
end.to raise_error(%r(expected to find xpath "//h2" but there were no matches))
|
131
|
-
end
|
132
|
-
end
|
133
|
-
|
134
|
-
context "with should_not" do
|
135
|
-
it "passes if has_no_xpath? returns true" do
|
136
|
-
expect("<h1>Text</h1>").not_to have_xpath('//h2')
|
137
|
-
end
|
138
|
-
|
139
|
-
it "fails if has_no_xpath? returns false" do
|
140
|
-
expect do
|
141
|
-
expect("<h1>Text</h1>").not_to have_xpath('//h1')
|
142
|
-
end.to raise_error(%r(expected not to find xpath "//h1"))
|
143
|
-
end
|
144
|
-
end
|
145
|
-
|
146
|
-
it "supports compounding" do
|
147
|
-
expect("<h1>Text</h1><h2>Text</h2>").to have_xpath('//h1').and have_xpath('//h2')
|
148
|
-
expect("<h1>Text</h1><h2>Text</h2>").to have_xpath('//h3').or have_xpath('//h1')
|
149
|
-
end if RSpec::Version::STRING.to_f >= 3.0
|
150
|
-
end
|
151
|
-
|
152
|
-
context "on a page or node" do
|
153
|
-
before do
|
154
|
-
visit('/with_html')
|
155
|
-
end
|
156
|
-
|
157
|
-
context "with should" do
|
158
|
-
it "passes if has_xpath? returns true" do
|
159
|
-
expect(page).to have_xpath('//h1')
|
160
|
-
end
|
161
|
-
|
162
|
-
it "fails if has_xpath? returns false" do
|
163
|
-
expect do
|
164
|
-
expect(page).to have_xpath("//h1[@id='doesnotexist']")
|
165
|
-
end.to raise_error(%r(expected to find xpath "//h1\[@id='doesnotexist'\]" but there were no matches))
|
166
|
-
end
|
167
|
-
end
|
168
|
-
|
169
|
-
context "with should_not" do
|
170
|
-
it "passes if has_no_xpath? returns true" do
|
171
|
-
expect(page).not_to have_xpath('//h1[@id="doesnotexist"]')
|
172
|
-
end
|
173
|
-
|
174
|
-
it "fails if has_no_xpath? returns false" do
|
175
|
-
expect do
|
176
|
-
expect(page).not_to have_xpath('//h1')
|
177
|
-
end.to raise_error(%r(expected not to find xpath "//h1"))
|
178
|
-
end
|
179
|
-
end
|
180
|
-
end
|
181
|
-
end
|
182
|
-
|
183
|
-
describe "have_selector matcher" do
|
184
|
-
it "gives proper description" do
|
185
|
-
matcher = have_selector('//h1')
|
186
|
-
expect("<h1>Text</h1>").to matcher
|
187
|
-
expect(matcher.description).to eq("have xpath \"//h1\"")
|
188
|
-
end
|
189
|
-
|
190
|
-
context "on a string" do
|
191
|
-
context "with should" do
|
192
|
-
it "passes if has_selector? returns true" do
|
193
|
-
expect("<h1>Text</h1>").to have_selector('//h1')
|
194
|
-
end
|
195
|
-
|
196
|
-
it "fails if has_selector? returns false" do
|
197
|
-
expect do
|
198
|
-
expect("<h1>Text</h1>").to have_selector('//h2')
|
199
|
-
end.to raise_error(%r(expected to find xpath "//h2" but there were no matches))
|
200
|
-
end
|
201
|
-
end
|
202
|
-
|
203
|
-
context "with should_not" do
|
204
|
-
it "passes if has_no_selector? returns true" do
|
205
|
-
expect("<h1>Text</h1>").not_to have_selector(:css, 'h2')
|
206
|
-
end
|
207
|
-
|
208
|
-
it "fails if has_no_selector? returns false" do
|
209
|
-
expect do
|
210
|
-
expect("<h1>Text</h1>").not_to have_selector(:css, 'h1')
|
211
|
-
end.to raise_error(%r(expected not to find css "h1"))
|
212
|
-
end
|
213
|
-
end
|
214
|
-
end
|
215
|
-
|
216
|
-
context "on a page or node" do
|
217
|
-
before do
|
218
|
-
visit('/with_html')
|
219
|
-
end
|
220
|
-
|
221
|
-
context "with should" do
|
222
|
-
it "passes if has_selector? returns true" do
|
223
|
-
expect(page).to have_selector('//h1', :text => 'test')
|
224
|
-
end
|
225
|
-
|
226
|
-
it "fails if has_selector? returns false" do
|
227
|
-
expect do
|
228
|
-
expect(page).to have_selector("//h1[@id='doesnotexist']")
|
229
|
-
end.to raise_error(%r(expected to find xpath "//h1\[@id='doesnotexist'\]" but there were no matches))
|
230
|
-
end
|
231
|
-
|
232
|
-
it "includes text in error message" do
|
233
|
-
expect do
|
234
|
-
expect(page).to have_selector("//h1", :text => 'wrong text')
|
235
|
-
end.to raise_error(%r(expected to find xpath "//h1" with text "wrong text" but there were no matches))
|
236
|
-
end
|
237
|
-
end
|
238
|
-
|
239
|
-
context "with should_not" do
|
240
|
-
it "passes if has_no_css? returns true" do
|
241
|
-
expect(page).not_to have_selector(:css, 'h1#doesnotexist')
|
242
|
-
end
|
243
|
-
|
244
|
-
it "fails if has_no_selector? returns false" do
|
245
|
-
expect do
|
246
|
-
expect(page).not_to have_selector(:css, 'h1', :text => 'test')
|
247
|
-
end.to raise_error(%r(expected not to find css "h1" with text "test"))
|
248
|
-
end
|
249
|
-
end
|
250
|
-
end
|
251
|
-
|
252
|
-
it "supports compounding" do
|
253
|
-
expect("<h1>Text</h1><h2>Text</h2>").to have_selector('//h1').and have_selector('//h2')
|
254
|
-
expect("<h1>Text</h1><h2>Text</h2>").to have_selector('//h3').or have_selector('//h1')
|
255
|
-
end if RSpec::Version::STRING.to_f >= 3.0
|
256
|
-
end
|
257
|
-
|
258
|
-
describe "have_content matcher" do
|
259
|
-
it "gives proper description" do
|
260
|
-
expect(have_content('Text').description).to eq("text \"Text\"")
|
261
|
-
end
|
262
|
-
|
263
|
-
context "on a string" do
|
264
|
-
context "with should" do
|
265
|
-
it "passes if has_content? returns true" do
|
266
|
-
expect("<h1>Text</h1>").to have_content('Text')
|
267
|
-
end
|
268
|
-
|
269
|
-
it "passes if has_content? returns true using regexp" do
|
270
|
-
expect("<h1>Text</h1>").to have_content(/ext/)
|
271
|
-
end
|
272
|
-
|
273
|
-
it "fails if has_content? returns false" do
|
274
|
-
expect do
|
275
|
-
expect("<h1>Text</h1>").to have_content('No such Text')
|
276
|
-
end.to raise_error(/expected to find text "No such Text" in "Text"/)
|
277
|
-
end
|
278
|
-
end
|
279
|
-
|
280
|
-
context "with should_not" do
|
281
|
-
it "passes if has_no_content? returns true" do
|
282
|
-
expect("<h1>Text</h1>").not_to have_content('No such Text')
|
283
|
-
end
|
284
|
-
|
285
|
-
it "passes because escapes any characters that would have special meaning in a regexp" do
|
286
|
-
expect("<h1>Text</h1>").not_to have_content('.')
|
287
|
-
end
|
288
|
-
|
289
|
-
it "fails if has_no_content? returns false" do
|
290
|
-
expect do
|
291
|
-
expect("<h1>Text</h1>").not_to have_content('Text')
|
292
|
-
end.to raise_error(/expected not to find text "Text" in "Text"/)
|
293
|
-
end
|
294
|
-
end
|
295
|
-
end
|
296
|
-
|
297
|
-
context "on a page or node" do
|
298
|
-
before do
|
299
|
-
visit('/with_html')
|
300
|
-
end
|
301
|
-
|
302
|
-
context "with should" do
|
303
|
-
it "passes if has_content? returns true" do
|
304
|
-
expect(page).to have_content('This is a test')
|
305
|
-
end
|
306
|
-
|
307
|
-
it "passes if has_content? returns true using regexp" do
|
308
|
-
expect(page).to have_content(/test/)
|
309
|
-
end
|
310
|
-
|
311
|
-
it "fails if has_content? returns false" do
|
312
|
-
expect do
|
313
|
-
expect(page).to have_content('No such Text')
|
314
|
-
end.to raise_error(/expected to find text "No such Text" in "(.*)This is a test(.*)"/)
|
315
|
-
end
|
316
|
-
|
317
|
-
context "with default selector CSS" do
|
318
|
-
before { Capybara.default_selector = :css }
|
319
|
-
it "fails if has_content? returns false" do
|
320
|
-
expect do
|
321
|
-
expect(page).to have_content('No such Text')
|
322
|
-
end.to raise_error(/expected to find text "No such Text" in "(.*)This is a test(.*)"/)
|
323
|
-
end
|
324
|
-
after { Capybara.default_selector = :xpath }
|
325
|
-
end
|
326
|
-
end
|
327
|
-
|
328
|
-
context "with should_not" do
|
329
|
-
it "passes if has_no_content? returns true" do
|
330
|
-
expect(page).not_to have_content('No such Text')
|
331
|
-
end
|
332
|
-
|
333
|
-
it "fails if has_no_content? returns false" do
|
334
|
-
expect do
|
335
|
-
expect(page).not_to have_content('This is a test')
|
336
|
-
end.to raise_error(/expected not to find text "This is a test"/)
|
337
|
-
end
|
338
|
-
end
|
339
|
-
end
|
340
|
-
|
341
|
-
it "supports compounding" do
|
342
|
-
expect("<h1>Text</h1><h2>And</h2>").to have_content('Text').and have_content('And')
|
343
|
-
expect("<h1>Text</h1><h2>Or</h2>").to have_content('XYZ').or have_content('Or')
|
344
|
-
end if RSpec::Version::STRING.to_f >= 3.0
|
345
|
-
end
|
346
|
-
|
347
|
-
describe "have_text matcher" do
|
348
|
-
it "gives proper description" do
|
349
|
-
expect(have_text('Text').description).to eq("text \"Text\"")
|
350
|
-
end
|
351
|
-
|
352
|
-
context "on a string" do
|
353
|
-
context "with should" do
|
354
|
-
it "passes if text contains given string" do
|
355
|
-
expect("<h1>Text</h1>").to have_text('Text')
|
356
|
-
end
|
357
|
-
|
358
|
-
it "passes if text matches given regexp" do
|
359
|
-
expect("<h1>Text</h1>").to have_text(/ext/)
|
360
|
-
end
|
361
|
-
|
362
|
-
it "fails if text doesn't contain given string" do
|
363
|
-
expect do
|
364
|
-
expect("<h1>Text</h1>").to have_text('No such Text')
|
365
|
-
end.to raise_error(/expected to find text "No such Text" in "Text"/)
|
366
|
-
end
|
367
|
-
|
368
|
-
it "fails if text doesn't match given regexp" do
|
369
|
-
expect do
|
370
|
-
expect("<h1>Text</h1>").to have_text(/No such Text/)
|
371
|
-
end.to raise_error('expected to find text matching /No such Text/ in "Text"')
|
372
|
-
end
|
373
|
-
|
374
|
-
it "casts Fixnum to string" do
|
375
|
-
expect do
|
376
|
-
expect("<h1>Text</h1>").to have_text(3)
|
377
|
-
end.to raise_error(/expected to find text "3" in "Text"/)
|
378
|
-
end
|
379
|
-
|
380
|
-
it "fails if matched text count does not equal to expected count" do
|
381
|
-
expect do
|
382
|
-
expect("<h1>Text</h1>").to have_text('Text', count: 2)
|
383
|
-
end.to raise_error('expected to find text "Text" 2 times but found 1 time in "Text"')
|
384
|
-
end
|
385
|
-
|
386
|
-
it "fails if matched text count is less than expected minimum count" do
|
387
|
-
expect do
|
388
|
-
expect("<h1>Text</h1>").to have_text('Lorem', minimum: 1)
|
389
|
-
end.to raise_error('expected to find text "Lorem" at least 1 time but found 0 times in "Text"')
|
390
|
-
end
|
391
|
-
|
392
|
-
it "fails if matched text count is more than expected maximum count" do
|
393
|
-
expect do
|
394
|
-
expect("<h1>Text TextText</h1>").to have_text('Text', maximum: 2)
|
395
|
-
end.to raise_error('expected to find text "Text" at most 2 times but found 3 times in "Text TextText"')
|
396
|
-
end
|
397
|
-
|
398
|
-
it "fails if matched text count does not belong to expected range" do
|
399
|
-
expect do
|
400
|
-
expect("<h1>Text</h1>").to have_text('Text', between: 2..3)
|
401
|
-
end.to raise_error('expected to find text "Text" between 2 and 3 times but found 1 time in "Text"')
|
402
|
-
end
|
403
|
-
end
|
404
|
-
|
405
|
-
context "with should_not" do
|
406
|
-
it "passes if text doesn't contain a string" do
|
407
|
-
expect("<h1>Text</h1>").not_to have_text('No such Text')
|
408
|
-
end
|
409
|
-
|
410
|
-
it "passes because escapes any characters that would have special meaning in a regexp" do
|
411
|
-
expect("<h1>Text</h1>").not_to have_text('.')
|
412
|
-
end
|
413
|
-
|
414
|
-
it "fails if text contains a string" do
|
415
|
-
expect do
|
416
|
-
expect("<h1>Text</h1>").not_to have_text('Text')
|
417
|
-
end.to raise_error(/expected not to find text "Text" in "Text"/)
|
418
|
-
end
|
419
|
-
end
|
420
|
-
end
|
421
|
-
|
422
|
-
context "on a page or node" do
|
423
|
-
before do
|
424
|
-
visit('/with_html')
|
425
|
-
end
|
426
|
-
|
427
|
-
context "with should" do
|
428
|
-
it "passes if has_text? returns true" do
|
429
|
-
expect(page).to have_text('This is a test')
|
430
|
-
end
|
431
|
-
|
432
|
-
it "passes if has_text? returns true using regexp" do
|
433
|
-
expect(page).to have_text(/test/)
|
434
|
-
end
|
435
|
-
|
436
|
-
it "can check for all text" do
|
437
|
-
expect(page).to have_text(:all, 'Some of this text is hidden!')
|
438
|
-
end
|
439
|
-
|
440
|
-
it "can check for visible text" do
|
441
|
-
expect(page).to have_text(:visible, 'Some of this text is')
|
442
|
-
expect(page).not_to have_text(:visible, 'Some of this text is hidden!')
|
443
|
-
end
|
444
|
-
|
445
|
-
it "fails if has_text? returns false" do
|
446
|
-
expect do
|
447
|
-
expect(page).to have_text('No such Text')
|
448
|
-
end.to raise_error(/expected to find text "No such Text" in "(.*)This is a test(.*)"/)
|
449
|
-
end
|
450
|
-
|
451
|
-
context "with default selector CSS" do
|
452
|
-
before { Capybara.default_selector = :css }
|
453
|
-
it "fails if has_text? returns false" do
|
454
|
-
expect do
|
455
|
-
expect(page).to have_text('No such Text')
|
456
|
-
end.to raise_error(/expected to find text "No such Text" in "(.*)This is a test(.*)"/)
|
457
|
-
end
|
458
|
-
after { Capybara.default_selector = :xpath }
|
459
|
-
end
|
460
|
-
end
|
461
|
-
|
462
|
-
context "with should_not" do
|
463
|
-
it "passes if has_no_text? returns true" do
|
464
|
-
expect(page).not_to have_text('No such Text')
|
465
|
-
end
|
466
|
-
|
467
|
-
it "fails if has_no_text? returns false" do
|
468
|
-
expect do
|
469
|
-
expect(page).not_to have_text('This is a test')
|
470
|
-
end.to raise_error(/expected not to find text "This is a test"/)
|
471
|
-
end
|
472
|
-
end
|
473
|
-
end
|
474
|
-
|
475
|
-
it "supports compounding" do
|
476
|
-
expect("<h1>Text</h1><h2>And</h2>").to have_text('Text').and have_text('And')
|
477
|
-
expect("<h1>Text</h1><h2>Or</h2>").to have_text('Not here').or have_text('Or')
|
478
|
-
end if RSpec::Version::STRING.to_f >= 3.0
|
479
|
-
end
|
480
|
-
|
481
|
-
describe "have_link matcher" do
|
482
|
-
let(:html) { '<a href="#">Just a link</a><a href="#">Another link</a>' }
|
483
|
-
|
484
|
-
it "gives proper description" do
|
485
|
-
expect(have_link('Just a link').description).to eq("have link \"Just a link\"")
|
486
|
-
end
|
487
|
-
|
488
|
-
it "passes if there is such a button" do
|
489
|
-
expect(html).to have_link('Just a link')
|
490
|
-
end
|
491
|
-
|
492
|
-
it "fails if there is no such button" do
|
493
|
-
expect do
|
494
|
-
expect(html).to have_link('No such Link')
|
495
|
-
end.to raise_error(/expected to find link "No such Link"/)
|
496
|
-
end
|
497
|
-
|
498
|
-
it "supports compounding" do
|
499
|
-
expect(html).to have_link('Just a link').and have_link('Another link')
|
500
|
-
expect(html).to have_link('Not a link').or have_link('Another link')
|
501
|
-
end if RSpec::Version::STRING.to_f >= 3.0
|
502
|
-
end
|
503
|
-
|
504
|
-
describe "have_title matcher" do
|
505
|
-
it "gives proper description" do
|
506
|
-
expect(have_title('Just a title').description).to eq("have title \"Just a title\"")
|
507
|
-
end
|
508
|
-
|
509
|
-
context "on a string" do
|
510
|
-
let(:html) { '<title>Just a title</title>' }
|
511
|
-
|
512
|
-
it "passes if there is such a title" do
|
513
|
-
expect(html).to have_title('Just a title')
|
514
|
-
end
|
515
|
-
|
516
|
-
it "fails if there is no such title" do
|
517
|
-
expect do
|
518
|
-
expect(html).to have_title('No such title')
|
519
|
-
end.to raise_error('expected "Just a title" to include "No such title"')
|
520
|
-
end
|
521
|
-
|
522
|
-
it "fails if title doesn't match regexp" do
|
523
|
-
expect do
|
524
|
-
expect(html).to have_title(/[[:upper:]]+[[:lower:]]+l{2}o/)
|
525
|
-
end.to raise_error('expected "Just a title" to match /[[:upper:]]+[[:lower:]]+l{2}o/')
|
526
|
-
end
|
527
|
-
end
|
528
|
-
|
529
|
-
context "on a page or node" do
|
530
|
-
it "passes if there is such a title" do
|
531
|
-
visit('/with_js')
|
532
|
-
expect(page).to have_title('with_js')
|
533
|
-
end
|
534
|
-
|
535
|
-
it "fails if there is no such title" do
|
536
|
-
visit('/with_js')
|
537
|
-
expect do
|
538
|
-
expect(page).to have_title('No such title')
|
539
|
-
end.to raise_error('expected "with_js" to include "No such title"')
|
540
|
-
end
|
541
|
-
|
542
|
-
context 'with wait' do
|
543
|
-
before(:each) do
|
544
|
-
@session = TestSessions::Selenium
|
545
|
-
@session.visit('/with_js')
|
546
|
-
end
|
547
|
-
|
548
|
-
it 'waits if wait time is more than timeout' do
|
549
|
-
@session.click_link("Change title")
|
550
|
-
using_wait_time 0 do
|
551
|
-
expect(@session).to have_title('changed title', wait: 0.5)
|
552
|
-
end
|
553
|
-
end
|
554
|
-
|
555
|
-
it "doesn't wait if wait time is less than timeout" do
|
556
|
-
@session.click_link("Change title")
|
557
|
-
using_wait_time 0 do
|
558
|
-
expect(@session).not_to have_title('changed title')
|
559
|
-
end
|
560
|
-
end
|
561
|
-
end
|
562
|
-
end
|
563
|
-
|
564
|
-
it "supports compounding" do
|
565
|
-
expect("<title>I compound</title>").to have_title('I dont compound').or have_title('I compound')
|
566
|
-
end if RSpec::Version::STRING.to_f >= 3.0
|
567
|
-
end
|
568
|
-
|
569
|
-
describe "have_current_path matcher" do
|
570
|
-
it "gives proper description" do
|
571
|
-
expect(have_current_path('http://www.example.com').description).to eq("have current path \"http://www.example.com\"")
|
572
|
-
end
|
573
|
-
|
574
|
-
context "on a page or node" do
|
575
|
-
it "passes if there is such a current path" do
|
576
|
-
visit('/with_js')
|
577
|
-
expect(page).to have_current_path('/with_js')
|
578
|
-
end
|
579
|
-
|
580
|
-
it "fails if there is no such current_path" do
|
581
|
-
visit('/with_js')
|
582
|
-
expect do
|
583
|
-
expect(page).to have_current_path('/not_with_js')
|
584
|
-
end.to raise_error('expected "/with_js" to equal "/not_with_js"')
|
585
|
-
end
|
586
|
-
|
587
|
-
context 'with wait' do
|
588
|
-
before(:each) do
|
589
|
-
@session = TestSessions::Selenium
|
590
|
-
@session.visit('/with_js')
|
591
|
-
end
|
592
|
-
|
593
|
-
it 'waits if wait time is more than timeout' do
|
594
|
-
@session.click_link("Change page")
|
595
|
-
using_wait_time 0 do
|
596
|
-
expect(@session).to have_current_path('/with_html', wait: 1)
|
597
|
-
end
|
598
|
-
end
|
599
|
-
|
600
|
-
it "doesn't wait if wait time is less than timeout" do
|
601
|
-
@session.click_link("Change page")
|
602
|
-
using_wait_time 0 do
|
603
|
-
expect(@session).not_to have_current_path('/with_html')
|
604
|
-
end
|
605
|
-
end
|
606
|
-
end
|
607
|
-
end
|
608
|
-
|
609
|
-
it "supports compounding" do
|
610
|
-
visit('/with_html')
|
611
|
-
expect(page).to have_current_path('/not_with_html').or have_current_path('/with_html')
|
612
|
-
end if RSpec::Version::STRING.to_f >= 3.0
|
613
|
-
end
|
614
|
-
|
615
|
-
describe "have_button matcher" do
|
616
|
-
let(:html) { '<button>A button</button><input type="submit" value="Another button"/>' }
|
617
|
-
|
618
|
-
it "gives proper description" do
|
619
|
-
expect(have_button('A button').description).to eq("have button \"A button\"")
|
620
|
-
end
|
621
|
-
|
622
|
-
it "passes if there is such a button" do
|
623
|
-
expect(html).to have_button('A button')
|
624
|
-
end
|
625
|
-
|
626
|
-
it "fails if there is no such button" do
|
627
|
-
expect do
|
628
|
-
expect(html).to have_button('No such Button')
|
629
|
-
end.to raise_error(/expected to find button "No such Button"/)
|
630
|
-
end
|
631
|
-
|
632
|
-
it "supports compounding" do
|
633
|
-
expect(html).to have_button('Not this button').or have_button('A button')
|
634
|
-
end if RSpec::Version::STRING.to_f >= 3.0
|
635
|
-
end
|
636
|
-
|
637
|
-
describe "have_field matcher" do
|
638
|
-
let(:html) { '<p><label>Text field<input type="text" value="some value"/></label></p>' }
|
639
|
-
|
640
|
-
it "gives proper description" do
|
641
|
-
expect(have_field('Text field').description).to eq("have field \"Text field\"")
|
642
|
-
end
|
643
|
-
|
644
|
-
it "gives proper description for a given value" do
|
645
|
-
expect(have_field('Text field', with: 'some value').description).to eq("have field \"Text field\" with value \"some value\"")
|
646
|
-
end
|
647
|
-
|
648
|
-
it "passes if there is such a field" do
|
649
|
-
expect(html).to have_field('Text field')
|
650
|
-
end
|
651
|
-
|
652
|
-
it "passes if there is such a field with value" do
|
653
|
-
expect(html).to have_field('Text field', with: 'some value')
|
654
|
-
end
|
655
|
-
|
656
|
-
it "fails if there is no such field" do
|
657
|
-
expect do
|
658
|
-
expect(html).to have_field('No such Field')
|
659
|
-
end.to raise_error(/expected to find field "No such Field"/)
|
660
|
-
end
|
661
|
-
|
662
|
-
it "fails if there is such field but with false value" do
|
663
|
-
expect do
|
664
|
-
expect(html).to have_field('Text field', with: 'false value')
|
665
|
-
end.to raise_error(/expected to find field "Text field"/)
|
666
|
-
end
|
667
|
-
|
668
|
-
it "treats a given value as a string" do
|
669
|
-
class Foo
|
670
|
-
def to_s
|
671
|
-
"some value"
|
672
|
-
end
|
673
|
-
end
|
674
|
-
expect(html).to have_field('Text field', with: Foo.new)
|
675
|
-
end
|
676
|
-
|
677
|
-
it "supports compounding" do
|
678
|
-
expect(html).to have_field('Not this one').or have_field('Text field')
|
679
|
-
end if RSpec::Version::STRING.to_f >= 3.0
|
680
|
-
end
|
681
|
-
|
682
|
-
describe "have_checked_field matcher" do
|
683
|
-
let(:html) do
|
684
|
-
'<label>it is checked<input type="checkbox" checked="checked"/></label>
|
685
|
-
<label>unchecked field<input type="checkbox"/></label>'
|
686
|
-
end
|
687
|
-
|
688
|
-
it "gives proper description" do
|
689
|
-
expect(have_checked_field('it is checked').description).to eq("have field \"it is checked\" that is checked")
|
690
|
-
end
|
691
|
-
|
692
|
-
context "with should" do
|
693
|
-
it "passes if there is such a field and it is checked" do
|
694
|
-
expect(html).to have_checked_field('it is checked')
|
695
|
-
end
|
696
|
-
|
697
|
-
it "fails if there is such a field but it is not checked" do
|
698
|
-
expect do
|
699
|
-
expect(html).to have_checked_field('unchecked field')
|
700
|
-
end.to raise_error(/expected to find field "unchecked field"/)
|
701
|
-
end
|
702
|
-
|
703
|
-
it "fails if there is no such field" do
|
704
|
-
expect do
|
705
|
-
expect(html).to have_checked_field('no such field')
|
706
|
-
end.to raise_error(/expected to find field "no such field"/)
|
707
|
-
end
|
708
|
-
end
|
709
|
-
|
710
|
-
context "with should not" do
|
711
|
-
it "fails if there is such a field and it is checked" do
|
712
|
-
expect do
|
713
|
-
expect(html).not_to have_checked_field('it is checked')
|
714
|
-
end.to raise_error(/expected not to find field "it is checked"/)
|
715
|
-
end
|
716
|
-
|
717
|
-
it "passes if there is such a field but it is not checked" do
|
718
|
-
expect(html).not_to have_checked_field('unchecked field')
|
719
|
-
end
|
720
|
-
|
721
|
-
it "passes if there is no such field" do
|
722
|
-
expect(html).not_to have_checked_field('no such field')
|
723
|
-
end
|
724
|
-
end
|
725
|
-
|
726
|
-
it "supports compounding" do
|
727
|
-
expect(html).to have_checked_field('not this one').or have_checked_field('it is checked')
|
728
|
-
end if RSpec::Version::STRING.to_f >= 3.0
|
729
|
-
end
|
730
|
-
|
731
|
-
describe "have_unchecked_field matcher" do
|
732
|
-
let(:html) do
|
733
|
-
'<label>it is checked<input type="checkbox" checked="checked"/></label>
|
734
|
-
<label>unchecked field<input type="checkbox"/></label>'
|
735
|
-
end
|
736
|
-
|
737
|
-
it "gives proper description" do
|
738
|
-
expect(have_unchecked_field('unchecked field').description).to eq("have field \"unchecked field\" that is not checked")
|
739
|
-
end
|
740
|
-
|
741
|
-
context "with should" do
|
742
|
-
it "passes if there is such a field and it is not checked" do
|
743
|
-
expect(html).to have_unchecked_field('unchecked field')
|
744
|
-
end
|
745
|
-
|
746
|
-
it "fails if there is such a field but it is checked" do
|
747
|
-
expect do
|
748
|
-
expect(html).to have_unchecked_field('it is checked')
|
749
|
-
end.to raise_error(/expected to find field "it is checked"/)
|
750
|
-
end
|
751
|
-
|
752
|
-
it "fails if there is no such field" do
|
753
|
-
expect do
|
754
|
-
expect(html).to have_unchecked_field('no such field')
|
755
|
-
end.to raise_error(/expected to find field "no such field"/)
|
756
|
-
end
|
757
|
-
end
|
758
|
-
|
759
|
-
context "with should not" do
|
760
|
-
it "fails if there is such a field and it is not checked" do
|
761
|
-
expect do
|
762
|
-
expect(html).not_to have_unchecked_field('unchecked field')
|
763
|
-
end.to raise_error(/expected not to find field "unchecked field"/)
|
764
|
-
end
|
765
|
-
|
766
|
-
it "passes if there is such a field but it is checked" do
|
767
|
-
expect(html).not_to have_unchecked_field('it is checked')
|
768
|
-
end
|
769
|
-
|
770
|
-
it "passes if there is no such field" do
|
771
|
-
expect(html).not_to have_unchecked_field('no such field')
|
772
|
-
end
|
773
|
-
end
|
774
|
-
|
775
|
-
it "supports compounding" do
|
776
|
-
expect(html).to have_unchecked_field('it is checked').or have_unchecked_field('unchecked field')
|
777
|
-
end if RSpec::Version::STRING.to_f >= 3.0
|
778
|
-
end
|
779
|
-
|
780
|
-
describe "have_select matcher" do
|
781
|
-
let(:html) { '<label>Select Box<select></select></label>' }
|
782
|
-
|
783
|
-
it "gives proper description" do
|
784
|
-
expect(have_select('Select Box').description).to eq("have select box \"Select Box\"")
|
785
|
-
end
|
786
|
-
|
787
|
-
it "gives proper description for a given selected value" do
|
788
|
-
expect(have_select('Select Box', selected: 'some value').description).to eq("have select box \"Select Box\" with \"some value\" selected")
|
789
|
-
end
|
790
|
-
|
791
|
-
it "passes if there is such a select" do
|
792
|
-
expect(html).to have_select('Select Box')
|
793
|
-
end
|
794
|
-
|
795
|
-
it "fails if there is no such select" do
|
796
|
-
expect do
|
797
|
-
expect(html).to have_select('No such Select box')
|
798
|
-
end.to raise_error(/expected to find select box "No such Select box"/)
|
799
|
-
end
|
800
|
-
|
801
|
-
it "supports compounding" do
|
802
|
-
expect(html).to have_select('Not this one').or have_select('Select Box')
|
803
|
-
end if RSpec::Version::STRING.to_f >= 3.0
|
804
|
-
end
|
805
|
-
|
806
|
-
describe "have_table matcher" do
|
807
|
-
let(:html) { '<table><caption>Lovely table</caption></table>' }
|
808
|
-
|
809
|
-
it "gives proper description" do
|
810
|
-
expect(have_table('Lovely table').description).to eq("have table \"Lovely table\"")
|
811
|
-
end
|
812
|
-
|
813
|
-
it "passes if there is such a select" do
|
814
|
-
expect(html).to have_table('Lovely table')
|
815
|
-
end
|
816
|
-
|
817
|
-
it "fails if there is no such select" do
|
818
|
-
expect do
|
819
|
-
expect(html).to have_table('No such Table')
|
820
|
-
end.to raise_error(/expected to find table "No such Table"/)
|
821
|
-
end
|
822
|
-
|
823
|
-
it "supports compounding" do
|
824
|
-
expect(html).to have_table('nope').or have_table('Lovely table')
|
825
|
-
end if RSpec::Version::STRING.to_f >= 3.0
|
826
|
-
end
|
827
|
-
end
|