Skip to content

Commit a9911e5

Browse files
smortexVietND96
authored andcommitted
[rb] Fix "no anonymous block parameter" in ruby 3.1 (SeleniumHQ#15315)
Fix "no anonymous block parameter" in ruby 3.1 When running on Ruby 3.1.2p20 (shipped with Debian 12), the use of anonymous blocks cause exceptions to be raised. This was fixed in later Ruby versions, but will not be backported to the version of Ruby shipped by Debian 12 nor the versions or ruby shipped with all Debian derivative. Explicitly name blocks to avoid triggering this issue with affected versions of Ruby. While here, also adjust the rubocop configuration to detect this issue and mandate the use of explicitly named blocks. Signed-off-by: Romain Tartière <[email protected]> Co-authored-by: Viet Nguyen Duc <[email protected]>
1 parent 5e651ba commit a9911e5

File tree

10 files changed

+28
-25
lines changed

10 files changed

+28
-25
lines changed

Diff for: rb/.rubocop.yml

+3
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ Metrics/PerceivedComplexity:
7575
- 'lib/selenium/webdriver/common/local_driver.rb'
7676
- 'lib/selenium/webdriver/common/logger.rb'
7777

78+
Naming/BlockForwarding:
79+
EnforcedStyle: explicit
80+
7881
Naming/FileName:
7982
Exclude:
8083
- 'lib/selenium-webdriver.rb'

Diff for: rb/lib/selenium/server.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -122,15 +122,15 @@ def available_assets
122122
end
123123
end
124124

125-
def net_http_start(address, &)
125+
def net_http_start(address, &block)
126126
http_proxy = ENV.fetch('http_proxy', nil) || ENV.fetch('HTTP_PROXY', nil)
127127
if http_proxy
128128
http_proxy = "http://#{http_proxy}" unless http_proxy.start_with?('http://')
129129
uri = URI.parse(http_proxy)
130130

131-
Net::HTTP.start(address, nil, uri.host, uri.port, &)
131+
Net::HTTP.start(address, nil, uri.host, uri.port, &block)
132132
else
133-
Net::HTTP.start(address, use_ssl: true, &)
133+
Net::HTTP.start(address, use_ssl: true, &block)
134134
end
135135
end
136136

Diff for: rb/lib/selenium/webdriver/bidi.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ def callbacks
4343
@ws.callbacks
4444
end
4545

46-
def add_callback(event, &)
47-
@ws.add_callback(event, &)
46+
def add_callback(event, &block)
47+
@ws.add_callback(event, &block)
4848
end
4949

5050
def remove_callback(event, id)

Diff for: rb/lib/selenium/webdriver/bidi/log_inspector.rb

+4-4
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ def on_javascript_exception(&block)
7979
end
8080
end
8181

82-
def on_log(filter_by = nil, &)
82+
def on_log(filter_by = nil, &block)
8383
unless filter_by.nil?
8484
check_valid_filter(filter_by)
8585

@@ -89,14 +89,14 @@ def on_log(filter_by = nil, &)
8989
return
9090
end
9191

92-
on(:entry_added, &)
92+
on(:entry_added, &block)
9393
end
9494

9595
private
9696

97-
def on(event, &)
97+
def on(event, &block)
9898
event = EVENTS[event] if event.is_a?(Symbol)
99-
@bidi.add_callback("log.#{event}", &)
99+
@bidi.add_callback("log.#{event}", &block)
100100
end
101101

102102
def check_valid_filter(filter_by)

Diff for: rb/lib/selenium/webdriver/bidi/network.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -128,9 +128,9 @@ def set_cache_behavior(behavior, *contexts)
128128
@bidi.send_cmd('network.setCacheBehavior', cacheBehavior: behavior, contexts: contexts)
129129
end
130130

131-
def on(event, &)
131+
def on(event, &block)
132132
event = EVENTS[event] if event.is_a?(Symbol)
133-
@bidi.add_callback(event, &)
133+
@bidi.add_callback(event, &block)
134134
@bidi.session.subscribe(event)
135135
end
136136
end # Network

Diff for: rb/lib/selenium/webdriver/common/driver_extensions/has_network_interception.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ module HasNetworkInterception
5959
# @yieldparam [Proc] continue block which proceeds with the request and optionally yields response
6060
#
6161

62-
def intercept(&)
62+
def intercept(&block)
6363
if browser == :firefox
6464
WebDriver.logger.deprecate(
6565
'Driver#intercept on Firefox',
@@ -68,7 +68,7 @@ def intercept(&)
6868
)
6969
end
7070
@interceptor ||= DevTools::NetworkInterceptor.new(devtools)
71-
@interceptor.intercept(&)
71+
@interceptor.intercept(&block)
7272
end
7373
end # HasNetworkInterception
7474
end # DriverExtensions

Diff for: rb/lib/selenium/webdriver/common/network.rb

+4-4
Original file line numberDiff line numberDiff line change
@@ -62,25 +62,25 @@ def add_authentication_handler(username = nil, password = nil, *filter, pattern_
6262
)
6363
end
6464

65-
def add_request_handler(*filter, pattern_type: nil, &)
65+
def add_request_handler(*filter, pattern_type: nil, &block)
6666
add_handler(
6767
:before_request,
6868
BiDi::Network::PHASES[:before_request],
6969
BiDi::InterceptedRequest,
7070
filter,
7171
pattern_type: pattern_type,
72-
&
72+
&block
7373
)
7474
end
7575

76-
def add_response_handler(*filter, pattern_type: nil, &)
76+
def add_response_handler(*filter, pattern_type: nil, &block)
7777
add_handler(
7878
:response_started,
7979
BiDi::Network::PHASES[:response_started],
8080
BiDi::InterceptedResponse,
8181
filter,
8282
pattern_type: pattern_type,
83-
&
83+
&block
8484
)
8585
end
8686

Diff for: rb/lib/selenium/webdriver/common/script.rb

+4-4
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@ def initialize(bridge)
2525
end
2626

2727
# @return [int] id of the handler
28-
def add_console_message_handler(&)
29-
@log_handler.add_message_handler('console', &)
28+
def add_console_message_handler(&block)
29+
@log_handler.add_message_handler('console', &block)
3030
end
3131

3232
# @return [int] id of the handler
33-
def add_javascript_error_handler(&)
34-
@log_handler.add_message_handler('javascript', &)
33+
def add_javascript_error_handler(&block)
34+
@log_handler.add_message_handler('javascript', &block)
3535
end
3636

3737
# @param [int] id of the handler previously added

Diff for: rb/lib/selenium/webdriver/remote/bridge.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@ class << self
3535
attr_reader :extra_commands
3636
attr_writer :element_class, :locator_converter
3737

38-
def add_command(name, verb, url, &)
38+
def add_command(name, verb, url, &block)
3939
@extra_commands ||= {}
4040
@extra_commands[name] = [verb, url]
41-
define_method(name, &)
41+
define_method(name, &block)
4242
end
4343

4444
def locator_converter

Diff for: rb/lib/selenium/webdriver/support/guards.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ def initialize(example, bug_tracker: '', conditions: nil)
3737
@messages = {}
3838
end
3939

40-
def add_condition(name, condition = nil, &)
41-
@guard_conditions << GuardCondition.new(name, condition, &)
40+
def add_condition(name, condition = nil, &block)
41+
@guard_conditions << GuardCondition.new(name, condition, &block)
4242
end
4343

4444
def add_message(name, message)

0 commit comments

Comments
 (0)