capybara 2.18.0 → 3.0.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/History.md +26 -1
- data/README.md +12 -12
- data/lib/capybara.rb +13 -25
- data/lib/capybara/config.rb +11 -57
- data/lib/capybara/cucumber.rb +2 -3
- data/lib/capybara/driver/base.rb +5 -16
- data/lib/capybara/driver/node.rb +5 -4
- data/lib/capybara/dsl.rb +1 -0
- data/lib/capybara/helpers.rb +16 -28
- data/lib/capybara/minitest.rb +139 -138
- data/lib/capybara/minitest/spec.rb +15 -14
- data/lib/capybara/node/actions.rb +59 -81
- data/lib/capybara/node/base.rb +11 -18
- data/lib/capybara/node/document.rb +2 -2
- data/lib/capybara/node/document_matchers.rb +8 -8
- data/lib/capybara/node/element.rb +30 -40
- data/lib/capybara/node/finders.rb +62 -70
- data/lib/capybara/node/matchers.rb +48 -71
- data/lib/capybara/node/simple.rb +11 -17
- data/lib/capybara/queries/ancestor_query.rb +4 -6
- data/lib/capybara/queries/base_query.rb +18 -17
- data/lib/capybara/queries/current_path_query.rb +8 -24
- data/lib/capybara/queries/match_query.rb +3 -7
- data/lib/capybara/queries/selector_query.rb +92 -95
- data/lib/capybara/queries/sibling_query.rb +4 -4
- data/lib/capybara/queries/text_query.rb +37 -34
- data/lib/capybara/queries/title_query.rb +8 -11
- data/lib/capybara/rack_test/browser.rb +15 -18
- data/lib/capybara/rack_test/css_handlers.rb +6 -4
- data/lib/capybara/rack_test/driver.rb +6 -10
- data/lib/capybara/rack_test/form.rb +50 -40
- data/lib/capybara/rack_test/node.rb +70 -56
- data/lib/capybara/rails.rb +2 -6
- data/lib/capybara/result.rb +22 -22
- data/lib/capybara/rspec.rb +5 -10
- data/lib/capybara/rspec/compound.rb +5 -10
- data/lib/capybara/rspec/features.rb +17 -48
- data/lib/capybara/rspec/matcher_proxies.rb +31 -15
- data/lib/capybara/rspec/matchers.rb +70 -60
- data/lib/capybara/selector.rb +129 -117
- data/lib/capybara/selector/css.rb +6 -11
- data/lib/capybara/selector/filter.rb +1 -17
- data/lib/capybara/selector/filter_set.rb +17 -14
- data/lib/capybara/selector/filters/base.rb +7 -6
- data/lib/capybara/selector/filters/expression_filter.rb +6 -23
- data/lib/capybara/selector/filters/node_filter.rb +2 -12
- data/lib/capybara/selector/selector.rb +27 -33
- data/lib/capybara/selenium/driver.rb +113 -127
- data/lib/capybara/selenium/node.rb +148 -113
- data/lib/capybara/server.rb +3 -2
- data/lib/capybara/session.rb +137 -223
- data/lib/capybara/session/config.rb +47 -67
- data/lib/capybara/session/matchers.rb +8 -7
- data/lib/capybara/spec/public/test.js +26 -4
- data/lib/capybara/spec/session/accept_alert_spec.rb +1 -0
- data/lib/capybara/spec/session/accept_confirm_spec.rb +3 -2
- data/lib/capybara/spec/session/accept_prompt_spec.rb +1 -0
- data/lib/capybara/spec/session/all_spec.rb +31 -18
- data/lib/capybara/spec/session/ancestor_spec.rb +2 -4
- data/lib/capybara/spec/session/assert_all_of_selectors_spec.rb +6 -5
- data/lib/capybara/spec/session/assert_current_path.rb +12 -11
- data/lib/capybara/spec/session/assert_selector.rb +1 -0
- data/lib/capybara/spec/session/assert_text.rb +18 -17
- data/lib/capybara/spec/session/assert_title.rb +1 -0
- data/lib/capybara/spec/session/attach_file_spec.rb +14 -13
- data/lib/capybara/spec/session/body_spec.rb +1 -0
- data/lib/capybara/spec/session/check_spec.rb +7 -6
- data/lib/capybara/spec/session/choose_spec.rb +5 -4
- data/lib/capybara/spec/session/click_button_spec.rb +20 -28
- data/lib/capybara/spec/session/click_link_or_button_spec.rb +8 -7
- data/lib/capybara/spec/session/click_link_spec.rb +8 -7
- data/lib/capybara/spec/session/current_scope_spec.rb +4 -3
- data/lib/capybara/spec/session/current_url_spec.rb +7 -6
- data/lib/capybara/spec/session/dismiss_confirm_spec.rb +1 -1
- data/lib/capybara/spec/session/dismiss_prompt_spec.rb +1 -0
- data/lib/capybara/spec/session/element/assert_match_selector.rb +1 -1
- data/lib/capybara/spec/session/element/match_xpath_spec.rb +1 -1
- data/lib/capybara/spec/session/element/matches_selector_spec.rb +5 -5
- data/lib/capybara/spec/session/evaluate_async_script_spec.rb +3 -2
- data/lib/capybara/spec/session/evaluate_script_spec.rb +4 -3
- data/lib/capybara/spec/session/execute_script_spec.rb +4 -3
- data/lib/capybara/spec/session/fill_in_spec.rb +6 -5
- data/lib/capybara/spec/session/find_button_spec.rb +4 -3
- data/lib/capybara/spec/session/find_by_id_spec.rb +2 -1
- data/lib/capybara/spec/session/find_field_spec.rb +8 -14
- data/lib/capybara/spec/session/find_link_spec.rb +6 -5
- data/lib/capybara/spec/session/find_spec.rb +37 -31
- data/lib/capybara/spec/session/first_spec.rb +60 -33
- data/lib/capybara/spec/session/frame/switch_to_frame_spec.rb +2 -1
- data/lib/capybara/spec/session/frame/within_frame_spec.rb +9 -16
- data/lib/capybara/spec/session/go_back_spec.rb +1 -0
- data/lib/capybara/spec/session/go_forward_spec.rb +1 -0
- data/lib/capybara/spec/session/has_all_selectors_spec.rb +15 -15
- data/lib/capybara/spec/session/has_button_spec.rb +2 -1
- data/lib/capybara/spec/session/has_css_spec.rb +3 -2
- data/lib/capybara/spec/session/has_current_path_spec.rb +12 -28
- data/lib/capybara/spec/session/has_field_spec.rb +4 -3
- data/lib/capybara/spec/session/has_link_spec.rb +1 -0
- data/lib/capybara/spec/session/has_none_selectors_spec.rb +17 -17
- data/lib/capybara/spec/session/has_select_spec.rb +30 -29
- data/lib/capybara/spec/session/has_selector_spec.rb +5 -4
- data/lib/capybara/spec/session/has_table_spec.rb +2 -1
- data/lib/capybara/spec/session/has_text_spec.rb +6 -5
- data/lib/capybara/spec/session/has_title_spec.rb +1 -0
- data/lib/capybara/spec/session/has_xpath_spec.rb +1 -0
- data/lib/capybara/spec/session/headers.rb +2 -1
- data/lib/capybara/spec/session/html_spec.rb +1 -0
- data/lib/capybara/spec/session/node_spec.rb +91 -56
- data/lib/capybara/spec/session/node_wrapper_spec.rb +36 -0
- data/lib/capybara/spec/session/refresh_spec.rb +4 -2
- data/lib/capybara/spec/session/reset_session_spec.rb +1 -0
- data/lib/capybara/spec/session/response_code.rb +1 -0
- data/lib/capybara/spec/session/save_and_open_page_spec.rb +1 -0
- data/lib/capybara/spec/session/save_and_open_screenshot_spec.rb +6 -11
- data/lib/capybara/spec/session/save_page_spec.rb +1 -17
- data/lib/capybara/spec/session/save_screenshot_spec.rb +1 -1
- data/lib/capybara/spec/session/select_spec.rb +20 -20
- data/lib/capybara/spec/session/selectors_spec.rb +2 -2
- data/lib/capybara/spec/session/sibling_spec.rb +1 -1
- data/lib/capybara/spec/session/text_spec.rb +1 -0
- data/lib/capybara/spec/session/title_spec.rb +1 -1
- data/lib/capybara/spec/session/uncheck_spec.rb +4 -3
- data/lib/capybara/spec/session/unselect_spec.rb +6 -5
- data/lib/capybara/spec/session/visit_spec.rb +9 -3
- data/lib/capybara/spec/session/window/become_closed_spec.rb +2 -1
- data/lib/capybara/spec/session/window/current_window_spec.rb +1 -0
- data/lib/capybara/spec/session/window/open_new_window_spec.rb +1 -0
- data/lib/capybara/spec/session/window/switch_to_window_spec.rb +2 -1
- data/lib/capybara/spec/session/window/window_opened_by_spec.rb +2 -1
- data/lib/capybara/spec/session/window/window_spec.rb +12 -12
- data/lib/capybara/spec/session/window/windows_spec.rb +2 -3
- data/lib/capybara/spec/session/window/within_window_spec.rb +13 -68
- data/lib/capybara/spec/session/within_spec.rb +1 -0
- data/lib/capybara/spec/spec_helper.rb +26 -18
- data/lib/capybara/spec/test_app.rb +8 -9
- data/lib/capybara/spec/views/form.erb +1 -0
- data/lib/capybara/spec/views/with_html.erb +3 -1
- data/lib/capybara/spec/views/within_frames.erb +4 -1
- data/lib/capybara/version.rb +2 -1
- data/lib/capybara/window.rb +6 -10
- data/spec/basic_node_spec.rb +1 -0
- data/spec/capybara_spec.rb +9 -32
- data/spec/dsl_spec.rb +5 -13
- data/spec/filter_set_spec.rb +5 -4
- data/spec/fixtures/selenium_driver_rspec_failure.rb +2 -1
- data/spec/fixtures/selenium_driver_rspec_success.rb +3 -2
- data/spec/minitest_spec.rb +4 -3
- data/spec/minitest_spec_spec.rb +3 -2
- data/spec/per_session_config_spec.rb +9 -8
- data/spec/rack_test_spec.rb +21 -20
- data/spec/result_spec.rb +17 -16
- data/spec/rspec/features_spec.rb +17 -14
- data/spec/rspec/scenarios_spec.rb +5 -7
- data/spec/rspec/shared_spec_matchers.rb +96 -99
- data/spec/rspec/views_spec.rb +2 -1
- data/spec/rspec_matchers_spec.rb +19 -2
- data/spec/rspec_spec.rb +11 -15
- data/spec/selector_spec.rb +5 -6
- data/spec/selenium_spec_chrome.rb +7 -4
- data/spec/selenium_spec_marionette.rb +26 -12
- data/spec/server_spec.rb +33 -33
- data/spec/session_spec.rb +2 -1
- data/spec/shared_selenium_session.rb +27 -21
- data/spec/spec_helper.rb +2 -5
- metadata +66 -87
- data/lib/capybara/query.rb +0 -7
- data/spec/selenium_spec_firefox.rb +0 -68
data/spec/dsl_spec.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
2
3
|
require 'spec_helper'
|
3
4
|
require 'capybara/dsl'
|
4
5
|
|
@@ -6,17 +7,8 @@ class TestClass
|
|
6
7
|
include Capybara::DSL
|
7
8
|
end
|
8
9
|
|
9
|
-
Capybara::SpecHelper.run_specs TestClass.new, "DSL", capybara_skip: [
|
10
|
-
|
11
|
-
:modals,
|
12
|
-
:screenshot,
|
13
|
-
:frames,
|
14
|
-
:windows,
|
15
|
-
:send_keys,
|
16
|
-
:server,
|
17
|
-
:hover,
|
18
|
-
:about_scheme,
|
19
|
-
:psc
|
10
|
+
Capybara::SpecHelper.run_specs TestClass.new, "DSL", capybara_skip: %i[
|
11
|
+
js modals screenshot frames windows send_keys server hover about_scheme psc
|
20
12
|
]
|
21
13
|
|
22
14
|
RSpec.describe Capybara::DSL do
|
@@ -93,7 +85,7 @@ RSpec.describe Capybara::DSL do
|
|
93
85
|
driver_before_block = Capybara.current_driver
|
94
86
|
begin
|
95
87
|
Capybara.using_driver(:selenium) { raise "ohnoes!" }
|
96
|
-
rescue Exception
|
88
|
+
rescue Exception # rubocop:disable Lint/RescueException
|
97
89
|
end
|
98
90
|
expect(Capybara.current_driver).to eq(driver_before_block)
|
99
91
|
end
|
@@ -211,7 +203,7 @@ RSpec.describe Capybara::DSL do
|
|
211
203
|
Capybara.using_session(:raise) do
|
212
204
|
raise
|
213
205
|
end
|
214
|
-
rescue Exception
|
206
|
+
rescue Exception # rubocop:disable Lint/RescueException
|
215
207
|
end
|
216
208
|
expect(Capybara.session_name).to eq(:default)
|
217
209
|
end
|
data/spec/filter_set_spec.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
2
3
|
require 'spec_helper'
|
3
4
|
|
4
5
|
RSpec.describe Capybara::Selector::FilterSet do
|
@@ -8,8 +9,8 @@ RSpec.describe Capybara::Selector::FilterSet do
|
|
8
9
|
|
9
10
|
it "allows node filters" do
|
10
11
|
fs = Capybara::Selector::FilterSet.add(:test) do
|
11
|
-
filter(:node_test, :boolean) { |
|
12
|
-
expression_filter(:expression_test, :boolean) { |
|
12
|
+
filter(:node_test, :boolean) { |_node, _value| true }
|
13
|
+
expression_filter(:expression_test, :boolean) { |_expr, _value| true }
|
13
14
|
end
|
14
15
|
|
15
16
|
expect(fs.node_filters.keys).to include(:node_test)
|
@@ -18,8 +19,8 @@ RSpec.describe Capybara::Selector::FilterSet do
|
|
18
19
|
|
19
20
|
it "allows expression filters" do
|
20
21
|
fs = Capybara::Selector::FilterSet.add(:test) do
|
21
|
-
filter(:node_test, :boolean) { |
|
22
|
-
expression_filter(:expression_test, :boolean) { |
|
22
|
+
filter(:node_test, :boolean) { |_node, _value| true }
|
23
|
+
expression_filter(:expression_test, :boolean) { |_expr, _value| true }
|
23
24
|
end
|
24
25
|
|
25
26
|
expect(fs.expression_filters.keys).to include(:expression_test)
|
@@ -1,12 +1,13 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
2
3
|
require 'spec_helper'
|
3
4
|
require 'selenium-webdriver'
|
4
5
|
|
5
6
|
RSpec.describe Capybara::Selenium::Driver do
|
6
7
|
it "should exit with a non-zero exit status" do
|
7
8
|
options = { browser: (ENV['SELENIUM_BROWSER'] || :firefox).to_sym }
|
8
|
-
options[:desired_capabilities] = Selenium::WebDriver::Remote::Capabilities.firefox(marionette: false) if ENV['LEGACY_FIREFOX']
|
9
9
|
browser = Capybara::Selenium::Driver.new(TestApp, options).browser
|
10
|
+
expect(browser).to be
|
10
11
|
expect(true).to eq(false)
|
11
12
|
end
|
12
13
|
end
|
@@ -1,12 +1,13 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
2
3
|
require 'spec_helper'
|
3
4
|
require 'selenium-webdriver'
|
4
5
|
|
5
6
|
RSpec.describe Capybara::Selenium::Driver do
|
6
7
|
it "should exit with a zero exit status" do
|
7
8
|
options = { browser: (ENV['SELENIUM_BROWSER'] || :firefox).to_sym }
|
8
|
-
|
9
|
-
browser
|
9
|
+
browser = Capybara::Selenium::Driver.new(TestApp, options).browser
|
10
|
+
expect(browser).to be
|
10
11
|
expect(true).to eq(true)
|
11
12
|
end
|
12
13
|
end
|
data/spec/minitest_spec.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
2
3
|
require 'spec_helper'
|
3
4
|
require 'capybara/minitest'
|
4
5
|
|
@@ -37,7 +38,7 @@ class MinitestTest < Minitest::Test
|
|
37
38
|
assert_xpath('.//select[@id="form_title"]')
|
38
39
|
assert_xpath('.//select', count: 1) { |el| el[:id] == "form_title" }
|
39
40
|
assert_no_xpath('.//select[@id="not_form_title"]')
|
40
|
-
assert_no_xpath('.//select') { |el| el[:id] == "not_form_title"}
|
41
|
+
assert_no_xpath('.//select') { |el| el[:id] == "not_form_title" }
|
41
42
|
refute_xpath('.//select[@id="not_form_title"]')
|
42
43
|
end
|
43
44
|
|
@@ -49,13 +50,13 @@ class MinitestTest < Minitest::Test
|
|
49
50
|
def test_assert_link
|
50
51
|
visit('/with_html')
|
51
52
|
assert_link('A link')
|
52
|
-
assert_link(count: 1){ |el| el.text == 'A link'}
|
53
|
+
assert_link(count: 1) { |el| el.text == 'A link' }
|
53
54
|
assert_no_link('Not on page')
|
54
55
|
end
|
55
56
|
|
56
57
|
def test_assert_button
|
57
58
|
assert_button('fresh_btn')
|
58
|
-
assert_button(count: 1){ |el| el[:id] == 'fresh_btn' }
|
59
|
+
assert_button(count: 1) { |el| el[:id] == 'fresh_btn' }
|
59
60
|
assert_no_button('not_btn')
|
60
61
|
end
|
61
62
|
|
data/spec/minitest_spec_spec.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
2
3
|
require 'spec_helper'
|
3
4
|
require 'capybara/minitest'
|
4
5
|
require 'capybara/minitest/spec'
|
@@ -39,7 +40,7 @@ class MinitestSpecTest < Minitest::Spec
|
|
39
40
|
page.wont_have_xpath('.//input[@id="customer_email"]') { |el| el[:id] == "not_customer_email" }
|
40
41
|
select = find(:select, 'form_title')
|
41
42
|
select.must_have_xpath('.//option[@class="title"]')
|
42
|
-
select.must_have_xpath('.//option', count: 1) { |option| option[:class] != 'title' && !option.disabled?}
|
43
|
+
select.must_have_xpath('.//option', count: 1) { |option| option[:class] != 'title' && !option.disabled? }
|
43
44
|
select.wont_have_xpath('.//input[@id="customer_email"]')
|
44
45
|
end
|
45
46
|
|
@@ -129,7 +130,7 @@ RSpec.describe 'capybara/minitest/spec' do
|
|
129
130
|
MinitestSpecTest.run reporter, {}
|
130
131
|
reporter.report
|
131
132
|
expect(output.string).to include("18 runs, 41 assertions, 1 failures, 0 errors, 0 skips")
|
132
|
-
#Make sure error messages are displayed
|
133
|
+
# Make sure error messages are displayed
|
133
134
|
expect(output.string).to include('expected to find visible select box "non_existing_form_title" that is not disabled but there were no matches')
|
134
135
|
end
|
135
136
|
end
|
@@ -1,4 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
2
3
|
require 'spec_helper'
|
3
4
|
require 'capybara/dsl'
|
4
5
|
|
@@ -7,13 +8,13 @@ RSpec.describe Capybara::SessionConfig do
|
|
7
8
|
it "defaults to global session options" do
|
8
9
|
Capybara.threadsafe = true
|
9
10
|
session = Capybara::Session.new(:rack_test, TestApp)
|
10
|
-
[
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
11
|
+
%i[default_host app_host always_include_port run_server
|
12
|
+
default_selector default_max_wait_time ignore_hidden_elements
|
13
|
+
automatic_reload match exact raise_server_errors visible_text_only
|
14
|
+
automatic_label_click enable_aria_label save_path
|
15
|
+
asset_host].each do |m|
|
16
|
+
expect(session.config.public_send(m)).to eq Capybara.public_send(m)
|
17
|
+
end
|
17
18
|
end
|
18
19
|
|
19
20
|
it "doesn't change global session when changed" do
|
@@ -64,4 +65,4 @@ RSpec.describe Capybara::SessionConfig do
|
|
64
65
|
expect { Capybara.threadsafe = true }.to raise_error(/Threadsafe setting cannot be changed once a session is created/)
|
65
66
|
end
|
66
67
|
end
|
67
|
-
end
|
68
|
+
end
|
data/spec/rack_test_spec.rb
CHANGED
@@ -1,20 +1,21 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
2
3
|
require 'spec_helper'
|
3
4
|
|
4
5
|
module TestSessions
|
5
6
|
RackTest = Capybara::Session.new(:rack_test, TestApp)
|
6
7
|
end
|
7
8
|
|
8
|
-
Capybara::SpecHelper.run_specs TestSessions::RackTest, "RackTest", capybara_skip: [
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
9
|
+
Capybara::SpecHelper.run_specs TestSessions::RackTest, "RackTest", capybara_skip: %i[
|
10
|
+
js
|
11
|
+
modals
|
12
|
+
screenshot
|
13
|
+
frames
|
14
|
+
windows
|
15
|
+
send_keys
|
16
|
+
server
|
17
|
+
hover
|
18
|
+
about_scheme
|
18
19
|
]
|
19
20
|
|
20
21
|
RSpec.describe Capybara::Session do
|
@@ -64,10 +65,11 @@ RSpec.describe Capybara::Session do
|
|
64
65
|
|
65
66
|
describe "#fill_in" do
|
66
67
|
it "should warn that :fill_options are not supported" do
|
67
|
-
expect_any_instance_of(Capybara::Node
|
68
|
-
.with("Options passed to
|
68
|
+
expect_any_instance_of(Capybara::RackTest::Node).to receive(:warn)
|
69
|
+
.with("Options passed to Node#set but the RackTest driver doesn't support any - ignoring")
|
69
70
|
@session.visit "/with_html"
|
70
|
-
@session.fill_in 'test_field', with: '
|
71
|
+
@session.fill_in 'test_field', with: 'not_monkey', fill_options: { random: true }
|
72
|
+
expect(@session).to have_field('test_field', with: 'not_monkey')
|
71
73
|
end
|
72
74
|
end
|
73
75
|
|
@@ -132,27 +134,27 @@ RSpec.describe Capybara::RackTest::Driver do
|
|
132
134
|
|
133
135
|
describe ':headers option' do
|
134
136
|
it 'should always set headers' do
|
135
|
-
@driver = Capybara::RackTest::Driver.new(TestApp, headers: {'HTTP_FOO' => 'foobar'})
|
137
|
+
@driver = Capybara::RackTest::Driver.new(TestApp, headers: { 'HTTP_FOO' => 'foobar' })
|
136
138
|
@driver.visit('/get_header')
|
137
139
|
expect(@driver.html).to include('foobar')
|
138
140
|
end
|
139
141
|
|
140
142
|
it 'should keep headers on link clicks' do
|
141
|
-
@driver = Capybara::RackTest::Driver.new(TestApp, headers: {'HTTP_FOO' => 'foobar'})
|
143
|
+
@driver = Capybara::RackTest::Driver.new(TestApp, headers: { 'HTTP_FOO' => 'foobar' })
|
142
144
|
@driver.visit('/header_links')
|
143
145
|
@driver.find_xpath('.//a').first.click
|
144
146
|
expect(@driver.html).to include('foobar')
|
145
147
|
end
|
146
148
|
|
147
149
|
it 'should keep headers on form submit' do
|
148
|
-
@driver = Capybara::RackTest::Driver.new(TestApp, headers: {'HTTP_FOO' => 'foobar'})
|
150
|
+
@driver = Capybara::RackTest::Driver.new(TestApp, headers: { 'HTTP_FOO' => 'foobar' })
|
149
151
|
@driver.visit('/header_links')
|
150
152
|
@driver.find_xpath('.//input').first.click
|
151
153
|
expect(@driver.html).to include('foobar')
|
152
154
|
end
|
153
155
|
|
154
156
|
it 'should keep headers on redirects' do
|
155
|
-
@driver = Capybara::RackTest::Driver.new(TestApp, headers: {'HTTP_FOO' => 'foobar'})
|
157
|
+
@driver = Capybara::RackTest::Driver.new(TestApp, headers: { 'HTTP_FOO' => 'foobar' })
|
156
158
|
@driver.visit('/get_header_via_redirect')
|
157
159
|
expect(@driver.html).to include('foobar')
|
158
160
|
end
|
@@ -218,11 +220,10 @@ module CSSHandlerIncludeTester
|
|
218
220
|
raise 'should never be called'
|
219
221
|
end
|
220
222
|
end
|
221
|
-
include CSSHandlerIncludeTester
|
223
|
+
include CSSHandlerIncludeTester # rubocop:disable Style/MixinUsage
|
222
224
|
|
223
|
-
RSpec.describe
|
225
|
+
RSpec.describe Capybara::RackTest::CSSHandlers do
|
224
226
|
it "should not be extended by global includes" do
|
225
227
|
expect(Capybara::RackTest::CSSHandlers.new).not_to respond_to(:dont_extend_css_handler)
|
226
228
|
end
|
227
229
|
end
|
228
|
-
|
data/spec/result_spec.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
2
3
|
require 'spec_helper'
|
3
4
|
|
4
5
|
RSpec.describe Capybara::Result do
|
@@ -14,7 +15,7 @@ RSpec.describe Capybara::Result do
|
|
14
15
|
end
|
15
16
|
|
16
17
|
let :result do
|
17
|
-
string.all '//li'
|
18
|
+
string.all '//li', minimum: 0 # pass minimum: 0 so lazy evaluation doesn't get triggered yet
|
18
19
|
end
|
19
20
|
|
20
21
|
it "has a length" do
|
@@ -30,7 +31,7 @@ RSpec.describe Capybara::Result do
|
|
30
31
|
end
|
31
32
|
|
32
33
|
it 'can supports values_at method' do
|
33
|
-
expect(result.values_at(0, 2).map(&:text)).to eq(%w
|
34
|
+
expect(result.values_at(0, 2).map(&:text)).to eq(%w[Alpha Gamma])
|
34
35
|
end
|
35
36
|
|
36
37
|
it "can return an element by its index" do
|
@@ -39,7 +40,7 @@ RSpec.describe Capybara::Result do
|
|
39
40
|
end
|
40
41
|
|
41
42
|
it "can be mapped" do
|
42
|
-
expect(result.map(&:text)).to eq(%w
|
43
|
+
expect(result.map(&:text)).to eq(%w[Alpha Beta Gamma Delta])
|
43
44
|
end
|
44
45
|
|
45
46
|
it "can be selected" do
|
@@ -50,7 +51,7 @@ RSpec.describe Capybara::Result do
|
|
50
51
|
|
51
52
|
it "can be reduced" do
|
52
53
|
expect(result.reduce('') do |memo, element|
|
53
|
-
memo
|
54
|
+
memo + element.text[0]
|
54
55
|
end).to eq('ABGD')
|
55
56
|
end
|
56
57
|
|
@@ -66,8 +67,8 @@ RSpec.describe Capybara::Result do
|
|
66
67
|
|
67
68
|
it 'supports all modes of []' do
|
68
69
|
expect(result[1].text).to eq 'Beta'
|
69
|
-
expect(result[0,2].map(&:text)).to eq [
|
70
|
-
expect(result[1..3].map(&:text)).to eq [
|
70
|
+
expect(result[0, 2].map(&:text)).to eq %w[Alpha Beta]
|
71
|
+
expect(result[1..3].map(&:text)).to eq %w[Beta Gamma Delta]
|
71
72
|
expect(result[-1].text).to eq 'Delta'
|
72
73
|
end
|
73
74
|
|
@@ -78,37 +79,37 @@ RSpec.describe Capybara::Result do
|
|
78
79
|
|
79
80
|
it 'should catch invalid element errors during filtering' do
|
80
81
|
allow_any_instance_of(Capybara::Node::Simple).to receive(:text).and_raise(StandardError)
|
81
|
-
allow_any_instance_of(Capybara::Node::Simple).to receive(:session).and_return(double("session", driver: double("driver", invalid_element_errors: [StandardError]
|
82
|
+
allow_any_instance_of(Capybara::Node::Simple).to receive(:session).and_return(double("session", driver: double("driver", invalid_element_errors: [StandardError])))
|
82
83
|
result = string.all('//li', text: 'Alpha')
|
83
84
|
expect(result.size).to eq 0
|
84
85
|
end
|
85
86
|
|
86
87
|
it 'should return non-invalid element errors during filtering' do
|
87
88
|
allow_any_instance_of(Capybara::Node::Simple).to receive(:text).and_raise(StandardError)
|
88
|
-
allow_any_instance_of(Capybara::Node::Simple).to receive(:session).and_return(double("session", driver: double("driver", invalid_element_errors: [ArgumentError]
|
89
|
+
allow_any_instance_of(Capybara::Node::Simple).to receive(:session).and_return(double("session", driver: double("driver", invalid_element_errors: [ArgumentError])))
|
89
90
|
expect do
|
90
91
|
string.all('//li', text: 'Alpha').to_a
|
91
92
|
end.to raise_error(StandardError)
|
92
93
|
end
|
93
94
|
|
94
|
-
#Not a great test but it indirectly tests what is needed
|
95
|
+
# Not a great test but it indirectly tests what is needed
|
95
96
|
it "should evaluate filters lazily" do
|
96
97
|
skip 'JRuby has an issue with lazy enumerator evaluation' if RUBY_PLATFORM == 'java'
|
97
|
-
#Not processed until accessed
|
98
|
+
# Not processed until accessed
|
98
99
|
expect(result.instance_variable_get('@result_cache').size).to be 0
|
99
100
|
|
100
|
-
#Only one retrieved when needed
|
101
|
+
# Only one retrieved when needed
|
101
102
|
result.first
|
102
103
|
expect(result.instance_variable_get('@result_cache').size).to be 1
|
103
104
|
|
104
|
-
#works for indexed access
|
105
|
+
# works for indexed access
|
105
106
|
result[0]
|
106
107
|
expect(result.instance_variable_get('@result_cache').size).to be 1
|
107
108
|
|
108
109
|
result[2]
|
109
110
|
expect(result.instance_variable_get('@result_cache').size).to be 3
|
110
111
|
|
111
|
-
#All cached when converted to array
|
112
|
+
# All cached when converted to array
|
112
113
|
result.to_a
|
113
114
|
expect(result.instance_variable_get('@result_cache').size).to eq 4
|
114
115
|
end
|
@@ -116,7 +117,7 @@ RSpec.describe Capybara::Result do
|
|
116
117
|
context '#each' do
|
117
118
|
it 'lazily evaluates' do
|
118
119
|
skip 'JRuby has an issue with lazy enumerator evaluation' if RUBY_PLATFORM == 'java'
|
119
|
-
results=[]
|
120
|
+
results = []
|
120
121
|
result.each do |el|
|
121
122
|
results << el
|
122
123
|
expect(result.instance_variable_get('@result_cache').size).to eq results.size
|
@@ -132,8 +133,8 @@ RSpec.describe Capybara::Result do
|
|
132
133
|
|
133
134
|
it 'lazily evaluates' do
|
134
135
|
skip 'JRuby has an issue with lazy enumerator evaluation' if RUBY_PLATFORM == 'java'
|
135
|
-
result.each.with_index do |
|
136
|
-
expect(result.instance_variable_get('@result_cache').size).to eq(idx+1)
|
136
|
+
result.each.with_index do |_el, idx|
|
137
|
+
expect(result.instance_variable_get('@result_cache').size).to eq(idx + 1) # 0 indexing
|
137
138
|
end
|
138
139
|
end
|
139
140
|
end
|
data/spec/rspec/features_spec.rb
CHANGED
@@ -1,8 +1,9 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
2
3
|
require 'spec_helper'
|
3
4
|
require 'capybara/rspec'
|
4
5
|
|
5
|
-
RSpec.configuration.before(:each,
|
6
|
+
RSpec.configuration.before(:each, file_path: "./spec/rspec/features_spec.rb") do
|
6
7
|
@in_filtered_hook = true
|
7
8
|
end
|
8
9
|
|
@@ -25,7 +26,7 @@ feature "Capybara's feature DSL" do
|
|
25
26
|
.to eq("Capybara's feature DSL preserves description")
|
26
27
|
end
|
27
28
|
|
28
|
-
scenario "allows driver switching", :
|
29
|
+
scenario "allows driver switching", driver: :selenium do
|
29
30
|
expect(Capybara.current_driver).to eq(:selenium)
|
30
31
|
end
|
31
32
|
|
@@ -71,25 +72,27 @@ feature "given and given! aliases to let and let!" do
|
|
71
72
|
end
|
72
73
|
end
|
73
74
|
|
74
|
-
feature "Capybara's feature DSL with driver", :
|
75
|
+
feature "Capybara's feature DSL with driver", driver: :culerity do
|
75
76
|
scenario "switches driver" do
|
76
77
|
expect(Capybara.current_driver).to eq(:culerity)
|
77
78
|
end
|
78
79
|
end
|
79
80
|
|
80
|
-
if
|
81
|
-
|
82
|
-
|
83
|
-
|
81
|
+
xfeature "if xfeature aliases to pending then" do
|
82
|
+
scenario "this should be 'temporarily disabled with xfeature'" do
|
83
|
+
# dummy
|
84
|
+
end
|
85
|
+
scenario "this also should be 'temporarily disabled with xfeature'" do
|
86
|
+
# dummy
|
84
87
|
end
|
88
|
+
end
|
85
89
|
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
+
ffeature "if ffeature aliases focused tag then" do
|
91
|
+
scenario "scenario inside this feature has metatag focus tag" do |example|
|
92
|
+
expect(example.metadata[:focus]).to eq true
|
93
|
+
end
|
90
94
|
|
91
|
-
|
92
|
-
|
93
|
-
end
|
95
|
+
scenario "other scenarios also has metatag focus tag " do |example|
|
96
|
+
expect(example.metadata[:focus]).to eq true
|
94
97
|
end
|
95
98
|
end
|