capybara 3.31.0 → 3.34.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/History.md +93 -13
- data/README.md +9 -4
- data/lib/capybara.rb +18 -8
- data/lib/capybara/config.rb +4 -6
- data/lib/capybara/cucumber.rb +1 -1
- data/lib/capybara/driver/base.rb +4 -0
- data/lib/capybara/helpers.rb +25 -1
- data/lib/capybara/minitest.rb +215 -141
- data/lib/capybara/minitest/spec.rb +156 -97
- data/lib/capybara/node/actions.rb +16 -21
- data/lib/capybara/node/element.rb +3 -5
- data/lib/capybara/node/finders.rb +7 -6
- data/lib/capybara/node/matchers.rb +11 -11
- data/lib/capybara/node/simple.rb +5 -1
- data/lib/capybara/queries/ancestor_query.rb +1 -1
- data/lib/capybara/queries/current_path_query.rb +14 -4
- data/lib/capybara/queries/selector_query.rb +16 -10
- data/lib/capybara/queries/sibling_query.rb +1 -1
- data/lib/capybara/queries/style_query.rb +1 -1
- data/lib/capybara/queries/text_query.rb +7 -1
- data/lib/capybara/rack_test/browser.rb +9 -3
- data/lib/capybara/rack_test/driver.rb +1 -0
- data/lib/capybara/rack_test/form.rb +1 -1
- data/lib/capybara/rack_test/node.rb +1 -1
- data/lib/capybara/registration_container.rb +44 -0
- data/lib/capybara/registrations/patches/puma_ssl.rb +3 -1
- data/lib/capybara/registrations/servers.rb +2 -1
- data/lib/capybara/result.rb +8 -8
- data/lib/capybara/rspec.rb +2 -0
- data/lib/capybara/rspec/matcher_proxies.rb +5 -5
- data/lib/capybara/rspec/matchers.rb +7 -6
- data/lib/capybara/rspec/matchers/have_current_path.rb +2 -2
- data/lib/capybara/rspec/matchers/have_text.rb +1 -1
- data/lib/capybara/rspec/matchers/match_style.rb +5 -0
- data/lib/capybara/selector.rb +10 -1
- data/lib/capybara/selector/definition.rb +11 -9
- data/lib/capybara/selector/definition/button.rb +8 -5
- data/lib/capybara/selector/definition/css.rb +1 -1
- data/lib/capybara/selector/definition/datalist_input.rb +1 -1
- data/lib/capybara/selector/definition/element.rb +2 -1
- data/lib/capybara/selector/definition/fillable_field.rb +1 -1
- data/lib/capybara/selector/definition/label.rb +1 -1
- data/lib/capybara/selector/definition/link.rb +8 -0
- data/lib/capybara/selector/definition/select.rb +1 -1
- data/lib/capybara/selector/definition/table.rb +1 -1
- data/lib/capybara/selector/definition/table_row.rb +1 -1
- data/lib/capybara/selector/filter_set.rb +2 -2
- data/lib/capybara/selector/selector.rb +9 -1
- data/lib/capybara/selenium/atoms/getAttribute.min.js +1 -1
- data/lib/capybara/selenium/atoms/src/getAttribute.js +1 -1
- data/lib/capybara/selenium/driver.rb +35 -6
- data/lib/capybara/selenium/driver_specializations/chrome_driver.rb +9 -11
- data/lib/capybara/selenium/driver_specializations/edge_driver.rb +9 -11
- data/lib/capybara/selenium/driver_specializations/firefox_driver.rb +3 -3
- data/lib/capybara/selenium/extensions/find.rb +3 -3
- data/lib/capybara/selenium/extensions/scroll.rb +8 -10
- data/lib/capybara/selenium/node.rb +75 -12
- data/lib/capybara/selenium/nodes/chrome_node.rb +20 -11
- data/lib/capybara/selenium/nodes/firefox_node.rb +2 -2
- data/lib/capybara/selenium/nodes/safari_node.rb +1 -1
- data/lib/capybara/selenium/patches/action_pauser.rb +26 -0
- data/lib/capybara/selenium/patches/atoms.rb +4 -4
- data/lib/capybara/selenium/patches/logs.rb +7 -9
- data/lib/capybara/server/animation_disabler.rb +3 -2
- data/lib/capybara/server/middleware.rb +4 -2
- data/lib/capybara/session.rb +23 -14
- data/lib/capybara/session/config.rb +3 -1
- data/lib/capybara/session/matchers.rb +11 -11
- data/lib/capybara/spec/public/test.js +24 -1
- data/lib/capybara/spec/session/accept_alert_spec.rb +1 -1
- data/lib/capybara/spec/session/check_spec.rb +6 -0
- data/lib/capybara/spec/session/click_button_spec.rb +11 -0
- data/lib/capybara/spec/session/current_url_spec.rb +11 -1
- data/lib/capybara/spec/session/fill_in_spec.rb +9 -0
- data/lib/capybara/spec/session/find_spec.rb +11 -8
- data/lib/capybara/spec/session/has_button_spec.rb +18 -0
- data/lib/capybara/spec/session/has_css_spec.rb +11 -7
- data/lib/capybara/spec/session/has_current_path_spec.rb +15 -2
- data/lib/capybara/spec/session/has_field_spec.rb +16 -0
- data/lib/capybara/spec/session/has_select_spec.rb +4 -4
- data/lib/capybara/spec/session/has_selector_spec.rb +4 -4
- data/lib/capybara/spec/session/has_text_spec.rb +0 -11
- data/lib/capybara/spec/session/matches_style_spec.rb +2 -2
- data/lib/capybara/spec/session/node_spec.rb +76 -29
- data/lib/capybara/spec/session/refresh_spec.rb +1 -0
- data/lib/capybara/spec/session/save_page_spec.rb +4 -4
- data/lib/capybara/spec/session/window/window_spec.rb +7 -7
- data/lib/capybara/spec/spec_helper.rb +13 -14
- data/lib/capybara/spec/test_app.rb +22 -21
- data/lib/capybara/spec/views/form.erb +25 -1
- data/lib/capybara/spec/views/with_animation.erb +8 -0
- data/lib/capybara/spec/views/with_dragula.erb +3 -1
- data/lib/capybara/spec/views/with_html.erb +2 -2
- data/lib/capybara/spec/views/with_js.erb +2 -0
- data/lib/capybara/spec/views/with_sortable_js.erb +1 -1
- data/lib/capybara/version.rb +1 -1
- data/lib/capybara/window.rb +3 -7
- data/spec/basic_node_spec.rb +9 -8
- data/spec/capybara_spec.rb +1 -1
- data/spec/dsl_spec.rb +14 -1
- data/spec/fixtures/selenium_driver_rspec_success.rb +1 -1
- data/spec/minitest_spec.rb +3 -2
- data/spec/rack_test_spec.rb +28 -5
- data/spec/regexp_dissassembler_spec.rb +0 -4
- data/spec/result_spec.rb +38 -31
- data/spec/rspec/features_spec.rb +3 -1
- data/spec/rspec/scenarios_spec.rb +4 -0
- data/spec/rspec/shared_spec_matchers.rb +63 -51
- data/spec/rspec_spec.rb +4 -0
- data/spec/selector_spec.rb +2 -1
- data/spec/selenium_spec_chrome.rb +4 -2
- data/spec/selenium_spec_chrome_remote.rb +2 -0
- data/spec/server_spec.rb +56 -49
- data/spec/shared_selenium_node.rb +18 -0
- data/spec/shared_selenium_session.rb +84 -7
- data/spec/spec_helper.rb +1 -1
- metadata +25 -24
- data/lib/capybara/spec/session/source_spec.rb +0 -0
@@ -60,15 +60,16 @@ module Capybara
|
|
60
60
|
# @param styles [Hash]
|
61
61
|
# @return [Boolean] If the styles match
|
62
62
|
#
|
63
|
-
def matches_style?(styles, **options)
|
63
|
+
def matches_style?(styles = nil, **options)
|
64
|
+
styles, options = options, {} if styles.nil?
|
64
65
|
make_predicate(options) { assert_matches_style(styles, **options) }
|
65
66
|
end
|
66
67
|
|
67
68
|
##
|
68
69
|
# @deprecated Use {#matches_style?} instead.
|
69
70
|
#
|
70
|
-
def has_style?(styles, **options)
|
71
|
-
warn
|
71
|
+
def has_style?(styles = nil, **options)
|
72
|
+
Capybara::Helpers.warn "DEPRECATED: has_style? is deprecated, please use matches_style? : #{Capybara::Helpers.filter_backtrace(caller)}"
|
72
73
|
matches_style?(styles, **options)
|
73
74
|
end
|
74
75
|
|
@@ -122,7 +123,8 @@ module Capybara
|
|
122
123
|
# @param styles [Hash]
|
123
124
|
# @raise [Capybara::ExpectationNotMet] If the element doesn't have the specified styles
|
124
125
|
#
|
125
|
-
def assert_matches_style(styles, **options)
|
126
|
+
def assert_matches_style(styles = nil, **options)
|
127
|
+
styles, options = options, {} if styles.nil?
|
126
128
|
query_args, query_opts = _set_query_session_options(styles, options)
|
127
129
|
query = Capybara::Queries::StyleQuery.new(*query_args, **query_opts)
|
128
130
|
synchronize(query.wait) do
|
@@ -134,7 +136,7 @@ module Capybara
|
|
134
136
|
##
|
135
137
|
# @deprecated Use {#assert_matches_style} instead.
|
136
138
|
#
|
137
|
-
def assert_style(styles, **options)
|
139
|
+
def assert_style(styles = nil, **options)
|
138
140
|
warn 'assert_style is deprecated, please use assert_matches_style instead'
|
139
141
|
assert_matches_style(styles, **options)
|
140
142
|
end
|
@@ -201,12 +203,10 @@ module Capybara
|
|
201
203
|
selector = extract_selector(args)
|
202
204
|
synchronize(wait) do
|
203
205
|
res = args.map do |locator|
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
e.message
|
209
|
-
end
|
206
|
+
assert_selector(selector, locator, options, &optional_filter_block)
|
207
|
+
break nil
|
208
|
+
rescue Capybara::ExpectationNotMet => e
|
209
|
+
e.message
|
210
210
|
end
|
211
211
|
raise Capybara::ExpectationNotMet, res.join(' or ') if res
|
212
212
|
|
data/lib/capybara/node/simple.rb
CHANGED
@@ -100,7 +100,7 @@ module Capybara
|
|
100
100
|
# @param [Boolean] check_ancestors Whether to inherit visibility from ancestors
|
101
101
|
# @return [Boolean] Whether the element is visible
|
102
102
|
#
|
103
|
-
def visible?(check_ancestors = true)
|
103
|
+
def visible?(check_ancestors = true) # rubocop:disable Style/OptionalBooleanParameter
|
104
104
|
return false if (tag_name == 'input') && (native[:type] == 'hidden')
|
105
105
|
return false if tag_name == 'template'
|
106
106
|
|
@@ -148,6 +148,10 @@ module Capybara
|
|
148
148
|
native.has_attribute?('multiple')
|
149
149
|
end
|
150
150
|
|
151
|
+
def readonly?
|
152
|
+
native.has_attribute?('readonly')
|
153
|
+
end
|
154
|
+
|
151
155
|
def synchronize(_seconds = nil)
|
152
156
|
yield # simple nodes don't need to wait
|
153
157
|
end
|
@@ -16,7 +16,7 @@ module Capybara
|
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
19
|
-
def description(applied = false)
|
19
|
+
def description(applied = false) # rubocop:disable Style/OptionalBooleanParameter
|
20
20
|
child_query = @child_node&.instance_variable_get(:@query)
|
21
21
|
desc = super
|
22
22
|
desc += " that is an ancestor of #{child_query.description}" if child_query
|
@@ -6,26 +6,30 @@ module Capybara
|
|
6
6
|
# @api private
|
7
7
|
module Queries
|
8
8
|
class CurrentPathQuery < BaseQuery
|
9
|
-
def initialize(expected_path, **options)
|
9
|
+
def initialize(expected_path, **options, &optional_filter_block)
|
10
10
|
super(options)
|
11
11
|
@expected_path = expected_path
|
12
12
|
@options = {
|
13
13
|
url: !@expected_path.is_a?(Regexp) && !::Addressable::URI.parse(@expected_path || '').hostname.nil?,
|
14
14
|
ignore_query: false
|
15
15
|
}.merge(options)
|
16
|
+
@filter_block = optional_filter_block
|
16
17
|
assert_valid_keys
|
17
18
|
end
|
18
19
|
|
19
20
|
def resolves_for?(session)
|
20
21
|
uri = ::Addressable::URI.parse(session.current_url)
|
21
|
-
|
22
|
-
|
22
|
+
@actual_path = (options[:ignore_query] ? uri&.omit(:query) : uri).yield_self do |u|
|
23
|
+
options[:url] ? u&.to_s : u&.request_uri
|
24
|
+
end
|
23
25
|
|
24
|
-
if @expected_path.is_a? Regexp
|
26
|
+
res = if @expected_path.is_a? Regexp
|
25
27
|
@actual_path.to_s.match?(@expected_path)
|
26
28
|
else
|
27
29
|
::Addressable::URI.parse(@expected_path) == ::Addressable::URI.parse(@actual_path)
|
28
30
|
end
|
31
|
+
|
32
|
+
res && matches_filter_block?(uri)
|
29
33
|
end
|
30
34
|
|
31
35
|
def failure_message
|
@@ -38,6 +42,12 @@ module Capybara
|
|
38
42
|
|
39
43
|
private
|
40
44
|
|
45
|
+
def matches_filter_block?(url)
|
46
|
+
return true unless @filter_block
|
47
|
+
|
48
|
+
@filter_block.call(url)
|
49
|
+
end
|
50
|
+
|
41
51
|
def failure_message_helper(negated = '')
|
42
52
|
verb = @expected_path.is_a?(Regexp) ? 'match' : 'equal'
|
43
53
|
"expected #{@actual_path.inspect}#{negated} to #{verb} #{@expected_path.inspect}"
|
@@ -6,6 +6,7 @@ module Capybara
|
|
6
6
|
module Queries
|
7
7
|
class SelectorQuery < Queries::BaseQuery
|
8
8
|
attr_reader :expression, :selector, :locator, :options
|
9
|
+
|
9
10
|
SPATIAL_KEYS = %i[above below left_of right_of near].freeze
|
10
11
|
VALID_KEYS = SPATIAL_KEYS + COUNT_KEYS +
|
11
12
|
%i[text id class style visible obscured exact exact_text normalize_ws match wait filter_set]
|
@@ -14,6 +15,7 @@ module Capybara
|
|
14
15
|
def initialize(*args,
|
15
16
|
session_options:,
|
16
17
|
enable_aria_label: session_options.enable_aria_label,
|
18
|
+
enable_aria_role: session_options.enable_aria_role,
|
17
19
|
test_id: session_options.test_id,
|
18
20
|
selector_format: nil,
|
19
21
|
order: nil,
|
@@ -30,7 +32,11 @@ module Capybara
|
|
30
32
|
|
31
33
|
@selector = Selector.new(
|
32
34
|
find_selector(args[0].is_a?(Symbol) ? args.shift : args[0]),
|
33
|
-
config: {
|
35
|
+
config: {
|
36
|
+
enable_aria_label: enable_aria_label,
|
37
|
+
enable_aria_role: enable_aria_role,
|
38
|
+
test_id: test_id
|
39
|
+
},
|
34
40
|
format: selector_format
|
35
41
|
)
|
36
42
|
|
@@ -49,7 +55,7 @@ module Capybara
|
|
49
55
|
def name; selector.name; end
|
50
56
|
def label; selector.label || selector.name; end
|
51
57
|
|
52
|
-
def description(only_applied = false)
|
58
|
+
def description(only_applied = false) # rubocop:disable Style/OptionalBooleanParameter
|
53
59
|
desc = +''
|
54
60
|
show_for = show_for_stage(only_applied)
|
55
61
|
|
@@ -89,11 +95,9 @@ module Capybara
|
|
89
95
|
desc << ' that also matches the custom filter block' if @filter_block && show_for[:node]
|
90
96
|
|
91
97
|
desc << " within #{@resolved_node.inspect}" if describe_within?
|
92
|
-
if locator.is_a?(String) && locator.start_with?('#', './/', '//')
|
93
|
-
|
94
|
-
|
95
|
-
"Please see the documentation for acceptable locator values.\n\n"
|
96
|
-
end
|
98
|
+
if locator.is_a?(String) && locator.start_with?('#', './/', '//') && !selector.raw_locator?
|
99
|
+
desc << "\nNote: It appears you may be passing a CSS selector or XPath expression rather than a locator. " \
|
100
|
+
"Please see the documentation for acceptable locator values.\n\n"
|
97
101
|
end
|
98
102
|
desc
|
99
103
|
end
|
@@ -233,13 +237,14 @@ module Capybara
|
|
233
237
|
hints[:styles] = options[:style] if use_default_style_filter?
|
234
238
|
hints[:position] = true if use_spatial_filter?
|
235
239
|
|
236
|
-
|
240
|
+
case selector_format
|
241
|
+
when :css
|
237
242
|
if node.method(:find_css).arity != 1
|
238
243
|
node.find_css(css, **hints)
|
239
244
|
else
|
240
245
|
node.find_css(css)
|
241
246
|
end
|
242
|
-
|
247
|
+
when :xpath
|
243
248
|
if node.method(:find_xpath).arity != 1
|
244
249
|
node.find_xpath(xpath(exact), **hints)
|
245
250
|
else
|
@@ -575,6 +580,7 @@ module Capybara
|
|
575
580
|
|
576
581
|
class Rectangle
|
577
582
|
attr_reader :top, :bottom, :left, :right
|
583
|
+
|
578
584
|
def initialize(position)
|
579
585
|
# rubocop:disable Style/RescueModifier
|
580
586
|
@top = position['top'] rescue position['y']
|
@@ -645,7 +651,7 @@ module Capybara
|
|
645
651
|
|
646
652
|
d = u.dot w
|
647
653
|
e = v.dot w
|
648
|
-
cap_d = (a * c) - (b
|
654
|
+
cap_d = (a * c) - (b**2)
|
649
655
|
sD = tD = cap_d
|
650
656
|
|
651
657
|
# compute the line parameters of the two closest points
|
@@ -15,7 +15,7 @@ module Capybara
|
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
18
|
-
def description(applied = false)
|
18
|
+
def description(applied = false) # rubocop:disable Style/OptionalBooleanParameter
|
19
19
|
desc = super
|
20
20
|
sibling_query = @sibling_node&.instance_variable_get(:@query)
|
21
21
|
desc += " that is a sibling of #{sibling_query.description}" if sibling_query
|
@@ -6,13 +6,15 @@ module Capybara
|
|
6
6
|
class TextQuery < BaseQuery
|
7
7
|
def initialize(type = nil, expected_text, session_options:, **options) # rubocop:disable Style/OptionalArguments
|
8
8
|
@type = type.nil? ? default_type : type
|
9
|
+
raise ArgumentError, "#{@type} is not a valid type for a text query" unless valid_types.include?(@type)
|
10
|
+
|
9
11
|
@options = options
|
10
12
|
super(@options)
|
11
13
|
self.session_options = session_options
|
12
14
|
|
13
15
|
if expected_text.nil? && !exact?
|
14
16
|
warn 'Checking for expected text of nil is confusing and/or pointless since it will always match. '\
|
15
|
-
|
17
|
+
"Please specify a string or regexp instead. #{Capybara::Helpers.filter_backtrace(caller)}"
|
16
18
|
end
|
17
19
|
|
18
20
|
@expected_text = expected_text.is_a?(Regexp) ? expected_text : expected_text.to_s
|
@@ -89,6 +91,10 @@ module Capybara
|
|
89
91
|
COUNT_KEYS + %i[wait exact normalize_ws]
|
90
92
|
end
|
91
93
|
|
94
|
+
def valid_types
|
95
|
+
%i[all visible]
|
96
|
+
end
|
97
|
+
|
92
98
|
def check_visible_text?
|
93
99
|
@type == :visible
|
94
100
|
end
|
@@ -8,6 +8,7 @@ class Capybara::RackTest::Browser
|
|
8
8
|
|
9
9
|
def initialize(driver)
|
10
10
|
@driver = driver
|
11
|
+
@current_fragment = nil
|
11
12
|
end
|
12
13
|
|
13
14
|
def app
|
@@ -30,7 +31,9 @@ class Capybara::RackTest::Browser
|
|
30
31
|
|
31
32
|
def submit(method, path, attributes)
|
32
33
|
path = request_path if path.nil? || path.empty?
|
33
|
-
|
34
|
+
uri = build_uri(path)
|
35
|
+
uri.query = '' if method.to_s.casecmp('get').zero?
|
36
|
+
process_and_follow_redirects(method, uri.to_s, attributes, 'HTTP_REFERER' => current_url)
|
34
37
|
end
|
35
38
|
|
36
39
|
def follow(method, path, **attributes)
|
@@ -40,6 +43,7 @@ class Capybara::RackTest::Browser
|
|
40
43
|
end
|
41
44
|
|
42
45
|
def process_and_follow_redirects(method, path, attributes = {}, env = {})
|
46
|
+
@current_fragment = build_uri(path).fragment
|
43
47
|
process(method, path, attributes, env)
|
44
48
|
|
45
49
|
return unless driver.follow_redirects?
|
@@ -63,7 +67,7 @@ class Capybara::RackTest::Browser
|
|
63
67
|
method = method.downcase
|
64
68
|
new_uri = build_uri(path)
|
65
69
|
@current_scheme, @current_host, @current_port = new_uri.select(:scheme, :host, :port)
|
66
|
-
|
70
|
+
@current_fragment = new_uri.fragment || @current_fragment
|
67
71
|
reset_cache!
|
68
72
|
send(method, new_uri.to_s, attributes, env.merge(options[:headers] || {}))
|
69
73
|
end
|
@@ -81,7 +85,9 @@ class Capybara::RackTest::Browser
|
|
81
85
|
end
|
82
86
|
|
83
87
|
def current_url
|
84
|
-
last_request.url
|
88
|
+
uri = build_uri(last_request.url)
|
89
|
+
uri.fragment = @current_fragment if @current_fragment
|
90
|
+
uri.to_s
|
85
91
|
rescue Rack::Test::Error
|
86
92
|
''
|
87
93
|
end
|
@@ -17,6 +17,7 @@ class Capybara::RackTest::Driver < Capybara::Driver::Base
|
|
17
17
|
def initialize(app, **options)
|
18
18
|
raise ArgumentError, 'rack-test requires a rack application, but none was given' unless app
|
19
19
|
|
20
|
+
super()
|
20
21
|
@app = app
|
21
22
|
@options = DEFAULT_OPTIONS.merge(options)
|
22
23
|
end
|
@@ -6,7 +6,7 @@ class Capybara::RackTest::Form < Capybara::RackTest::Node
|
|
6
6
|
# That check should be based solely on the form element's 'enctype' attribute value,
|
7
7
|
# which should probably be provided to Rack::Test in its non-GET request methods.
|
8
8
|
class NilUploadedFile < Rack::Test::UploadedFile
|
9
|
-
def initialize
|
9
|
+
def initialize # rubocop:disable Lint/MissingSuper
|
10
10
|
@empty_file = Tempfile.new('nil_uploaded_file')
|
11
11
|
@empty_file.close
|
12
12
|
end
|
@@ -15,7 +15,7 @@ class Capybara::RackTest::Node < Capybara::Driver::Node
|
|
15
15
|
end
|
16
16
|
|
17
17
|
def visible_text
|
18
|
-
displayed_text.
|
18
|
+
displayed_text.squeeze(' ')
|
19
19
|
.gsub(/[\ \n]*\n[\ \n]*/, "\n")
|
20
20
|
.gsub(/\A[[:space:]&&[^\u00a0]]+/, '')
|
21
21
|
.gsub(/[[:space:]&&[^\u00a0]]+\z/, '')
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Capybara
|
4
|
+
# @api private
|
5
|
+
class RegistrationContainer
|
6
|
+
def names
|
7
|
+
@registered.keys
|
8
|
+
end
|
9
|
+
|
10
|
+
def [](name)
|
11
|
+
@registered[name]
|
12
|
+
end
|
13
|
+
|
14
|
+
def []=(name, value)
|
15
|
+
Capybara::Helpers.warn 'DEPRECATED: Directly setting drivers/servers is deprecated, please use Capybara.register_driver/register_server instead'
|
16
|
+
@registered[name] = value
|
17
|
+
end
|
18
|
+
|
19
|
+
def method_missing(method_name, *args, **options, &block)
|
20
|
+
if @registered.respond_to?(method_name)
|
21
|
+
Capybara::Helpers.warn "DEPRECATED: Calling '#{method_name}' on the drivers/servers container is deprecated without replacement"
|
22
|
+
# RUBY 2.6 will send an empty hash rather than nothing with **options so fix that
|
23
|
+
return @registered.public_send(method_name, *args, &block) if options.empty?
|
24
|
+
|
25
|
+
return @registered.public_send(method_name, *args, **options, &block)
|
26
|
+
end
|
27
|
+
super
|
28
|
+
end
|
29
|
+
|
30
|
+
def respond_to_missing?(method_name, include_all)
|
31
|
+
@registered.respond_to?(method_name) || super
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
def initialize
|
37
|
+
@registered = {}
|
38
|
+
end
|
39
|
+
|
40
|
+
def register(name, block)
|
41
|
+
@registered[name] = block
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -4,12 +4,14 @@ module Puma
|
|
4
4
|
module MiniSSL
|
5
5
|
class Socket
|
6
6
|
def read_nonblock(size, *_)
|
7
|
+
wait_states = %i[wait_readable wait_writable]
|
8
|
+
|
7
9
|
loop do
|
8
10
|
output = engine_read_all
|
9
11
|
return output if output
|
10
12
|
|
11
13
|
data = @socket.read_nonblock(size, exception: false)
|
12
|
-
raise IO::EAGAINWaitReadable if
|
14
|
+
raise IO::EAGAINWaitReadable if wait_states.include? data
|
13
15
|
return nil if data.nil?
|
14
16
|
|
15
17
|
@engine.inject(data)
|
@@ -7,7 +7,7 @@ end
|
|
7
7
|
Capybara.register_server :webrick do |app, port, host, **options|
|
8
8
|
require 'rack/handler/webrick'
|
9
9
|
options = { Host: host, Port: port, AccessLog: [], Logger: WEBrick::Log.new(nil, 0) }.merge(options)
|
10
|
-
Rack::Handler::WEBrick.run(app, options)
|
10
|
+
Rack::Handler::WEBrick.run(app, **options)
|
11
11
|
end
|
12
12
|
|
13
13
|
Capybara.register_server :puma do |app, port, host, **options|
|
@@ -28,6 +28,7 @@ Capybara.register_server :puma do |app, port, host, **options|
|
|
28
28
|
options = default_options.merge(options)
|
29
29
|
|
30
30
|
conf = Rack::Handler::Puma.config(app, options)
|
31
|
+
conf.clamp
|
31
32
|
events = conf.options[:Silent] ? ::Puma::Events.strings : ::Puma::Events.stdio
|
32
33
|
|
33
34
|
puma_ver = Gem::Version.new(Puma::Const::PUMA_VERSION)
|
data/lib/capybara/result.rb
CHANGED
@@ -39,7 +39,7 @@ module Capybara
|
|
39
39
|
alias index find_index
|
40
40
|
|
41
41
|
def each(&block)
|
42
|
-
return enum_for(:each) unless
|
42
|
+
return enum_for(:each) unless block
|
43
43
|
|
44
44
|
@result_cache.each(&block)
|
45
45
|
loop do
|
@@ -63,6 +63,7 @@ module Capybara
|
|
63
63
|
# idx.max is broken with beginless ranges
|
64
64
|
# idx.end && idx.max # endless range will have end == nil
|
65
65
|
max = idx.end
|
66
|
+
max = nil if max&.negative?
|
66
67
|
max -= 1 if max && idx.exclude_end?
|
67
68
|
max
|
68
69
|
end
|
@@ -90,13 +91,9 @@ module Capybara
|
|
90
91
|
return load_up_to(count + 1) <=> count
|
91
92
|
end
|
92
93
|
|
93
|
-
if min && (min = Integer(min))
|
94
|
-
return -1 if load_up_to(min) < min
|
95
|
-
end
|
94
|
+
return -1 if min && (min = Integer(min)) && (load_up_to(min) < min)
|
96
95
|
|
97
|
-
if max && (max = Integer(max))
|
98
|
-
return 1 if load_up_to(max + 1) > max
|
99
|
-
end
|
96
|
+
return 1 if max && (max = Integer(max)) && (load_up_to(max + 1) > max)
|
100
97
|
|
101
98
|
if between
|
102
99
|
min, max = (between.begin && between.min) || 1, between.end
|
@@ -170,10 +167,13 @@ module Capybara
|
|
170
167
|
@rest ||= @elements - full_results
|
171
168
|
end
|
172
169
|
|
173
|
-
if
|
170
|
+
if RUBY_PLATFORM == 'java'
|
174
171
|
# JRuby < 9.2.8.0 has an issue with lazy enumerators which
|
175
172
|
# causes a concurrency issue with network requests here
|
176
173
|
# https://github.com/jruby/jruby/issues/4212
|
174
|
+
# while JRuby >= 9.2.8.0 leaks threads when using lazy enumerators
|
175
|
+
# https://github.com/teamcapybara/capybara/issues/2349
|
176
|
+
# so disable the use and JRuby users will need to pay a performance penalty
|
177
177
|
def lazy_select_elements(&block)
|
178
178
|
@elements.select(&block).to_enum # non-lazy evaluation
|
179
179
|
end
|