capybara 3.16.1 → 3.33.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.yardopts +1 -0
- data/History.md +321 -0
- data/README.md +51 -60
- data/lib/capybara.rb +71 -114
- data/lib/capybara/config.rb +8 -5
- data/lib/capybara/cucumber.rb +1 -1
- data/lib/capybara/driver/node.rb +15 -3
- data/lib/capybara/dsl.rb +10 -2
- data/lib/capybara/helpers.rb +5 -3
- data/lib/capybara/minitest.rb +242 -141
- data/lib/capybara/minitest/spec.rb +159 -90
- data/lib/capybara/node/actions.rb +85 -74
- data/lib/capybara/node/base.rb +4 -4
- data/lib/capybara/node/document.rb +2 -2
- data/lib/capybara/node/document_matchers.rb +3 -3
- data/lib/capybara/node/element.rb +216 -117
- data/lib/capybara/node/finders.rb +65 -65
- data/lib/capybara/node/matchers.rb +228 -126
- data/lib/capybara/node/simple.rb +9 -4
- data/lib/capybara/queries/ancestor_query.rb +5 -7
- data/lib/capybara/queries/base_query.rb +2 -1
- data/lib/capybara/queries/current_path_query.rb +1 -1
- data/lib/capybara/queries/selector_query.rb +296 -30
- data/lib/capybara/queries/sibling_query.rb +5 -4
- data/lib/capybara/queries/style_query.rb +2 -2
- data/lib/capybara/queries/text_query.rb +13 -1
- data/lib/capybara/queries/title_query.rb +1 -1
- data/lib/capybara/rack_test/browser.rb +7 -2
- data/lib/capybara/rack_test/driver.rb +1 -1
- data/lib/capybara/rack_test/form.rb +1 -1
- data/lib/capybara/rack_test/node.rb +43 -7
- data/lib/capybara/registration_container.rb +44 -0
- data/lib/capybara/registrations/drivers.rb +36 -0
- data/lib/capybara/registrations/patches/puma_ssl.rb +27 -0
- data/lib/capybara/registrations/servers.rb +44 -0
- data/lib/capybara/result.rb +36 -8
- data/lib/capybara/rspec/matcher_proxies.rb +6 -4
- data/lib/capybara/rspec/matchers.rb +100 -63
- data/lib/capybara/rspec/matchers/base.rb +23 -10
- data/lib/capybara/rspec/matchers/count_sugar.rb +37 -0
- data/lib/capybara/rspec/matchers/have_ancestor.rb +28 -0
- data/lib/capybara/rspec/matchers/have_current_path.rb +2 -2
- data/lib/capybara/rspec/matchers/have_selector.rb +16 -8
- data/lib/capybara/rspec/matchers/have_sibling.rb +27 -0
- data/lib/capybara/rspec/matchers/have_text.rb +4 -4
- data/lib/capybara/rspec/matchers/have_title.rb +2 -2
- data/lib/capybara/rspec/matchers/match_selector.rb +3 -3
- data/lib/capybara/rspec/matchers/match_style.rb +2 -2
- data/lib/capybara/rspec/matchers/spatial_sugar.rb +39 -0
- data/lib/capybara/selector.rb +219 -588
- data/lib/capybara/selector/builders/css_builder.rb +10 -6
- data/lib/capybara/selector/builders/xpath_builder.rb +1 -1
- data/lib/capybara/selector/css.rb +4 -2
- data/lib/capybara/selector/definition.rb +277 -0
- data/lib/capybara/selector/definition/button.rb +52 -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 +27 -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/filter_set.rb +13 -9
- data/lib/capybara/selector/filters/base.rb +11 -2
- data/lib/capybara/selector/filters/locator_filter.rb +13 -3
- data/lib/capybara/selector/regexp_disassembler.rb +9 -2
- data/lib/capybara/selector/selector.rb +43 -448
- 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 +125 -56
- data/lib/capybara/selenium/driver_specializations/chrome_driver.rb +73 -17
- data/lib/capybara/selenium/driver_specializations/edge_driver.rb +124 -0
- data/lib/capybara/selenium/driver_specializations/firefox_driver.rb +41 -2
- data/lib/capybara/selenium/driver_specializations/internet_explorer_driver.rb +14 -1
- data/lib/capybara/selenium/driver_specializations/safari_driver.rb +14 -5
- data/lib/capybara/selenium/extensions/file_input_click_emulation.rb +34 -0
- data/lib/capybara/selenium/extensions/find.rb +67 -45
- data/lib/capybara/selenium/extensions/html5_drag.rb +152 -36
- data/lib/capybara/selenium/extensions/modifier_keys_stack.rb +28 -0
- data/lib/capybara/selenium/logger_suppressor.rb +34 -0
- data/lib/capybara/selenium/node.rb +227 -56
- data/lib/capybara/selenium/nodes/chrome_node.rb +93 -8
- data/lib/capybara/selenium/nodes/edge_node.rb +104 -0
- data/lib/capybara/selenium/nodes/firefox_node.rb +37 -59
- data/lib/capybara/selenium/nodes/ie_node.rb +22 -0
- data/lib/capybara/selenium/nodes/safari_node.rb +27 -54
- 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/server.rb +19 -3
- data/lib/capybara/server/animation_disabler.rb +2 -2
- data/lib/capybara/server/checker.rb +6 -2
- data/lib/capybara/server/middleware.rb +23 -13
- data/lib/capybara/session.rb +124 -106
- data/lib/capybara/session/config.rb +12 -10
- data/lib/capybara/session/matchers.rb +6 -6
- data/lib/capybara/spec/public/offset.js +6 -0
- data/lib/capybara/spec/public/test.js +94 -5
- data/lib/capybara/spec/session/all_spec.rb +84 -6
- data/lib/capybara/spec/session/ancestor_spec.rb +5 -0
- data/lib/capybara/spec/session/assert_current_path_spec.rb +5 -2
- data/lib/capybara/spec/session/assert_text_spec.rb +9 -5
- data/lib/capybara/spec/session/attach_file_spec.rb +14 -6
- data/lib/capybara/spec/session/check_spec.rb +10 -4
- data/lib/capybara/spec/session/choose_spec.rb +8 -2
- data/lib/capybara/spec/session/click_button_spec.rb +44 -1
- data/lib/capybara/spec/session/click_link_spec.rb +11 -0
- data/lib/capybara/spec/session/evaluate_script_spec.rb +12 -0
- data/lib/capybara/spec/session/fill_in_spec.rb +37 -2
- data/lib/capybara/spec/session/find_spec.rb +60 -6
- data/lib/capybara/spec/session/first_spec.rb +1 -1
- data/lib/capybara/spec/session/frame/switch_to_frame_spec.rb +14 -1
- data/lib/capybara/spec/session/frame/within_frame_spec.rb +12 -1
- data/lib/capybara/spec/session/has_ancestor_spec.rb +46 -0
- data/lib/capybara/spec/session/has_button_spec.rb +16 -0
- data/lib/capybara/spec/session/has_css_spec.rb +35 -6
- data/lib/capybara/spec/session/has_current_path_spec.rb +6 -4
- data/lib/capybara/spec/session/has_field_spec.rb +34 -0
- data/lib/capybara/spec/session/has_select_spec.rb +32 -4
- data/lib/capybara/spec/session/has_selector_spec.rb +4 -4
- data/lib/capybara/spec/session/has_sibling_spec.rb +50 -0
- data/lib/capybara/spec/session/has_table_spec.rb +51 -5
- data/lib/capybara/spec/session/has_text_spec.rb +47 -0
- data/lib/capybara/spec/session/matches_style_spec.rb +2 -2
- data/lib/capybara/spec/session/node_spec.rb +574 -16
- data/lib/capybara/spec/session/save_and_open_screenshot_spec.rb +2 -2
- data/lib/capybara/spec/session/save_screenshot_spec.rb +4 -4
- data/lib/capybara/spec/session/scroll_spec.rb +1 -1
- data/lib/capybara/spec/session/select_spec.rb +5 -10
- data/lib/capybara/spec/session/selectors_spec.rb +24 -3
- data/lib/capybara/spec/session/uncheck_spec.rb +2 -2
- data/lib/capybara/spec/session/unselect_spec.rb +1 -1
- data/lib/capybara/spec/session/window/window_spec.rb +10 -9
- data/lib/capybara/spec/spec_helper.rb +7 -2
- data/lib/capybara/spec/test_app.rb +26 -21
- data/lib/capybara/spec/views/animated.erb +49 -0
- data/lib/capybara/spec/views/form.erb +25 -4
- data/lib/capybara/spec/views/frame_child.erb +2 -1
- data/lib/capybara/spec/views/frame_one.erb +1 -0
- data/lib/capybara/spec/views/obscured.erb +9 -9
- data/lib/capybara/spec/views/offset.erb +32 -0
- data/lib/capybara/spec/views/react.erb +45 -0
- data/lib/capybara/spec/views/spatial.erb +31 -0
- data/lib/capybara/spec/views/with_animation.erb +29 -1
- data/lib/capybara/spec/views/with_dragula.erb +24 -0
- data/lib/capybara/spec/views/with_html.erb +28 -2
- data/lib/capybara/spec/views/with_js.erb +2 -1
- data/lib/capybara/spec/views/with_jstree.erb +26 -0
- data/lib/capybara/spec/views/with_sortable_js.erb +21 -0
- data/lib/capybara/version.rb +1 -1
- data/lib/capybara/window.rb +10 -10
- data/spec/basic_node_spec.rb +6 -6
- data/spec/capybara_spec.rb +28 -28
- data/spec/dsl_spec.rb +16 -3
- data/spec/filter_set_spec.rb +5 -5
- data/spec/fixtures/selenium_driver_rspec_failure.rb +1 -1
- data/spec/fixtures/selenium_driver_rspec_success.rb +1 -1
- data/spec/minitest_spec.rb +12 -2
- data/spec/minitest_spec_spec.rb +56 -45
- data/spec/rack_test_spec.rb +25 -12
- data/spec/regexp_dissassembler_spec.rb +53 -39
- data/spec/result_spec.rb +50 -54
- data/spec/rspec/features_spec.rb +1 -0
- data/spec/rspec/shared_spec_matchers.rb +78 -62
- data/spec/rspec_spec.rb +5 -5
- data/spec/sauce_spec_chrome.rb +1 -0
- data/spec/selector_spec.rb +26 -16
- data/spec/selenium_spec_chrome.rb +84 -5
- data/spec/selenium_spec_chrome_remote.rb +23 -8
- data/spec/selenium_spec_edge.rb +23 -8
- data/spec/selenium_spec_firefox.rb +16 -21
- data/spec/selenium_spec_firefox_remote.rb +4 -13
- data/spec/selenium_spec_ie.rb +23 -15
- data/spec/selenium_spec_safari.rb +17 -17
- data/spec/server_spec.rb +87 -42
- data/spec/session_spec.rb +11 -4
- data/spec/shared_selenium_node.rb +83 -0
- data/spec/shared_selenium_session.rb +62 -72
- data/spec/spec_helper.rb +43 -5
- metadata +114 -16
data/spec/capybara_spec.rb
CHANGED
@@ -4,20 +4,20 @@ require 'spec_helper'
|
|
4
4
|
|
5
5
|
RSpec.describe Capybara do
|
6
6
|
describe 'default_max_wait_time' do
|
7
|
-
before { @previous_default_time =
|
7
|
+
before { @previous_default_time = described_class.default_max_wait_time }
|
8
8
|
|
9
|
-
after {
|
9
|
+
after { described_class.default_max_wait_time = @previous_default_time } # rubocop:disable RSpec/InstanceVariable
|
10
10
|
|
11
11
|
it 'should be changeable' do
|
12
|
-
expect(
|
13
|
-
|
14
|
-
expect(
|
12
|
+
expect(described_class.default_max_wait_time).not_to eq(5)
|
13
|
+
described_class.default_max_wait_time = 5
|
14
|
+
expect(described_class.default_max_wait_time).to eq(5)
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
18
18
|
describe '.register_driver' do
|
19
19
|
it 'should add a new driver' do
|
20
|
-
|
20
|
+
described_class.register_driver :schmoo do |app|
|
21
21
|
Capybara::RackTest::Driver.new(app)
|
22
22
|
end
|
23
23
|
session = Capybara::Session.new(:schmoo, TestApp)
|
@@ -28,85 +28,85 @@ RSpec.describe Capybara do
|
|
28
28
|
|
29
29
|
describe '.register_server' do
|
30
30
|
it 'should add a new server' do
|
31
|
-
|
31
|
+
described_class.register_server :blob do |_app, _port, _host|
|
32
32
|
# do nothing
|
33
33
|
end
|
34
34
|
|
35
|
-
expect(
|
35
|
+
expect(described_class.servers[:blob]).to be_truthy
|
36
36
|
end
|
37
37
|
end
|
38
38
|
|
39
39
|
describe '.server' do
|
40
40
|
after do
|
41
|
-
|
41
|
+
described_class.server = :default
|
42
42
|
end
|
43
43
|
|
44
44
|
it 'should default to a proc that calls run_default_server' do
|
45
45
|
mock_app = Object.new
|
46
|
-
allow(
|
47
|
-
|
48
|
-
expect(
|
46
|
+
allow(described_class).to receive(:run_default_server).and_return(true)
|
47
|
+
described_class.server.call(mock_app, 8000)
|
48
|
+
expect(described_class).to have_received(:run_default_server).with(mock_app, 8000)
|
49
49
|
end
|
50
50
|
|
51
51
|
it 'should return a custom server proc' do
|
52
52
|
server = ->(_app, _port) {}
|
53
|
-
|
54
|
-
|
55
|
-
expect(
|
53
|
+
described_class.register_server :custom, &server
|
54
|
+
described_class.server = :custom
|
55
|
+
expect(described_class.server).to eq(server)
|
56
56
|
end
|
57
57
|
|
58
58
|
it 'should have :webrick registered' do
|
59
|
-
expect(
|
59
|
+
expect(described_class.servers[:webrick]).not_to be_nil
|
60
60
|
end
|
61
61
|
|
62
62
|
it 'should have :puma registered' do
|
63
|
-
expect(
|
63
|
+
expect(described_class.servers[:puma]).not_to be_nil
|
64
64
|
end
|
65
65
|
end
|
66
66
|
|
67
67
|
describe 'server=' do
|
68
68
|
after do
|
69
|
-
|
69
|
+
described_class.server = :default
|
70
70
|
end
|
71
71
|
|
72
72
|
it 'accepts a proc' do
|
73
73
|
server = ->(_app, _port) {}
|
74
|
-
|
75
|
-
expect(
|
74
|
+
described_class.server = server
|
75
|
+
expect(described_class.server).to eq server
|
76
76
|
end
|
77
77
|
end
|
78
78
|
|
79
79
|
describe 'app_host' do
|
80
80
|
after do
|
81
|
-
|
81
|
+
described_class.app_host = nil
|
82
82
|
end
|
83
83
|
|
84
84
|
it 'should warn if not a valid URL' do
|
85
|
-
expect {
|
85
|
+
expect { described_class.app_host = 'www.example.com' }.to raise_error(ArgumentError, /Capybara\.app_host should be set to a url/)
|
86
86
|
end
|
87
87
|
|
88
88
|
it 'should not warn if a valid URL' do
|
89
|
-
expect {
|
89
|
+
expect { described_class.app_host = 'http://www.example.com' }.not_to raise_error
|
90
90
|
end
|
91
91
|
|
92
92
|
it 'should not warn if nil' do
|
93
|
-
expect {
|
93
|
+
expect { described_class.app_host = nil }.not_to raise_error
|
94
94
|
end
|
95
95
|
end
|
96
96
|
|
97
97
|
describe 'default_host' do
|
98
98
|
around do |test|
|
99
|
-
old_default =
|
99
|
+
old_default = described_class.default_host
|
100
100
|
test.run
|
101
|
-
|
101
|
+
described_class.default_host = old_default
|
102
102
|
end
|
103
103
|
|
104
104
|
it 'should raise if not a valid URL' do
|
105
|
-
expect {
|
105
|
+
expect { described_class.default_host = 'www.example.com' }.to raise_error(ArgumentError, /Capybara\.default_host should be set to a url/)
|
106
106
|
end
|
107
107
|
|
108
108
|
it 'should not warn if a valid URL' do
|
109
|
-
expect {
|
109
|
+
expect { described_class.default_host = 'http://www.example.com' }.not_to raise_error
|
110
110
|
end
|
111
111
|
end
|
112
112
|
end
|
data/spec/dsl_spec.rb
CHANGED
@@ -8,7 +8,7 @@ class TestClass
|
|
8
8
|
end
|
9
9
|
|
10
10
|
Capybara::SpecHelper.run_specs TestClass.new, 'DSL', capybara_skip: %i[
|
11
|
-
js modals screenshot frames windows send_keys server hover about_scheme psc download css driver scroll
|
11
|
+
js modals screenshot frames windows send_keys server hover about_scheme psc download css driver scroll spatial html_validation
|
12
12
|
] do |example|
|
13
13
|
case example.metadata[:full_description]
|
14
14
|
when /has_css\? should support case insensitive :class and :id options/
|
@@ -19,6 +19,10 @@ Capybara::SpecHelper.run_specs TestClass.new, 'DSL', capybara_skip: %i[
|
|
19
19
|
end
|
20
20
|
|
21
21
|
RSpec.describe Capybara::DSL do
|
22
|
+
before do
|
23
|
+
Capybara.use_default_driver
|
24
|
+
end
|
25
|
+
|
22
26
|
after do
|
23
27
|
Capybara.session_name = nil
|
24
28
|
Capybara.default_driver = nil
|
@@ -92,7 +96,7 @@ RSpec.describe Capybara::DSL do
|
|
92
96
|
driver_before_block = Capybara.current_driver
|
93
97
|
begin
|
94
98
|
Capybara.using_driver(:selenium) { raise 'ohnoes!' }
|
95
|
-
rescue Exception # rubocop:disable Lint/RescueException,Lint/
|
99
|
+
rescue Exception # rubocop:disable Lint/RescueException,Lint/SuppressedException
|
96
100
|
end
|
97
101
|
expect(Capybara.current_driver).to eq(driver_before_block)
|
98
102
|
end
|
@@ -208,7 +212,7 @@ RSpec.describe Capybara::DSL do
|
|
208
212
|
Capybara.using_session(:raise) do
|
209
213
|
raise
|
210
214
|
end
|
211
|
-
rescue Exception # rubocop:disable Lint/RescueException,Lint/
|
215
|
+
rescue Exception # rubocop:disable Lint/RescueException,Lint/SuppressedException
|
212
216
|
end
|
213
217
|
expect(Capybara.session_name).to eq(:default)
|
214
218
|
end
|
@@ -238,6 +242,15 @@ RSpec.describe Capybara::DSL do
|
|
238
242
|
end
|
239
243
|
expect(Capybara.current_session).to eq(original_session)
|
240
244
|
end
|
245
|
+
|
246
|
+
it 'should pass the new session if block accepts' do
|
247
|
+
original_session = Capybara.current_session
|
248
|
+
Capybara.using_session(:administrator) do |admin_session, prev_session|
|
249
|
+
expect(admin_session).to be(Capybara.current_session)
|
250
|
+
expect(prev_session).to be(original_session)
|
251
|
+
expect(prev_session).not_to be(admin_session)
|
252
|
+
end
|
253
|
+
end
|
241
254
|
end
|
242
255
|
|
243
256
|
describe '#session_name' do
|
data/spec/filter_set_spec.rb
CHANGED
@@ -4,11 +4,11 @@ require 'spec_helper'
|
|
4
4
|
|
5
5
|
RSpec.describe Capybara::Selector::FilterSet do
|
6
6
|
after do
|
7
|
-
|
7
|
+
described_class.remove(:test)
|
8
8
|
end
|
9
9
|
|
10
10
|
it 'allows node filters' do
|
11
|
-
fs =
|
11
|
+
fs = described_class.add(:test) do
|
12
12
|
node_filter(:node_test, :boolean) { |_node, _value| true }
|
13
13
|
expression_filter(:expression_test, :boolean) { |_expr, _value| true }
|
14
14
|
end
|
@@ -18,7 +18,7 @@ RSpec.describe Capybara::Selector::FilterSet do
|
|
18
18
|
end
|
19
19
|
|
20
20
|
it 'allows expression filters' do
|
21
|
-
fs =
|
21
|
+
fs = described_class.add(:test) do
|
22
22
|
node_filter(:node_test, :boolean) { |_node, _value| true }
|
23
23
|
expression_filter(:expression_test, :boolean) { |_expr, _value| true }
|
24
24
|
end
|
@@ -28,7 +28,7 @@ RSpec.describe Capybara::Selector::FilterSet do
|
|
28
28
|
end
|
29
29
|
|
30
30
|
it 'allows node filter and expression filter with the same name' do
|
31
|
-
fs =
|
31
|
+
fs = described_class.add(:test) do
|
32
32
|
node_filter(:test, :boolean) { |_node, _value| true }
|
33
33
|
expression_filter(:test, :boolean) { |_expr, _value| true }
|
34
34
|
end
|
@@ -37,7 +37,7 @@ RSpec.describe Capybara::Selector::FilterSet do
|
|
37
37
|
end
|
38
38
|
|
39
39
|
it 'allows `filter` as an alias of `node_filter`' do
|
40
|
-
fs =
|
40
|
+
fs = described_class.add(:test) do
|
41
41
|
filter(:node_test, :boolean) { |_node, _value| true }
|
42
42
|
end
|
43
43
|
|
@@ -6,7 +6,7 @@ require 'selenium-webdriver'
|
|
6
6
|
RSpec.describe Capybara::Selenium::Driver do
|
7
7
|
it 'should exit with a non-zero exit status' do
|
8
8
|
options = { browser: (ENV['SELENIUM_BROWSER'] || :firefox).to_sym }
|
9
|
-
browser =
|
9
|
+
browser = described_class.new(TestApp, options).browser
|
10
10
|
expect(browser).to be_truthy
|
11
11
|
expect(true).to eq(false) # rubocop:disable RSpec/ExpectActual
|
12
12
|
end
|
@@ -6,7 +6,7 @@ require 'selenium-webdriver'
|
|
6
6
|
RSpec.describe Capybara::Selenium::Driver do
|
7
7
|
it 'should exit with a zero exit status' do
|
8
8
|
options = { browser: (ENV['SELENIUM_BROWSER'] || :firefox).to_sym }
|
9
|
-
browser =
|
9
|
+
browser = described_class.new(TestApp, options).browser
|
10
10
|
expect(browser).to be_truthy
|
11
11
|
expect(true).to eq(true) # rubocop:disable RSpec/ExpectActual
|
12
12
|
end
|
data/spec/minitest_spec.rb
CHANGED
@@ -16,7 +16,7 @@ class MinitestTest < Minitest::Test
|
|
16
16
|
end
|
17
17
|
|
18
18
|
def test_assert_text
|
19
|
-
assert_text('Form')
|
19
|
+
assert_text('Form', normalize_ws: false)
|
20
20
|
assert_no_text('Not on the page')
|
21
21
|
refute_text('Also Not on the page')
|
22
22
|
end
|
@@ -130,6 +130,16 @@ class MinitestTest < Minitest::Test
|
|
130
130
|
visit('/with_html')
|
131
131
|
assert_matches_style(find(:css, '#second'), display: 'inline')
|
132
132
|
end
|
133
|
+
|
134
|
+
def test_assert_ancestor
|
135
|
+
option = find(:option, 'Finnish')
|
136
|
+
assert_ancestor(option, :css, '#form_locale')
|
137
|
+
end
|
138
|
+
|
139
|
+
def test_assert_sibling
|
140
|
+
option = find(:css, '#form_title').find(:option, 'Mrs')
|
141
|
+
assert_sibling(option, :option, 'Mr')
|
142
|
+
end
|
133
143
|
end
|
134
144
|
|
135
145
|
RSpec.describe 'capybara/minitest' do
|
@@ -148,6 +158,6 @@ RSpec.describe 'capybara/minitest' do
|
|
148
158
|
reporter.start
|
149
159
|
MinitestTest.run reporter, {}
|
150
160
|
reporter.report
|
151
|
-
expect(output.string).to include('
|
161
|
+
expect(output.string).to include('22 runs, 52 assertions, 0 failures, 0 errors, 1 skips')
|
152
162
|
end
|
153
163
|
end
|
data/spec/minitest_spec_spec.rb
CHANGED
@@ -17,114 +17,125 @@ class MinitestSpecTest < Minitest::Spec
|
|
17
17
|
end
|
18
18
|
|
19
19
|
it 'supports text expectations' do
|
20
|
-
page.must_have_text('Form', minimum: 1)
|
21
|
-
page.wont_have_text('Not a form')
|
20
|
+
_(page).must_have_text('Form', minimum: 1)
|
21
|
+
_(page).wont_have_text('Not a form')
|
22
22
|
form = find(:css, 'form', text: 'Title')
|
23
|
-
form.must_have_text('Customer Email')
|
24
|
-
form.wont_have_text('Some other email')
|
23
|
+
_(form).must_have_text('Customer Email')
|
24
|
+
_(form).wont_have_text('Some other email')
|
25
25
|
end
|
26
26
|
|
27
27
|
it 'supports current_path expectations' do
|
28
|
-
page.must_have_current_path('/form')
|
29
|
-
page.wont_have_current_path('/form2')
|
28
|
+
_(page).must_have_current_path('/form')
|
29
|
+
_(page).wont_have_current_path('/form2')
|
30
30
|
end
|
31
31
|
|
32
32
|
it 'supports title expectations' do
|
33
33
|
visit('/with_title')
|
34
|
-
page.must_have_title('Test Title')
|
35
|
-
page.wont_have_title('Not the title')
|
34
|
+
_(page).must_have_title('Test Title')
|
35
|
+
_(page).wont_have_title('Not the title')
|
36
36
|
end
|
37
37
|
|
38
38
|
it 'supports xpath expectations' do
|
39
|
-
page.must_have_xpath('.//input[@id="customer_email"]')
|
40
|
-
page.wont_have_xpath('.//select[@id="not_form_title"]')
|
41
|
-
page.wont_have_xpath('.//input[@id="customer_email"]') { |el| el[:id] == 'not_customer_email' }
|
39
|
+
_(page).must_have_xpath('.//input[@id="customer_email"]')
|
40
|
+
_(page).wont_have_xpath('.//select[@id="not_form_title"]')
|
41
|
+
_(page).wont_have_xpath('.//input[@id="customer_email"]') { |el| el[:id] == 'not_customer_email' }
|
42
42
|
select = find(:select, 'form_title')
|
43
|
-
select.must_have_xpath('.//option[@class="title"]')
|
44
|
-
select.must_have_xpath('.//option', count: 1) { |option| option[:class] != 'title' && !option.disabled? }
|
45
|
-
select.wont_have_xpath('.//input[@id="customer_email"]')
|
43
|
+
_(select).must_have_xpath('.//option[@class="title"]')
|
44
|
+
_(select).must_have_xpath('.//option', count: 1) { |option| option[:class] != 'title' && !option.disabled? }
|
45
|
+
_(select).wont_have_xpath('.//input[@id="customer_email"]')
|
46
46
|
end
|
47
47
|
|
48
48
|
it 'support css expectations' do
|
49
|
-
page.must_have_css('input#customer_email')
|
50
|
-
page.wont_have_css('select#not_form_title')
|
49
|
+
_(page).must_have_css('input#customer_email')
|
50
|
+
_(page).wont_have_css('select#not_form_title')
|
51
51
|
el = find(:select, 'form_title')
|
52
|
-
el.must_have_css('option.title')
|
53
|
-
el.wont_have_css('input#customer_email')
|
52
|
+
_(el).must_have_css('option.title')
|
53
|
+
_(el).wont_have_css('input#customer_email')
|
54
54
|
end
|
55
55
|
|
56
56
|
it 'supports link expectations' do
|
57
57
|
visit('/with_html')
|
58
|
-
page.must_have_link('A link')
|
59
|
-
page.wont_have_link('Not on page')
|
58
|
+
_(page).must_have_link('A link')
|
59
|
+
_(page).wont_have_link('Not on page')
|
60
60
|
end
|
61
61
|
|
62
62
|
it 'supports button expectations' do
|
63
|
-
page.must_have_button('fresh_btn')
|
64
|
-
page.wont_have_button('not_btn')
|
63
|
+
_(page).must_have_button('fresh_btn')
|
64
|
+
_(page).wont_have_button('not_btn')
|
65
65
|
end
|
66
66
|
|
67
67
|
it 'supports field expectations' do
|
68
|
-
page.must_have_field('customer_email')
|
69
|
-
page.wont_have_field('not_on_the_form')
|
68
|
+
_(page).must_have_field('customer_email')
|
69
|
+
_(page).wont_have_field('not_on_the_form')
|
70
70
|
end
|
71
71
|
|
72
72
|
it 'supports select expectations' do
|
73
|
-
page.must_have_select('form_title')
|
74
|
-
page.wont_have_select('not_form_title')
|
73
|
+
_(page).must_have_select('form_title')
|
74
|
+
_(page).wont_have_select('not_form_title')
|
75
75
|
end
|
76
76
|
|
77
77
|
it 'supports checked_field expectations' do
|
78
|
-
page.must_have_checked_field('form_pets_dog')
|
79
|
-
page.wont_have_checked_field('form_pets_cat')
|
78
|
+
_(page).must_have_checked_field('form_pets_dog')
|
79
|
+
_(page).wont_have_checked_field('form_pets_cat')
|
80
80
|
end
|
81
81
|
|
82
82
|
it 'supports unchecked_field expectations' do
|
83
|
-
page.must_have_unchecked_field('form_pets_cat')
|
84
|
-
page.wont_have_unchecked_field('form_pets_dog')
|
83
|
+
_(page).must_have_unchecked_field('form_pets_cat')
|
84
|
+
_(page).wont_have_unchecked_field('form_pets_dog')
|
85
85
|
end
|
86
86
|
|
87
87
|
it 'supports table expectations' do
|
88
88
|
visit('/tables')
|
89
|
-
page.must_have_table('agent_table')
|
90
|
-
page.wont_have_table('not_on_form')
|
89
|
+
_(page).must_have_table('agent_table')
|
90
|
+
_(page).wont_have_table('not_on_form')
|
91
91
|
end
|
92
92
|
|
93
93
|
it 'supports all_of_selectors expectations' do
|
94
|
-
page.must_have_all_of_selectors(:css, 'select#form_other_title', 'input#form_last_name')
|
94
|
+
_(page).must_have_all_of_selectors(:css, 'select#form_other_title', 'input#form_last_name')
|
95
95
|
end
|
96
96
|
|
97
97
|
it 'supports none_of_selectors expectations' do
|
98
|
-
page.must_have_none_of_selectors(:css, 'input#not_on_page', 'input#also_not_on_page')
|
98
|
+
_(page).must_have_none_of_selectors(:css, 'input#not_on_page', 'input#also_not_on_page')
|
99
99
|
end
|
100
100
|
|
101
101
|
it 'supports any_of_selectors expectations' do
|
102
|
-
page.must_have_any_of_selectors(:css, 'select#form_other_title', 'input#not_on_page')
|
102
|
+
_(page).must_have_any_of_selectors(:css, 'select#form_other_title', 'input#not_on_page')
|
103
103
|
end
|
104
104
|
|
105
105
|
it 'supports match_selector expectations' do
|
106
|
-
find(:field, 'customer_email').must_match_selector(:field, 'customer_email')
|
107
|
-
find(:select, 'form_title').wont_match_selector(:field, 'customer_email')
|
106
|
+
_(find(:field, 'customer_email')).must_match_selector(:field, 'customer_email')
|
107
|
+
_(find(:select, 'form_title')).wont_match_selector(:field, 'customer_email')
|
108
108
|
end
|
109
109
|
|
110
110
|
it 'supports match_css expectations' do
|
111
|
-
find(:select, 'form_title').must_match_css('select#form_title')
|
112
|
-
find(:select, 'form_title').wont_match_css('select#form_other_title')
|
111
|
+
_(find(:select, 'form_title')).must_match_css('select#form_title')
|
112
|
+
_(find(:select, 'form_title')).wont_match_css('select#form_other_title')
|
113
113
|
end
|
114
114
|
|
115
115
|
it 'supports match_xpath expectations' do
|
116
|
-
find(:select, 'form_title').must_match_xpath('.//select[@id="form_title"]')
|
117
|
-
find(:select, 'form_title').wont_match_xpath('.//select[@id="not_on_page"]')
|
116
|
+
_(find(:select, 'form_title')).must_match_xpath('.//select[@id="form_title"]')
|
117
|
+
_(find(:select, 'form_title')).wont_match_xpath('.//select[@id="not_on_page"]')
|
118
118
|
end
|
119
119
|
|
120
120
|
it 'handles failures' do
|
121
|
-
page.must_have_select('non_existing_form_title')
|
121
|
+
_(page).must_have_select('non_existing_form_title')
|
122
122
|
end
|
123
123
|
|
124
124
|
it 'supports style expectations' do
|
125
125
|
skip "Rack test doesn't support style" if Capybara.current_driver == :rack_test
|
126
126
|
visit('/with_html')
|
127
|
-
find(:css, '#second').
|
127
|
+
_(find(:css, '#second')).must_have_style('display' => 'inline') # deprecated
|
128
|
+
_(find(:css, '#second')).must_match_style('display' => 'inline')
|
129
|
+
end
|
130
|
+
|
131
|
+
it 'supports ancestor expectations' do
|
132
|
+
option = find(:option, 'Finnish')
|
133
|
+
_(option).must_have_ancestor(:css, '#form_locale')
|
134
|
+
end
|
135
|
+
|
136
|
+
it 'supports sibling expectations' do
|
137
|
+
option = find(:css, '#form_title').find(:option, 'Mrs')
|
138
|
+
_(option).must_have_sibling(:option, 'Mr')
|
128
139
|
end
|
129
140
|
end
|
130
141
|
|
@@ -144,8 +155,8 @@ RSpec.describe 'capybara/minitest/spec' do
|
|
144
155
|
reporter.start
|
145
156
|
MinitestSpecTest.run reporter, {}
|
146
157
|
reporter.report
|
147
|
-
expect(output.string).to include('
|
158
|
+
expect(output.string).to include('22 runs, 44 assertions, 1 failures, 0 errors, 1 skips')
|
148
159
|
# Make sure error messages are displayed
|
149
|
-
expect(output.string).to
|
160
|
+
expect(output.string).to match(/expected to find select box "non_existing_form_title" .*but there were no matches/)
|
150
161
|
end
|
151
162
|
end
|