Rails 7.1's action_dispatch/testing/integration changed its matching algorithm using include? method in rails/rails@5726b1d
When I upgraded my Rails app, I encountered testing errors like
GRPC::Unavailable:
14:undefined method `include?' for #<Addressable::URI:0x4de2c URI:http://test.host:80/api/grpc/<redacted>>
When I debugged it, I noticed that the request was stubbed:
stub_request(:post, "http://test.host/api/grpc/#{proto}/#{action}").to_return do |request|
post request.uri, params: request.body, headers: request.headers
{
headers: response_options.fetch(:headers, response.headers),
body: response_options.fetch(:body, response.body),
status: response_options.fetch(:status, response.status)
}
end
And in the GRPC executor:
def post_request(uri, request_body, metadata)
request = Net::HTTP::Post.new(uri, request_headers(metadata))
request.body = request_body
request.basic_auth uri.user, uri.password if uri.userinfo
begin
Net::HTTP.start(uri.hostname, uri.port, use_ssl: uri.scheme == 'https') do |http|
http.request(request)
end
rescue StandardError => e
raise ::GRPC::Unavailable, e.message
end
end
When I checked the backtrace, the error was coming from said ActionDispatch line above which gets the Addressable::URI from the Net::HTTP.start call above
|
def start(&block) |
|
uri = Addressable::URI.parse(WebMock::NetHTTPUtility.get_uri(self)) |
|
|
|
if WebMock.net_http_connect_on_start?(uri) |
|
super(&block) |
|
else |
|
start_without_connect(&block) |
|
end |
|
end |
Is this an actual bug with webmock or were my tests set up wrong?
Check out the full trace below
Full trace
".rbenv/versions/3.2.7/lib/ruby/gems/3.2.0/gems/actionpack-7.1.5.1/lib/action_dispatch/testing/integration.rb:235:in `process'"
"my_app/spec/support/initializers/user_agent.rb:7:in `process'"
".rbenv/versions/3.2.7/lib/ruby/gems/3.2.0/gems/actionpack-7.1.5.1/lib/action_dispatch/testing/integration.rb:22:in `post'"
".rbenv/versions/3.2.7/lib/ruby/gems/3.2.0/gems/actionpack-7.1.5.1/lib/action_dispatch/testing/integration.rb:379:in `post'"
".rbenv/versions/3.2.7/lib/ruby/gems/3.2.0/gems/rails-controller-testing-1.0.5/lib/rails/controller/testing/integration.rb:16:in `block (2 levels) in <module:Integration>'"
"my_app/spec/support/helpers/grpc.rb:70:in `block in stub_grpc_request'"
".rbenv/versions/3.2.7/lib/ruby/gems/3.2.0/gems/webmock-3.18.1/lib/webmock/response.rb:155:in `evaluate'"
".rbenv/versions/3.2.7/lib/ruby/gems/3.2.0/gems/webmock-3.18.1/lib/webmock/stub_registry.rb:78:in `evaluate_response_for_request'"
".rbenv/versions/3.2.7/lib/ruby/gems/3.2.0/gems/webmock-3.18.1/lib/webmock/stub_registry.rb:65:in `response_for_request'"
".rbenv/versions/3.2.7/lib/ruby/gems/3.2.0/gems/webmock-3.18.1/lib/webmock/http_lib_adapters/net_http.rb:74:in `request'"
"my_app/app/grpc/grpc_web/my_client_executor.rb:25:in `block in post_request'"
".rbenv/versions/3.2.7/lib/ruby/gems/3.2.0/gems/webmock-3.18.1/lib/webmock/http_lib_adapters/net_http.rb:114:in `start_without_connect'"
".rbenv/versions/3.2.7/lib/ruby/gems/3.2.0/gems/webmock-3.18.1/lib/webmock/http_lib_adapters/net_http.rb:141:in `start'"
".rbenv/versions/3.2.7/lib/ruby/3.2.0/net/http.rb:1029:in `start'"
"my_app/app/grpc/grpc_web/my_client_executor.rb:24:in `post_request'"
".rbenv/versions/3.2.7/lib/ruby/gems/3.2.0/bundler/gems/grpc-web-ruby-9049576e8587/lib/grpc_web/client/client_executor.rb:25:in `request'"
".rbenv/versions/3.2.7/lib/ruby/gems/3.2.0/bundler/gems/grpc-web-ruby-9049576e8587/lib/grpc_web/client/client.rb:31:in `block in define_rpc_method'"
"my_app/spec/lib/middleware/grpc_auth_spec.rb:25:in `block (5 levels) in <top (required)>'"
".rbenv/versions/3.2.7/lib/ruby/gems/3.2.0/gems/rspec-expectations-3.13.0/lib/rspec/matchers/built_in/raise_error.rb:59:in `matches?'"
".rbenv/versions/3.2.7/lib/ruby/gems/3.2.0/gems/rspec-expectations-3.13.0/lib/rspec/expectations/handler.rb:51:in `block in handle_matcher'"
".rbenv/versions/3.2.7/lib/ruby/gems/3.2.0/gems/rspec-expectations-3.13.0/lib/rspec/expectations/handler.rb:27:in `with_matcher'"
".rbenv/versions/3.2.7/lib/ruby/gems/3.2.0/gems/rspec-expectations-3.13.0/lib/rspec/expectations/handler.rb:48:in `handle_matcher'"
".rbenv/versions/3.2.7/lib/ruby/gems/3.2.0/gems/rspec-expectations-3.13.0/lib/rspec/expectations/expectation_target.rb:65:in `to'"
".rbenv/versions/3.2.7/lib/ruby/gems/3.2.0/gems/rspec-expectations-3.13.0/lib/rspec/expectations/expectation_target.rb:139:in `to'"
"my_app/spec/lib/middleware/grpc_auth_spec.rb:25:in `block (4 levels) in <top (required)>'"
Rails 7.1's
action_dispatch/testing/integrationchanged its matching algorithm usinginclude?method in rails/rails@5726b1dWhen I upgraded my Rails app, I encountered testing errors like
When I debugged it, I noticed that the request was stubbed:
And in the GRPC executor:
When I checked the backtrace, the error was coming from said
ActionDispatchline above which gets theAddressable::URIfrom theNet::HTTP.startcall abovewebmock/lib/webmock/http_lib_adapters/net_http.rb
Lines 151 to 159 in f90fd50
Is this an actual bug with
webmockor were my tests set up wrong?Check out the full trace below
Full trace