Projects
Mega:23.09
rubygem-webmock
Sign Up
Log In
Username
Password
We truncated the diff of some files because they were too big. If you want to see the full diff for every file,
click here
.
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
Expand all
Collapse all
Changes of Revision 3
View file
_service:tar_scm:rubygem-webmock.spec
Changed
@@ -1,8 +1,8 @@ %bcond_with bootstrap %global gem_name webmock Name: rubygem-%{gem_name} -Version: 3.5.1 -Release: 2 +Version: 3.18.1 +Release: 1 Summary: Library for stubbing HTTP requests in Ruby License: MIT URL: http://github.com/bblimke/webmock @@ -27,8 +27,6 @@ %prep %setup -q -n %{gem_name}-%{version} -sed -i '/^#!\/usr\/bin\/env\ rake/ d' Rakefile -chmod -x Rakefile %build gem build ../%{gem_name}-%{version}.gemspec @@ -45,8 +43,7 @@ ruby -e 'Dir.glob "./minitest/**/*.rb", &method(:require)' ruby -e 'Dir.glob "./test/**/test_*.rb", &method(:require)' sed -i '/patron/ s/^/#/' spec/spec_helper.rb -sed -i '/em-http/ s/^/#/' spec/spec_helper.rb -rspec spec --exclude-pattern 'spec/{quality_spec.rb,acceptance/{patron,http_rb,em_http_request}/*}' +rspec spec --exclude-pattern 'spec/{quality_spec.rb,acceptance/{async_http_client,patron,http_rb}/*}' popd %endif @@ -70,6 +67,9 @@ %{gem_instdir}/webmock.gemspec %changelog +* Tue Nov 14 2023 liyanan <liyanan61@h-partners.com> - 3.18.1-1 +- Update to 3.18.1 + * Sat Sep 5 2020 liyanan <liyanan32@huawei.com> - 3.5.1-2 - fix build fail
View file
_service
Changed
@@ -2,7 +2,7 @@ <service name="tar_scm"> <param name="url">git@gitee.com:src-openeuler/rubygem-webmock.git</param> <param name="scm">git</param> - <param name="revision">openEuler-23.09</param> + <param name="revision">master</param> <param name="exclude">*</param> <param name="extract">*</param> </service>
View file
_service:tar_scm:webmock-3.5.1.gem/checksums.yaml.gz -> _service:tar_scm:webmock-3.18.1.gem/checksums.yaml.gz
Changed
@@ -1,7 +1,7 @@ --- SHA256: - metadata.gz: a1f4b12d21d9712fdf49cc29d9494285c36926b29eda702e3821caab05ba7a97 - data.tar.gz: 24a7edb6ce921ef9735043588ee89ab31b895f9e99bccf3c655d20f645b3cf55 + metadata.gz: 3a7e964f28dd42787fd854c5fcc87dba4cd61ef214c3dee485d9bd0d71fc1cdd + data.tar.gz: f6921a9b14ccd71f18b4674aca8d4d24bf377545a4ef8c56862f95cc56b6e8a7 SHA512: - metadata.gz: 724c7ae8d9ba016537b0e45968e9ae8d820458be36106a24eb7374ccc09cb3e06fb0df5968014443b4f94ba16349dad4643bf683cab17c4af1b32ae9c5b1112d - data.tar.gz: 440171bbd565223139df3aec8581378497cfe359dc766c4b5e8dcf0b865a6c6adf759029d551b3ffac084d7b9683401baabd0b713930017563b7d79cb09320e8 + metadata.gz: 80e85d1bb83018bdaab80aed649134757ee8ac591b98e9ccf1b6df10c0d8930db167dd5fd3bb039dd56a955d22c0cc6b1a1227bb88e8f3e56d31d0e1c9d7708e + data.tar.gz: c67f1f8486d6ee932bd9d01dff2bfcec35d9c3e3ed937e50e1f56d34f664ca11db4c9399c51e82da9316245c1d4727c726b9e307646aef80477764609ecf95ee
View file
_service:tar_scm:webmock-3.18.1.gem/data/.github/workflows/CI.yml
Added
@@ -0,0 +1,38 @@ +name: CI + +on: + push: + branches: + - master + pull_request: + +jobs: + build: + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + ruby: + - head + - '3.1' + - '3.0' + - '2.7' + - '2.6' + - '2.5' + - jruby + continue-on-error: ${{ matrix.ruby == 'head' }} + name: Ruby ${{ matrix.ruby }} + env: + JRUBY_OPTS: "--debug" + steps: + - uses: actions/checkout@v2 + - name: Install Apt Packages + run: | + sudo apt-get install libcurl4-openssl-dev -y + - uses: ruby/setup-ruby@v1 + continue-on-error: true + with: + ruby-version: ${{ matrix.ruby }} + bundler-cache: true + - run: | + bundle exec rake
View file
_service:tar_scm:webmock-3.5.1.gem/data/CHANGELOG.md -> _service:tar_scm:webmock-3.18.1.gem/data/CHANGELOG.md
Changed
@@ -1,5 +1,346 @@ # Changelog +# 3.18.1 + + * Reverted simplified connection handing in Net::HTTP adapter due to https://github.com/bblimke/webmock/issues/999 + +# 3.18.0 + + * Net::BufferedIO is not replaced anymore. + + Thanks to Ray Zane(https://github.com/rzane) + + * Simplified connection handing in Net::HTTP adapter. + + Thanks to Ray Zane(https://github.com/rzane) + +# 3.17.1 + + * Fixed Syntax Error + + Thanks to Mark Spangler(https://github.com/mspangler) + +# 3.17.0 + + * Minimum required Ruby version is 2.3 + + Thanks to Go Sueyoshi(https://github.com/sue445) + + * When using Net::HTTP, stubbed socket StubSocket#close and StubSocket#closed? behave more like the real sockets. + + Thanks to Ray Zane(https://github.com/rzane) + + * Added `peeraddr`, `ssl_version` and `cipher` methods to stubbed sockets used by Net::HTTP. + + Thanks to Ray Zane(https://github.com/rzane) + + * Added support for matching top-level array in JSON request body. + + E.g. + + ```` + stub_request(:post, 'www.example.com').with(body: {a: 1}) + ```` + + Thanks to Cedric Sohrauer(https://github.com/cedrics) + +# 3.16.2 + + * Minimum required Ruby version is 2.0. + +# 3.16.0 (yanked) + + * Fix leaky file descriptors and reuse socket for persistent connections. + + Thanks to Ray Zane(https://github.com/rzane) + + * Allow specifying for what URIs or hosts, Net::HTTP should connect on start. + + Thanks to Ray Zane(https://github.com/rzane) + +# 3.15.2 + + * Minimum required Ruby version is 2.0. + +# 3.15.0 (yanked) + + * fixed async-http adapter on Windows + + Thanks to Pavel Rosický(https://github.com/ahorek) + + * Support for http.rb >= 5.0.2 + + Thanks to ojab(https://github.com/ojab) + + * Curb adapter supports headers with `:` character in the header value + + Thanks to Giorgio Gambino(https://github.com/mrbuzz) + + * Support for matching body of JSON or application/x-www-form-urlencoded requests with content type header including charset. + + Thanks to Timmitry(https://github.com/Timmitry) + + * Prevent double-wrapping http.rb features on non-stubbed requests + + Thanks to Michael Fairley(https://github.com/michaelfairley) + +# 3.14.0 + + * Bump Addressable from 2.3.6 to 2.8.0 + + Thanks to Eduardo Hernandez(https://github.com/EduardoGHdez) + +# 3.13.0 + + * Support http.rb 5.x + + Thanks to Will Storey(https://github.com/horgh) + +# 3.12.2 + + * Fixed em-http-request adapter to avoid calling middleware twice. + + Thanks to Alex Vondrak(https://github.com/ajvondrak) + +# 3.12.1 + + * Fixed handling of URIs with IPv6 addresses with square brackets when in Net::HTTP adapter. + + Thanks to Johanna Hartmann(https://github.com/JohannaHartmann) + +# 3.12.0 + + * Added support for handling custom JSON and XML content types e.g. 'application/vnd.api+json' + +# 3.11.3 + + * Fixed async-http adapter to only considered requests as real if they are real. + + Thanks to Thanks to Tony Schneider(https://github.com/tonywok) and Samuel Williams(https://github.com/ioquatix) + +# 3.11.2 + + * Fix for Manticore streaming mode + + Thanks to Oleksiy Kovyrin(https://github.com/kovyrin) + +# 3.11.1 + + * Compatibility with async-http 0.54+ + + Thanks to Jun Jiang(https://github.com/jasl) + +# 3.11.0 + + * Added support for `features` in http.rb adapter. + + Thanks to Carl (ce07c3)(https://github.com/ce07c3) + +# 3.10.0 + + * Added option to global stubs to have lower priority than local stubs. + + WebMock.globally_stub_request(:after_local_stubs) do + { body: "global stub body" } + end + + stub_request(:get, "www.example.com").to_return(body: 'non-global stub body') + + expect(http_request(:get, "http://www.example.com/").body).to eq("non-global stub body") + + Thanks to Marek Kasztelnik(https://github.com/mkasztelnik) + +# 3.9.5 + + * Prevent overwriting `teardown` method in Test::Unit + + Thanks to Jesse Bowes(https://github.com/jessebs) + +# 3.9.4 + + * More intuitive error message when stubbed response body was provided as Hash + + Thanks to Ben Koshy(https://github.com/BKSpurgeon) + +# 3.9.3 + + * Make httpclient_adapter thread-safe + + Thanks to Adam Harwood(https://github.com/adam-harwood) + +# 3.9.2 + + * Made global stubs thread-safe + + Thanks to Adam Harwood(https://github.com/adam-harwood) + +# 3.9.1 + + * Fixed support for passing `URI` objects as second argument of `stub_request` + + Thanks to Ryan Kerr(https://github.com/leboshi) + +## 3.9.0 + + * Allow using a "callable" (like a proc) as URI pattern + + stub_request(:any, ->(uri) { true }) + + Thanks to John Hawthorn(https://github.com/jhawthorn) + + * Added stubbed IO on stubbed socket in Net::HTTP adapter. + + Thanks to Thilo Rusche(https://github.com/trusche) + + * When 'webmock/rspec' is required, reset WebMock after all after(:each/example) hooks + + Thanks to Andrew Stuntz(https://github.com/drews256) + + * Fixed `net_connect_allowed?` when invoked with no arguments, when there were any allowed URIs passed to `disable_net_connect?`.
View file
_service:tar_scm:webmock-3.5.1.gem/data/Gemfile -> _service:tar_scm:webmock-3.18.1.gem/data/Gemfile
Changed
@@ -1,4 +1,4 @@ -source 'http://rubygems.org/' +source 'https://rubygems.org/' gemspec
View file
_service:tar_scm:webmock-3.5.1.gem/data/README.md -> _service:tar_scm:webmock-3.18.1.gem/data/README.md
Changed
@@ -1,6 +1,11 @@ WebMock ======= -!Gem Version(https://badge.fury.io/rb/webmock.svg)(http://badge.fury.io/rb/webmock) !Build Status(https://secure.travis-ci.org/bblimke/webmock.svg?branch=master)(http://travis-ci.org/bblimke/webmock) !Dependency Status(https://gemnasium.com/bblimke/webmock.svg)(http://gemnasium.com/bblimke/webmock) !Code Climate(https://codeclimate.com/github/bblimke/webmock/badges/gpa.svg)(https://codeclimate.com/github/bblimke/webmock) !Mentioned in Awesome Ruby(https://awesome.re/mentioned-badge.svg)(https://github.com/markets/awesome-ruby) !Inline docs(http://inch-ci.org/github/bblimke/webmock.svg?branch=master)(http://inch-ci.org/github/bblimke/webmock) +!Gem Version(https://badge.fury.io/rb/webmock.svg)(http://badge.fury.io/rb/webmock) +!Build Status(https://github.com/bblimke/webmock/workflows/CI/badge.svg?branch=master)(https://github.com/bblimke/webmock/actions) +!Code Climate(https://codeclimate.com/github/bblimke/webmock/badges/gpa.svg)(https://codeclimate.com/github/bblimke/webmock) +!Mentioned in Awesome Ruby(https://awesome.re/mentioned-badge.svg)(https://github.com/markets/awesome-ruby) +!Inline docs(http://inch-ci.org/github/bblimke/webmock.svg?branch=master)(http://inch-ci.org/github/bblimke/webmock) +!SemVer(https://api.dependabot.com/badges/compatibility_score?dependency-name=webmock&package-manager=bundler&version-scheme=semver)(https://dependabot.com/compatibility-score.html?dependency-name=webmock&package-manager=bundler&version-scheme=semver) Library for stubbing and setting expectations on HTTP requests in Ruby. @@ -19,30 +24,42 @@ Supported HTTP libraries ------------------------ -* Net::HTTP and libraries based on Net::HTTP (i.e RightHttpConnection, REST Client, HTTParty) -* HTTPClient -* Patron -* EM-HTTP-Request -* Curb (currently only Curb::Easy) -* Typhoeus (currently only Typhoeus::Hydra) -* Excon -* HTTP Gem -* Manticore +* Async::HTTP::Client(https://github.com/socketry/async-http) +* Curb(https://github.com/taf2/curb) (currently only Curb::Easy) +* EM-HTTP-Request(https://github.com/igrigorik/em-http-request) +* Excon(https://github.com/excon/excon) +* HTTPClient(https://github.com/nahi/httpclient) +* HTTP Gem (also known as http.rb)(https://github.com/httprb/http) +* httpx(https://honeyryderchuck.gitlab.io/httpx/wiki/Webmock-Adapter) +* Manticore(https://github.com/cheald/manticore) +* Net::HTTP(https://ruby-doc.org/stdlib-2.7.0/libdoc/net/http/rdoc/Net/HTTP.html) and other libraries based on Net::HTTP, e.g.: + * HTTParty(https://github.com/jnunemaker/httparty) + * REST Client(https://github.com/rest-client/rest-client) +* Patron(https://github.com/toland/patron) +* Typhoeus(https://github.com/typhoeus/typhoeus) (currently only Typhoeus::Hydra) Supported Ruby Interpreters --------------------------- -* MRI 2.2 -* MRI 2.3 -* MRI 2.4 * MRI 2.5 * MRI 2.6 +* MRI 2.7 * JRuby * Rubinius ## Installation +```bash gem install webmock +``` +or alternatively: + +```ruby + # add to your Gemfile + group :test do + gem "webmock" + end +``` ### or to install the latest development version from github master @@ -54,36 +71,36 @@ WebMock 2.x has changed somewhat since version 1.x. Changes are listed in CHANGELOG.md(CHANGELOG.md) -### Test::Unit +### Cucumber -Add the following code to `test/test_helper.rb` +Create a file `features/support/webmock.rb` with the following contents: ```ruby -require 'webmock/test_unit' +require 'webmock/cucumber' ``` -### RSpec +### MiniTest -Add the following code to `spec/spec_helper`: +Add the following code to `test/test_helper`: ```ruby -require 'webmock/rspec' +require 'webmock/minitest' ``` -### MiniTest +### RSpec -Add the following code to `test/test_helper`: +Add the following code to `spec/spec_helper`: ```ruby -require 'webmock/minitest' +require 'webmock/rspec' ``` -### Cucumber +### Test::Unit -Create a file `features/support/webmock.rb` with the following contents: +Add the following code to `test/test_helper.rb` ```ruby -require 'webmock/cucumber' +require 'webmock/test_unit' ``` ### Outside a test framework @@ -97,13 +114,10 @@ WebMock.enable! ``` -## Examples - - +# Examples ## Stubbing - ### Stubbed request based on uri only and with the default response ```ruby @@ -236,6 +250,12 @@ Net::HTTP.get('www.example.com', '/') # ===> Success ``` +### Matching uris using lambda + +```ruby +stub_request(:any, ->(uri) { true }) +``` + ### Matching uris using RFC 6570 - Basic Example ```ruby @@ -293,6 +313,12 @@ Net::HTTP.get("www.example.com", '/') # ===> "abc" ``` +Set appropriate Content-Type for HTTParty's `parsed_response`. + +```ruby +stub_request(:any, "www.example.com").to_return body: '{}', headers: {content_type: 'application/json'} +``` + ### Response with body specified as IO object ```ruby @@ -524,9 +550,9 @@ With an object that responds to `#call`, receiving a `URI` object and returning a boolean: ```ruby -blacklist = 'google.com', 'facebook.com', 'apple.com' +denylist = 'google.com', 'facebook.com', 'apple.com' allowed_sites = lambda{|uri| - blacklist.none?{|site| uri.host.include?(site) } + denylist.none?{|site| uri.host.include?(site) } } WebMock.disable_net_connect!(allow: allowed_sites) @@ -873,6 +899,10 @@ Please submit them here http://github.com/bblimke/webmock/issues(http://github.com/bblimke/webmock/issues) +## Issue triage !Open Source Helpers(https://www.codetriage.com/bblimke/webmock/badges/users.svg)(https://www.codetriage.com/bblimke/webmock) + +You can contribute by triaging issues which may include reproducing bug reports or asking for vital information, such as version numbers or reproduction instructions. If you would like to start triaging issues, one easy way to get started is to subscribe to webmock on CodeTriage(https://www.codetriage.com/bblimke/webmock). + ## Suggestions If you have any suggestions on how to improve WebMock please send an email to the mailing list groups.google.com/group/webmock-users(http://groups.google.com/group/webmock-users) @@ -1086,13 +1116,67 @@ * Geremia Taglialatela * Koichi Sasada * Yusuke Endoh +* Grey Baker +* SoonKhen OwYong +* Pavel Valena +* Adam Sokolnicki +* Jeff Felchner +* Eike Send +* Claudio Poli +* Csaba Apagyi +* Frederick Cheung +* Fábio D. Batista +* Andriy Yanko +* y-yagi +* Rafael França +* George Claghorn +* Alex Junger
View file
_service:tar_scm:webmock-3.5.1.gem/data/Rakefile -> _service:tar_scm:webmock-3.18.1.gem/data/Rakefile
Changed
@@ -1,28 +1,36 @@ -#!/usr/bin/env rake - require 'bundler' Bundler::GemHelper.install_tasks require "rspec/core/rake_task" RSpec::Core::RakeTask.new(:spec) do |t| - t.rspec_opts = "-c", "-f progress", "-r ./spec/spec_helper.rb" + t.rspec_opts = %w + --force-color + --format progress + --require ./spec/spec_helper.rb + t.pattern = 'spec/**/*_spec.rb' end RSpec::Core::RakeTask.new(:spec_http_without_webmock) do |t| - t.rspec_opts = "-c", "-f progress", "-r ./spec/acceptance/net_http/real_net_http_spec.rb" + t.rspec_opts = %w + --force-color + --format progress + --require ./spec/acceptance/net_http/real_net_http_spec.rb + t.pattern = 'spec/acceptance/net_http/real_net_http_spec.rb' end require 'rake/testtask' Rake::TestTask.new(:test) do |test| test.test_files = FileList"test/**/*.rb".exclude("test/test_helper.rb") + test.options = "--use-color" test.verbose = false test.warning = false end Rake::TestTask.new(:minitest) do |test| test.test_files = FileList"minitest/**/*.rb".exclude("test/test_helper.rb") + test.options = "--pride" test.verbose = false test.warning = false end
View file
_service:tar_scm:webmock-3.5.1.gem/data/lib/webmock.rb -> _service:tar_scm:webmock-3.18.1.gem/data/lib/webmock.rb
Changed
@@ -54,5 +54,6 @@ require_relative 'webmock/http_lib_adapters/typhoeus_hydra_adapter' require_relative 'webmock/http_lib_adapters/excon_adapter' require_relative 'webmock/http_lib_adapters/manticore_adapter' +require_relative 'webmock/http_lib_adapters/async_http_client_adapter' require_relative 'webmock/webmock'
View file
_service:tar_scm:webmock-3.18.1.gem/data/lib/webmock/http_lib_adapters/async_http_client_adapter.rb
Added
@@ -0,0 +1,221 @@ +begin + require 'async' + require 'async/http' +rescue LoadError + # async-http not found +end + +if defined?(Async::HTTP) + module WebMock + module HttpLibAdapters + class AsyncHttpClientAdapter < HttpLibAdapter + adapter_for :async_http_client + + OriginalAsyncHttpClient = Async::HTTP::Client unless const_defined?(:OriginalAsyncHttpClient) + + class << self + def enable! + Async::HTTP.send(:remove_const, :Client) + Async::HTTP.send(:const_set, :Client, Async::HTTP::WebMockClientWrapper) + end + + def disable! + Async::HTTP.send(:remove_const, :Client) + Async::HTTP.send(:const_set, :Client, OriginalAsyncHttpClient) + end + end + end + end + end + + module Async + module HTTP + class WebMockClientWrapper < Client + def initialize( + endpoint, + protocol = endpoint.protocol, + scheme = endpoint.scheme, + authority = endpoint.authority, + **options + ) + webmock_endpoint = WebMockEndpoint.new(scheme, authority, protocol) + + @network_client = WebMockClient.new(endpoint, **options) + @webmock_client = WebMockClient.new(webmock_endpoint, **options) + + @scheme = scheme + @authority = authority + end + + def call(request) + request.scheme ||= self.scheme + request.authority ||= self.authority + + request_signature = build_request_signature(request) + WebMock::RequestRegistry.instance.requested_signatures.put(request_signature) + webmock_response = WebMock::StubRegistry.instance.response_for_request(request_signature) + net_connect_allowed = WebMock.net_connect_allowed?(request_signature.uri) + real_request = false + + if webmock_response + webmock_response.raise_error_if_any + raise Async::TimeoutError, 'WebMock timeout error' if webmock_response.should_timeout + WebMockApplication.add_webmock_response(request, webmock_response) + response = @webmock_client.call(request) + elsif net_connect_allowed + response = @network_client.call(request) + real_request = true + else + raise WebMock::NetConnectNotAllowedError.new(request_signature) unless webmock_response + end + + if WebMock::CallbackRegistry.any_callbacks? + webmock_response ||= build_webmock_response(response) + WebMock::CallbackRegistry.invoke_callbacks( + { + lib: :async_http_client, + real_request: real_request + }, + request_signature, + webmock_response + ) + end + + response + end + + def close + @network_client.close + @webmock_client.close + end + + private + + def build_request_signature(request) + body = request.read + request.body = ::Protocol::HTTP::Body::Buffered.wrap(body) + WebMock::RequestSignature.new( + request.method.downcase.to_sym, + "#{request.scheme}://#{request.authority}#{request.path}", + headers: request.headers.to_h, + body: body + ) + end + + def build_webmock_response(response) + body = response.read + response.body = ::Protocol::HTTP::Body::Buffered.wrap(body) + + webmock_response = WebMock::Response.new + webmock_response.status = + response.status, + ::Protocol::HTTP1::Reason::DESCRIPTIONSresponse.status + + webmock_response.headers = build_webmock_response_headers(response) + webmock_response.body = body + webmock_response + end + + def build_webmock_response_headers(response) + response.headers.each.each_with_object({}) do |(k, v), o| + ok ||= + ok << v + end + end + end + + class WebMockClient < Client + end + + class WebMockEndpoint + def initialize(scheme, authority, protocol) + @scheme = scheme + @authority = authority + @protocol = protocol + end + + attr :scheme, :authority, :protocol + + def connect + server_socket, client_socket = create_connected_sockets + Async(transient: true) do + accept_socket(server_socket) + end + client_socket + end + + def inspect + "\#<#{self.class}> #{scheme}://#{authority} protocol=#{protocol}" + end + + private + + def create_connected_sockets + pair = begin + Async::IO::Socket.pair(Socket::AF_UNIX, Socket::SOCK_STREAM) + rescue Errno::EAFNOSUPPORT + Async::IO::Socket.pair(Socket::AF_INET, Socket::SOCK_STREAM) + end + pair.tap do |sockets| + sockets.each do |socket| + socket.instance_variable_set :@alpn_protocol, nil + socket.instance_eval do + def alpn_protocol + nil # means HTTP11 will be used for HTTPS + end + end + end + end + end + + def accept_socket(socket) + server = Async::HTTP::Server.new(WebMockApplication, self) + server.accept(socket, socket.remote_address) + end + end + + module WebMockApplication + WEBMOCK_REQUEST_ID_HEADER = 'x-webmock-request-id'.freeze + + class << self + def call(request) + request.read + webmock_response = get_webmock_response(request) + build_response(webmock_response) + end + + def add_webmock_response(request, webmock_response) + webmock_request_id = request.object_id.to_s + request.headers.add(WEBMOCK_REQUEST_ID_HEADER, webmock_request_id) + webmock_responseswebmock_request_id = webmock_response + end + + def get_webmock_response(request) + webmock_request_id = request.headersWEBMOCK_REQUEST_ID_HEADER0 + webmock_responses.fetch(webmock_request_id) + end + + private +
View file
_service:tar_scm:webmock-3.5.1.gem/data/lib/webmock/http_lib_adapters/curb_adapter.rb -> _service:tar_scm:webmock-3.18.1.gem/data/lib/webmock/http_lib_adapters/curb_adapter.rb
Changed
@@ -5,7 +5,7 @@ end if defined?(Curl) - WebMock::VersionChecker.new('Curb', Curl::CURB_VERSION, '0.7.16', '0.9.1', '0.8.7').check_version! + WebMock::VersionChecker.new('Curb', Curl::CURB_VERSION, '0.7.16', '1.0.1', '0.8.7').check_version! module WebMock module HttpLibAdapters @@ -54,7 +54,6 @@ module Curl class WebMockCurlEasy < Curl::Easy - def curb_or_webmock request_signature = build_request_signature WebMock::RequestRegistry.instance.requested_signatures.put(request_signature) @@ -129,7 +128,7 @@ def headers_as_hash(headers) if headers.is_a?(Array) headers.inject({}) {|hash, header| - name, value = header.split(":").map(&:strip) + name, value = header.split(":", 2).map(&:strip) hashname = value hash } @@ -271,6 +270,8 @@ def perform @webmock_method ||= :get curb_or_webmock { super } + ensure + reset_webmock_method end def put_data= data @@ -333,8 +334,16 @@ METHOD end + def reset_webmock_method + @webmock_method = :get + end + def reset instance_variable_set(:@body_str, nil) + instance_variable_set(:@content_type, nil) + instance_variable_set(:@header_str, nil) + instance_variable_set(:@last_effective_url, nil) + instance_variable_set(:@response_code, nil) super end end
View file
_service:tar_scm:webmock-3.5.1.gem/data/lib/webmock/http_lib_adapters/em_http_request_adapter.rb -> _service:tar_scm:webmock-3.18.1.gem/data/lib/webmock/http_lib_adapters/em_http_request_adapter.rb
Changed
@@ -99,6 +99,11 @@ end end + def connection_completed + @state = :response_header + send_request(request_signature.headers, request_signature.body) + end + def send_request(head, body) WebMock::RequestRegistry.instance.requested_signatures.put(request_signature) @@ -107,7 +112,7 @@ @uri ||= nil EM.next_tick { setup(make_raw_response(stubbed_webmock_response), @uri, - stubbed_webmock_response.should_timeout ? "WebMock timeout error" : nil) + stubbed_webmock_response.should_timeout ? Errno::ETIMEDOUT : nil) } self elsif WebMock.net_connect_allowed?(request_signature.uri) @@ -164,7 +169,7 @@ end def build_request_signature - headers, body = @req.headers, @req.body + headers, body = build_request, @req.body @conn.middleware.select {|m| m.respond_to?(:request) }.each do |m| headers, body = m.request(self, headers, body) @@ -178,8 +183,6 @@ body = form_encode_body(body) if body.is_a?(Hash) - headers = @req.headers - if headers'authorization' && headers'authorization'.is_a?(Array) headers'Authorization' = WebMock::Util::Headers.basic_auth_header(headers.delete('authorization')) end
View file
_service:tar_scm:webmock-3.5.1.gem/data/lib/webmock/http_lib_adapters/excon_adapter.rb -> _service:tar_scm:webmock-3.18.1.gem/data/lib/webmock/http_lib_adapters/excon_adapter.rb
Changed
@@ -159,4 +159,7 @@ end end end + + # Suppresses Excon connection argument validation warning + Excon::VALID_CONNECTION_KEYS << :__construction_args end
View file
_service:tar_scm:webmock-3.5.1.gem/data/lib/webmock/http_lib_adapters/http_rb/client.rb -> _service:tar_scm:webmock-3.18.1.gem/data/lib/webmock/http_lib_adapters/http_rb/client.rb
Changed
@@ -4,7 +4,8 @@ def perform(request, options) return __perform__(request, options) unless webmock_enabled? - WebMockPerform.new(request) { __perform__(request, options) }.exec + + WebMockPerform.new(request, options) { __perform__(request, options) }.exec end def webmock_enabled?
View file
_service:tar_scm:webmock-3.5.1.gem/data/lib/webmock/http_lib_adapters/http_rb/response.rb -> _service:tar_scm:webmock-3.18.1.gem/data/lib/webmock/http_lib_adapters/http_rb/response.rb
Changed
@@ -11,20 +11,44 @@ end class << self - def from_webmock(webmock_response, request_signature = nil) + def from_webmock(request, webmock_response, request_signature = nil) status = Status.new(webmock_response.status.first) headers = webmock_response.headers || {} - body = Body.new Streamer.new webmock_response.body uri = normalize_uri(request_signature && request_signature.uri) + # HTTP.rb 3.0+ uses a keyword argument to pass the encoding, but 1.x + # and 2.x use a positional argument, and 0.x don't support supplying + # the encoding. + body = if HTTP::VERSION < "1.0.0" + Body.new(Streamer.new(webmock_response.body)) + elsif HTTP::VERSION < "3.0.0" + Body.new(Streamer.new(webmock_response.body), webmock_response.body.encoding) + else + Body.new( + Streamer.new(webmock_response.body, encoding: webmock_response.body.encoding), + encoding: webmock_response.body.encoding + ) + end + return new(status, "1.1", headers, body, uri) if HTTP::VERSION < "1.0.0" + # 5.0.0 had a breaking change to require request instead of uri. + if HTTP::VERSION < '5.0.0' + return new({ + status: status, + version: "1.1", + headers: headers, + body: body, + uri: uri + }) + end + new({ status: status, version: "1.1", headers: headers, body: body, - uri: uri + request: request, }) end
View file
_service:tar_scm:webmock-3.5.1.gem/data/lib/webmock/http_lib_adapters/http_rb/streamer.rb -> _service:tar_scm:webmock-3.18.1.gem/data/lib/webmock/http_lib_adapters/http_rb/streamer.rb
Changed
@@ -1,11 +1,12 @@ module HTTP class Response class Streamer - def initialize(str) + def initialize(str, encoding: Encoding::BINARY) @io = StringIO.new str + @encoding = encoding end - def readpartial(size = nil) + def readpartial(size = nil, outbuf = nil) unless size if defined?(HTTP::Client::BUFFER_SIZE) size = HTTP::Client::BUFFER_SIZE @@ -14,7 +15,8 @@ end end - @io.read size + chunk = @io.read size, outbuf + chunk.force_encoding(@encoding) if chunk end def close
View file
_service:tar_scm:webmock-3.5.1.gem/data/lib/webmock/http_lib_adapters/http_rb/webmock.rb -> _service:tar_scm:webmock-3.18.1.gem/data/lib/webmock/http_lib_adapters/http_rb/webmock.rb
Changed
@@ -1,7 +1,8 @@ module HTTP class WebMockPerform - def initialize(request, &perform) + def initialize(request, options, &perform) @request = request + @options = options @perform = perform @request_signature = nil end @@ -38,7 +39,10 @@ webmock_response.raise_error_if_any invoke_callbacks(webmock_response, real_request: false) - ::HTTP::Response.from_webmock webmock_response, request_signature + response = ::HTTP::Response.from_webmock @request, webmock_response, request_signature + + @options.features.each { |_name, feature| response = feature.wrap_response(response) } + response end def raise_timeout_error
View file
_service:tar_scm:webmock-3.5.1.gem/data/lib/webmock/http_lib_adapters/httpclient_adapter.rb -> _service:tar_scm:webmock-3.18.1.gem/data/lib/webmock/http_lib_adapters/httpclient_adapter.rb
Changed
@@ -43,6 +43,9 @@ end module WebMockHTTPClients + + REQUEST_RESPONSE_LOCK = Mutex.new + def do_get_block(req, proxy, conn, &block) do_get(req, proxy, conn, false, &block) end @@ -57,7 +60,7 @@ WebMock::RequestRegistry.instance.requested_signatures.put(request_signature) if webmock_responsesrequest_signature - webmock_response = webmock_responses.delete(request_signature) + webmock_response = synchronize_request_response { webmock_responses.delete(request_signature) } response = build_httpclient_response(webmock_response, stream, req.header, &block) @request_filter.each do |filter| filter.filter_response(req, response) @@ -68,7 +71,7 @@ res elsif WebMock.net_connect_allowed?(request_signature.uri) # in case there is a nil entry in the hash... - webmock_responses.delete(request_signature) + synchronize_request_response { webmock_responses.delete(request_signature) } res = if stream do_get_stream_without_webmock(req, proxy, conn, &block) @@ -100,7 +103,7 @@ def do_request_async(method, uri, query, body, extheader) req = create_request(method, uri, query, body, extheader) request_signature = build_request_signature(req) - webmock_request_signatures << request_signature + synchronize_request_response { webmock_request_signatures << request_signature } if webmock_responsesrequest_signature || WebMock.net_connect_allowed?(request_signature.uri) super @@ -184,7 +187,9 @@ def webmock_responses @webmock_responses ||= Hash.new do |hash, request_signature| - hashrequest_signature = WebMock::StubRegistry.instance.response_for_request(request_signature) + synchronize_request_response do + hashrequest_signature = WebMock::StubRegistry.instance.response_for_request(request_signature) + end end end @@ -193,8 +198,10 @@ end def previous_signature_for(signature) - return nil unless index = webmock_request_signatures.index(signature) - webmock_request_signatures.delete_at(index) + synchronize_request_response do + return nil unless index = webmock_request_signatures.index(signature) + webmock_request_signatures.delete_at(index) + end end private @@ -209,6 +216,16 @@ hdrs end end + + def synchronize_request_response + if REQUEST_RESPONSE_LOCK.owned? + yield + else + REQUEST_RESPONSE_LOCK.synchronize do + yield + end + end + end end class WebMockHTTPClient < HTTPClient
View file
_service:tar_scm:webmock-3.5.1.gem/data/lib/webmock/http_lib_adapters/manticore_adapter.rb -> _service:tar_scm:webmock-3.18.1.gem/data/lib/webmock/http_lib_adapters/manticore_adapter.rb
Changed
@@ -24,6 +24,12 @@ Manticore.instance_variable_set(:@manticore_facade, OriginalManticoreClient.new) end + class StubbedTimeoutResponse < Manticore::StubbedResponse + def call + @handlers:failure.call(Manticore::ConnectTimeout.new("Too slow (mocked timeout)")) + end + end + class WebMockManticoreClient < Manticore::Client def request(klass, url, options={}, &block) super(klass, WebMock::Util::URI.normalize_uri(url).to_s, format_options(options)) @@ -50,19 +56,22 @@ if webmock_response = registered_response_for(request_signature) webmock_response.raise_error_if_any - manticore_response = generate_manticore_response(webmock_response).call - real_request = false + manticore_response = generate_manticore_response(webmock_response) + manticore_response.on_success do + WebMock::CallbackRegistry.invoke_callbacks({lib: :manticore, real_request: false}, request_signature, webmock_response) + end elsif real_request_allowed?(request_signature.uri) - manticore_response = Manticore::Response.new(self, request, context, &block).call - webmock_response = generate_webmock_response(manticore_response) - real_request = true + manticore_response = Manticore::Response.new(self, request, context, &block) + manticore_response.on_complete do |completed_response| + webmock_response = generate_webmock_response(completed_response) + WebMock::CallbackRegistry.invoke_callbacks({lib: :manticore, real_request: true}, request_signature, webmock_response) + end else raise WebMock::NetConnectNotAllowedError.new(request_signature) end - WebMock::CallbackRegistry.invoke_callbacks({lib: :manticore, real_request: real_request}, request_signature, webmock_response) manticore_response end @@ -103,21 +112,30 @@ end def generate_manticore_response(webmock_response) - raise Manticore::ConnectTimeout if webmock_response.should_timeout - - Manticore::StubbedResponse.stub( - code: webmock_response.status0, - body: webmock_response.body, - headers: webmock_response.headers, - cookies: {} - ) + if webmock_response.should_timeout + StubbedTimeoutResponse.new + else + Manticore::StubbedResponse.stub( + code: webmock_response.status0, + body: webmock_response.body, + headers: webmock_response.headers, + cookies: {} + ) + end end def generate_webmock_response(manticore_response) webmock_response = WebMock::Response.new webmock_response.status = manticore_response.code, manticore_response.message - webmock_response.body = manticore_response.body webmock_response.headers = manticore_response.headers + + # The attempt to read the body could fail if manticore is used in a streaming mode + webmock_response.body = begin + manticore_response.body + rescue ::Manticore::StreamClosedException + nil + end + webmock_response end end
View file
_service:tar_scm:webmock-3.5.1.gem/data/lib/webmock/http_lib_adapters/net_http.rb -> _service:tar_scm:webmock-3.18.1.gem/data/lib/webmock/http_lib_adapters/net_http.rb
Changed
@@ -10,24 +10,19 @@ adapter_for :net_http OriginalNetHTTP = Net::HTTP unless const_defined?(:OriginalNetHTTP) - OriginalNetBufferedIO = Net::BufferedIO unless const_defined?(:OriginalNetBufferedIO) def self.enable! - Net.send(:remove_const, :BufferedIO) Net.send(:remove_const, :HTTP) Net.send(:remove_const, :HTTPSession) Net.send(:const_set, :HTTP, @webMockNetHTTP) Net.send(:const_set, :HTTPSession, @webMockNetHTTP) - Net.send(:const_set, :BufferedIO, Net::WebMockNetBufferedIO) end def self.disable! - Net.send(:remove_const, :BufferedIO) Net.send(:remove_const, :HTTP) Net.send(:remove_const, :HTTPSession) Net.send(:const_set, :HTTP, OriginalNetHTTP) Net.send(:const_set, :HTTPSession, OriginalNetHTTP) - Net.send(:const_set, :BufferedIO, OriginalNetBufferedIO) #copy all constants from @webMockNetHTTP to original Net::HTTP #in case any constants were added to @webMockNetHTTP instead of Net::HTTP @@ -98,13 +93,8 @@ after_request.call(response) } if started? - if WebMock::Config.instance.net_http_connect_on_start - super_with_after_request.call - else - start_with_connect_without_finish { - super_with_after_request.call - } - end + ensure_actual_connection + super_with_after_request.call else start_with_connect { super_with_after_request.call @@ -119,32 +109,33 @@ raise IOError, 'HTTP session already opened' if @started if block_given? begin + @socket = Net::HTTP.socket_type.new @started = true return yield(self) ensure do_finish end end + @socket = Net::HTTP.socket_type.new @started = true self end - def start_with_connect_without_finish # :yield: http - if block_given? - begin - do_start - return yield(self) - end + def ensure_actual_connection + if @socket.is_a?(StubSocket) + @socket&.close + @socket = nil + do_start end - do_start - self end alias_method :start_with_connect, :start def start(&block) - if WebMock::Config.instance.net_http_connect_on_start + uri = Addressable::URI.parse(WebMock::NetHTTPUtility.get_uri(self)) + + if WebMock.net_http_connect_on_start?(uri) super(&block) else start_without_connect(&block) @@ -169,7 +160,7 @@ response.extend Net::WebMockHTTPResponse if webmock_response.should_timeout - raise timeout_exception, "execution expired" + raise Net::OpenTimeout, "execution expired" end webmock_response.raise_error_if_any @@ -179,16 +170,6 @@ response end - def timeout_exception - if defined?(Net::OpenTimeout) - # Ruby 2.x - Net::OpenTimeout - else - # Fallback, if things change - Timeout::Error - end - end - def build_webmock_response(net_http_response) webmock_response = WebMock::Response.new webmock_response.status = @@ -222,81 +203,43 @@ end end -# patch for StringIO behavior in Ruby 2.2.3 -# https://github.com/bblimke/webmock/issues/558 -class PatchedStringIO < StringIO #:nodoc: - - alias_method :orig_read_nonblock, :read_nonblock - - def read_nonblock(size, *args) - orig_read_nonblock(size) - end - -end - class StubSocket #:nodoc: - attr_accessor :read_timeout, :continue_timeout + attr_accessor :read_timeout, :continue_timeout, :write_timeout def initialize(*args) + @closed = false end def closed? - @closed ||= true + @closed end def close + @closed = true + nil end def readuntil(*args) end -end - -module Net #:nodoc: all - - class WebMockNetBufferedIO < BufferedIO - def initialize(io, *args) - io = case io - when Socket, OpenSSL::SSL::SSLSocket, IO - io - when StringIO - PatchedStringIO.new(io.string) - when String - PatchedStringIO.new(io) - end - raise "Unable to create local socket" unless io - - super - end - - if RUBY_VERSION >= '2.6.0' - def rbuf_fill - current_thread_id = Thread.current.object_id - - trace = TracePoint.trace(:line) do |tp| - next unless Thread.current.object_id == current_thread_id - if tp.binding.local_variable_defined?(:tmp) - tp.binding.local_variable_set(:tmp, nil) - end - end - - super - ensure - trace.disable - end - end + def io + @io ||= StubIO.new end + class StubIO + def setsockopt(*args); end + def peer_cert; end + def peeraddr; "AF_INET", 443, "127.0.0.1", "127.0.0.1" end + def ssl_version; "TLSv1.3" end + def cipher; "TLS_AES_128_GCM_SHA256", "TLSv1.3", 128, 128 end + end end - module WebMock module NetHTTPUtility
View file
_service:tar_scm:webmock-3.5.1.gem/data/lib/webmock/http_lib_adapters/patron_adapter.rb -> _service:tar_scm:webmock-3.18.1.gem/data/lib/webmock/http_lib_adapters/patron_adapter.rb
Changed
@@ -118,7 +118,7 @@ def self.build_webmock_response(patron_response) webmock_response = WebMock::Response.new reason = patron_response.status_line. - scan(%r(\AHTTP/(\d+\.\d+)\s+(\d\d\d)\s*(^\r\n+)?))02 + scan(%r(\AHTTP/(\d+(?:\.\d+)?)\s+(\d\d\d)\s*(^\r\n+)?))02 webmock_response.status = patron_response.status, reason webmock_response.body = patron_response.body webmock_response.headers = patron_response.headers
View file
_service:tar_scm:webmock-3.5.1.gem/data/lib/webmock/request_body_diff.rb -> _service:tar_scm:webmock-3.18.1.gem/data/lib/webmock/request_body_diff.rb
Changed
@@ -12,7 +12,7 @@ def body_diff return {} unless request_signature_diffable? && request_stub_diffable? - HashDiff.diff(request_signature_body_hash, request_stub_body_hash) + Hashdiff.diff(request_signature_body_hash, request_stub_body_hash) end attr_reader :request_signature, :request_stub
View file
_service:tar_scm:webmock-3.5.1.gem/data/lib/webmock/request_pattern.rb -> _service:tar_scm:webmock-3.18.1.gem/data/lib/webmock/request_pattern.rb
Changed
@@ -24,7 +24,7 @@ end def with(options = {}, &block) - raise ArgumentError.new('#with method invoked with no arguments. Either options hash or block must be specified.') if options.empty? && !block_given? + raise ArgumentError.new('#with method invoked with no arguments. Either options hash or block must be specified. Created a block with do..end? Try creating it with curly braces {} instead.') if options.empty? && !block_given? assign_options(options) @with_block = block self @@ -80,6 +80,8 @@ URIRegexpPattern.new(uri) elsif uri.is_a?(Addressable::Template) URIAddressablePattern.new(uri) + elsif uri.respond_to?(:call) + URICallablePattern.new(uri) else URIStringPattern.new(uri) end @@ -107,11 +109,13 @@ include RSpecMatcherDetector def initialize(pattern) - @pattern = case pattern - when Addressable::URI, Addressable::Template + @pattern = if pattern.is_a?(Addressable::URI) \ + || pattern.is_a?(Addressable::Template) + pattern + elsif pattern.respond_to?(:call) pattern else - WebMock::Util::URI.normalize_uri(pattern) + WebMock::Util::URI.normalize_uri(pattern) end @query_params = nil end @@ -131,38 +135,44 @@ end end + def matches?(uri) + pattern_matches?(uri) && query_params_matches?(uri) + end + def to_s - str = @pattern.inspect + str = pattern_inspect str += " with query params #{@query_params.inspect}" if @query_params str end - end - class URIRegexpPattern < URIPattern - def matches?(uri) - WebMock::Util::URI.variations_of_uri_as_strings(uri).any? { |u| u.match(@pattern) } && - (@query_params.nil? || @query_params == WebMock::Util::QueryMapper.query_to_values(uri.query, notation: Config.instance.query_values_notation)) + private + + def pattern_inspect + @pattern.inspect end - def to_s - str = @pattern.inspect - str += " with query params #{@query_params.inspect}" if @query_params - str + def query_params_matches?(uri) + @query_params.nil? || @query_params == WebMock::Util::QueryMapper.query_to_values(uri.query, notation: Config.instance.query_values_notation) end end - class URIAddressablePattern < URIPattern - def matches?(uri) - if @query_params.nil? - # Let Addressable check the whole URI - matches_with_variations?(uri) - else - # WebMock checks the query, Addressable checks everything else - matches_with_variations?(uri.omit(:query)) && - @query_params == WebMock::Util::QueryMapper.query_to_values(uri.query) - end + class URICallablePattern < URIPattern + private + + def pattern_matches?(uri) + @pattern.call(uri) + end + end + + class URIRegexpPattern < URIPattern + private + + def pattern_matches?(uri) + WebMock::Util::URI.variations_of_uri_as_strings(uri).any? { |u| u.match(@pattern) } end + end + class URIAddressablePattern < URIPattern def add_query_params(query_params) @@add_query_params_warned ||= false if not @@add_query_params_warned @@ -172,28 +182,57 @@ super(query_params) end - def to_s - str = @pattern.pattern.inspect - str += " with variables #{@pattern.variables.inspect}" if @pattern.variables - str + private + + def pattern_matches?(uri) + if @query_params.nil? + # Let Addressable check the whole URI + matches_with_variations?(uri) + else + # WebMock checks the query, Addressable checks everything else + matches_with_variations?(uri.omit(:query)) + end end - private + def pattern_inspect + @pattern.pattern.inspect + end def matches_with_variations?(uri) - normalized_template = Addressable::Template.new(WebMock::Util::URI.heuristic_parse(@pattern.pattern)) + template = + begin + Addressable::Template.new(WebMock::Util::URI.heuristic_parse(@pattern.pattern)) + rescue Addressable::URI::InvalidURIError + Addressable::Template.new(@pattern.pattern) + end + WebMock::Util::URI.variations_of_uri_as_strings(uri).any? { |u| + template_matches_uri?(template, u) + } + end - WebMock::Util::URI.variations_of_uri_as_strings(uri, only_with_scheme: true) - .any? { |u| normalized_template.match(u) } + def template_matches_uri?(template, uri) + template.match(uri) + rescue Addressable::URI::InvalidURIError + false end end class URIStringPattern < URIPattern - def matches?(uri) + def add_query_params(query_params) + super + if @query_params.is_a?(Hash) || @query_params.is_a?(String) + query_hash = (WebMock::Util::QueryMapper.query_to_values(@pattern.query, notation: Config.instance.query_values_notation) || {}).merge(@query_params) + @pattern.query = WebMock::Util::QueryMapper.values_to_query(query_hash, notation: WebMock::Config.instance.query_values_notation) + @query_params = nil + end + end + + private + + def pattern_matches?(uri) if @pattern.is_a?(Addressable::URI) if @query_params - uri.omit(:query) === @pattern && - (@query_params.nil? || @query_params == WebMock::Util::QueryMapper.query_to_values(uri.query, notation: Config.instance.query_values_notation)) + uri.omit(:query) === @pattern else uri === @pattern end @@ -202,19 +241,8 @@ end end - def add_query_params(query_params) - super - if @query_params.is_a?(Hash) || @query_params.is_a?(String) - query_hash = (WebMock::Util::QueryMapper.query_to_values(@pattern.query, notation: Config.instance.query_values_notation) || {}).merge(@query_params) - @pattern.query = WebMock::Util::QueryMapper.values_to_query(query_hash, notation: WebMock::Config.instance.query_values_notation) - @query_params = nil - end - end - - def to_s - str = WebMock::Util::URI.strip_default_port_from_uri_string(@pattern.to_s) - str += " with query params #{@query_params.inspect}" if @query_params - str + def pattern_inspect + WebMock::Util::URI.strip_default_port_from_uri_string(@pattern.to_s) end end @@ -253,6 +281,8 @@ if (@pattern).is_a?(Hash) return true if @pattern.empty? matching_body_hashes?(body_as_hash(body, content_type), @pattern, content_type) + elsif (@pattern).is_a?(Array) + matching_body_array?(body_as_hash(body, content_type), @pattern, content_type) elsif (@pattern).is_a?(WebMock::Matchers::HashIncludingMatcher) @pattern == body_as_hash(body, content_type) else
View file
_service:tar_scm:webmock-3.5.1.gem/data/lib/webmock/request_signature.rb -> _service:tar_scm:webmock-3.18.1.gem/data/lib/webmock/request_signature.rb
Changed
@@ -35,11 +35,11 @@ alias == eql? def url_encoded? - !!(headers && headers'Content-Type' == 'application/x-www-form-urlencoded') + !!(headers&.fetch('Content-Type', nil)&.start_with?('application/x-www-form-urlencoded')) end def json_headers? - !!(headers && headers'Content-Type' == 'application/json') + !!(headers&.fetch('Content-Type', nil)&.start_with?('application/json')) end private
View file
_service:tar_scm:webmock-3.5.1.gem/data/lib/webmock/request_stub.rb -> _service:tar_scm:webmock-3.18.1.gem/data/lib/webmock/request_stub.rb
Changed
@@ -24,6 +24,21 @@ end alias_method :and_return, :to_return + def to_return_json(*response_hashes) + raise ArgumentError, '#to_return_json does not support passing a block' if block_given? + + json_response_hashes = *response_hashes.flatten.map do |resp_h| + headers, body = resp_h.values_at(:headers, :body) + resp_h.merge( + headers: {content_type: 'application/json'}.merge(headers.to_h), + body: body.is_a?(Hash) ? body.to_json : body + ) + end + + to_return(json_response_hashes) + end + alias_method :and_return_json, :to_return_json + def to_rack(app, options={}) @responses_sequences << ResponsesSequence.new(RackResponse.new(app)) end
View file
_service:tar_scm:webmock-3.5.1.gem/data/lib/webmock/response.rb -> _service:tar_scm:webmock-3.18.1.gem/data/lib/webmock/response.rb
Changed
@@ -14,8 +14,11 @@ class Response def initialize(options = {}) - if options.is_a?(IO) || options.is_a?(String) + case options + when IO, StringIO self.options = read_raw_response(options) + when String + self.options = read_raw_response(StringIO.new(options)) else self.options = options end @@ -91,10 +94,10 @@ def ==(other) self.body == other.body && - self.headers === other.headers && - self.status == other.status && - self.exception == other.exception && - self.should_timeout == other.should_timeout + self.headers === other.headers && + self.status == other.status && + self.exception == other.exception && + self.should_timeout == other.should_timeout end private @@ -111,16 +114,17 @@ valid_types = Proc, IO, Pathname, String, Array return if @body.nil? return if valid_types.any? { |c| @body.is_a?(c) } - raise InvalidBody, "must be one of: #{valid_types}. '#{@body.class}' given" - end - def read_raw_response(raw_response) - if raw_response.is_a?(IO) - string = raw_response.read - raw_response.close - raw_response = string + if @body.class.is_a?(Hash) + raise InvalidBody, "must be one of: #{valid_types}, but you've used a #{@body.class}' instead." \ + "\n What shall we encode it to? try calling .to_json .to_xml instead on the hash instead, or otherwise convert it to a string." + else + raise InvalidBody, "must be one of: #{valid_types}. '#{@body.class}' given" end - socket = ::Net::BufferedIO.new(raw_response) + end + + def read_raw_response(io) + socket = ::Net::BufferedIO.new(io) response = ::Net::HTTPResponse.read_new(socket) transfer_encoding = response.delete('transfer-encoding') #chunks were already read by curl response.reading_body(socket, true) {} @@ -132,6 +136,8 @@ options:body = response.read_body options:status = response.code.to_i, response.message options + ensure + socket.close end InvalidBody = Class.new(StandardError)
View file
_service:tar_scm:webmock-3.5.1.gem/data/lib/webmock/rspec.rb -> _service:tar_scm:webmock-3.18.1.gem/data/lib/webmock/rspec.rb
Changed
@@ -33,7 +33,8 @@ WebMock.disable! end - config.after(:each) do + config.around(:each) do |example| + example.run WebMock.reset! end }
View file
_service:tar_scm:webmock-3.5.1.gem/data/lib/webmock/stub_registry.rb -> _service:tar_scm:webmock-3.18.1.gem/data/lib/webmock/stub_registry.rb
Changed
@@ -10,25 +10,39 @@ end def global_stubs - @global_stubs ||= + @global_stubs ||= Hash.new { |h, k| hk = } end def reset! self.request_stubs = end - def register_global_stub(&block) + def register_global_stub(order = :before_local_stubs, &block) + unless %ibefore_local_stubs after_local_stubs.include?(order) + raise ArgumentError.new("Wrong order. Use :before_local_stubs or :after_local_stubs") + end + # This hash contains the responses returned by the block, # keyed by the exact request (using the object_id). # That way, there's no race condition in case #to_return # doesn't run immediately after stub.with. responses = {} - - stub = ::WebMock::RequestStub.new(:any, /.*/).with { |request| - responsesrequest.object_id = yield(request) - }.to_return(lambda { |request| responses.delete(request.object_id) }) - - global_stubs.push stub + response_lock = Mutex.new + + stub = ::WebMock::RequestStub.new(:any, ->(uri) { true }).with { |request| + update_response = -> { responsesrequest.object_id = yield(request) } + + # The block can recurse, so only lock if we don't already own it + if response_lock.owned? + update_response.call + else + response_lock.synchronize(&update_response) + end + }.to_return(lambda { |request| + response_lock.synchronize { responses.delete(request.object_id) } + }) + + global_stubsorder.push stub end def register_request_stub(stub) @@ -54,9 +68,10 @@ private def request_stub_for(request_signature) - (global_stubs + request_stubs).detect { |registered_request_stub| - registered_request_stub.request_pattern.matches?(request_signature) - } + (global_stubs:before_local_stubs + request_stubs + global_stubs:after_local_stubs) + .detect { |registered_request_stub| + registered_request_stub.request_pattern.matches?(request_signature) + } end def evaluate_response_for_request(response, request_signature)
View file
_service:tar_scm:webmock-3.5.1.gem/data/lib/webmock/test_unit.rb -> _service:tar_scm:webmock-3.18.1.gem/data/lib/webmock/test_unit.rb
Changed
@@ -8,12 +8,10 @@ class TestCase include WebMock::API - alias_method :teardown_without_webmock, :teardown + teardown def teardown_with_webmock - teardown_without_webmock WebMock.reset! end - alias_method :teardown, :teardown_with_webmock end end
View file
_service:tar_scm:webmock-3.5.1.gem/data/lib/webmock/util/query_mapper.rb -> _service:tar_scm:webmock-3.18.1.gem/data/lib/webmock/util/query_mapper.rb
Changed
@@ -161,7 +161,7 @@ else if array_value current_nodelast_key ||= - current_nodelast_key << value + current_nodelast_key << value unless value.nil? else current_nodelast_key = value end @@ -186,7 +186,9 @@ new_query_values = new_query_values.to_hash new_query_values = new_query_values.inject() do |object, (key, value)| key = key.to_s if key.is_a?(::Symbol) || key.nil? - if value.is_a?(Array) + if value.is_a?(Array) && value.empty? + object << key.to_s + '' + elsif value.is_a?(Array) value.each { |v| object << key.to_s + '', v } elsif value.is_a?(Hash) value.each { |k, v| object << "#{key.to_s}#{k}", v}
View file
_service:tar_scm:webmock-3.5.1.gem/data/lib/webmock/util/uri.rb -> _service:tar_scm:webmock-3.18.1.gem/data/lib/webmock/util/uri.rb
Changed
@@ -41,12 +41,12 @@ uris = uris_with_trailing_slash_and_without(uris) end - uris = uris_encoded_and_unencoded(uris) - if normalized_uri.port == Addressable::URI.port_mappingnormalized_uri.scheme uris = uris_with_inferred_port_and_without(uris) end + uris = uris_encoded_and_unencoded(uris) + if normalized_uri.scheme == "http" && !only_with_scheme uris = uris_with_scheme_and_without(uris) end @@ -80,27 +80,27 @@ def self.uris_with_inferred_port_and_without(uris) uris.map { |uri| - uri = uri.dup.force_encoding(Encoding::ASCII_8BIT) if uri.respond_to?(:force_encoding) - uri, uri.gsub(%r{(:80)|(:443)}, "").freeze + uri, uri.omit(:port) }.flatten end def self.uris_encoded_and_unencoded(uris) uris.map do |uri| - uri.to_s, Addressable::URI.unencode(uri, String).freeze + + uri.to_s.force_encoding(Encoding::ASCII_8BIT), + Addressable::URI.unencode(uri, String).force_encoding(Encoding::ASCII_8BIT).freeze + end.flatten end def self.uris_with_scheme_and_without(uris) uris.map { |uri| - uri = uri.dup.force_encoding(Encoding::ASCII_8BIT) if uri.respond_to?(:force_encoding) uri, uri.gsub(%r{^https?://},"").freeze }.flatten end def self.uris_with_trailing_slash_and_without(uris) - uris = uris.map { |uri| - uri = uri.dup.force_encoding(Encoding::ASCII_8BIT) if uri.respond_to?(:force_encoding) + uris.map { |uri| uri, uri.omit(:path).freeze }.flatten end
View file
_service:tar_scm:webmock-3.5.1.gem/data/lib/webmock/version.rb -> _service:tar_scm:webmock-3.18.1.gem/data/lib/webmock/version.rb
Changed
@@ -1,3 +1,3 @@ module WebMock - VERSION = '3.5.1' unless defined?(::WebMock::VERSION) + VERSION = '3.18.1' unless defined?(::WebMock::VERSION) end
View file
_service:tar_scm:webmock-3.5.1.gem/data/lib/webmock/webmock.rb -> _service:tar_scm:webmock-3.18.1.gem/data/lib/webmock/webmock.rb
Changed
@@ -53,16 +53,33 @@ Config.instance.net_http_connect_on_start = options:net_http_connect_on_start end + class << self + alias :enable_net_connect! :allow_net_connect! + alias :disallow_net_connect! :disable_net_connect! + end + def self.net_connect_allowed?(uri = nil) + return !!Config.instance.allow_net_connect if uri.nil? + if uri.is_a?(String) uri = WebMock::Util::URI.normalize_uri(uri) end - Config.instance.allow_net_connect || + !!Config.instance.allow_net_connect || ( Config.instance.allow_localhost && WebMock::Util::URI.is_uri_localhost?(uri) || Config.instance.allow && net_connect_explicit_allowed?(Config.instance.allow, uri) ) end + def self.net_http_connect_on_start?(uri) + allowed = Config.instance.net_http_connect_on_start || false + + if true, false.include?(allowed) + allowed + else + net_connect_explicit_allowed?(allowed, uri) + end + end + def self.net_connect_explicit_allowed?(allowed, uri=nil) case allowed when Array @@ -133,8 +150,8 @@ puts WebMock::RequestExecutionVerifier.executed_requests_message end - def self.globally_stub_request(&block) - WebMock::StubRegistry.instance.register_global_stub(&block) + def self.globally_stub_request(order = :before_local_stubs, &block) + WebMock::StubRegistry.instance.register_global_stub(order, &block) end %w(
View file
_service:tar_scm:webmock-3.5.1.gem/data/minitest/webmock_spec.rb -> _service:tar_scm:webmock-3.18.1.gem/data/minitest/webmock_spec.rb
Changed
@@ -20,7 +20,7 @@ end it "should raise error on non stubbed request" do - lambda { http_request(:get, "http://www.example.net/") }.must_raise(WebMock::NetConnectNotAllowedError) + expect { http_request(:get, "http://www.example.net/") }.must_raise(WebMock::NetConnectNotAllowedError) end it "should verify that expected request occured" do
View file
_service:tar_scm:webmock-3.18.1.gem/data/spec/acceptance/async_http_client/async_http_client_spec.rb
Added
@@ -0,0 +1,375 @@ +# encoding: utf-8 +require 'spec_helper' +require 'acceptance/webmock_shared' +require_relative './async_http_client_spec_helper' + +require 'protocol/http/body/file' + +Async.logger.debug! if ENV'ASYNC_LOGGER_DEBUG' + +unless RUBY_PLATFORM =~ /java/ + describe 'Async::HTTP::Client' do + include AsyncHttpClientSpecHelper + + include_context "with WebMock", + :no_status_message, + :no_url_auth, + :no_content_length_header + + it 'works' do + stub_request(:get, 'http://www.example.com') + expect(make_request(:get, 'http://www.example.com')).to eq( + status: 200, + headers: {}, + body: nil + ) + end + + it 'works with request path' do + stub_request(:get, 'http://www.example.com/foo') + expect(make_request(:get, 'http://www.example.com/foo')).to eq( + status: 200, + headers: {}, + body: nil + ) + end + + it 'works with request query' do + stub_request(:get, 'http://www.example.com/').with( + query: { + 'foo' => 'bar' + } + ) + expect(make_request(:get, 'http://www.example.com/?foo=bar')).to eq( + status: 200, + headers: {}, + body: nil + ) + end + + it 'works with request headers' do + stub_request(:get, 'http://www.example.com').with( + headers: { + 'X-Token' => 'Token' + } + ) + expect( + make_request :get, 'http://www.example.com', + headers: { + 'X-Token' => 'Token' + } + ).to eq( + status: 200, + headers: {}, + body: nil + ) + end + + it 'works with request body as text' do + stub_request(:post, 'http://www.example.com').with( + body: 'x'*10_000 + ) + expect( + make_request :post, 'http://www.example.com', + body: 'x'*10_000 + ).to eq( + status: 200, + headers: {}, + body: nil + ) + end + + it 'works with request body as file' do + stub_request(:post, "www.example.com").with( + body: File.read(__FILE__) + ) + expect( + make_request :post, "http://www.example.com", + body: ::Protocol::HTTP::Body::File.open(__FILE__, block_size: 32) + ).to eq( + status: 200, + headers: {}, + body: nil + ) + end + + it 'works with response status' do + stub_request(:get, 'http://www.example.com').to_return( + status: 400 + ) + expect(make_request(:get, 'http://www.example.com')).to eq( + status: 400, + headers: {}, + body: nil + ) + end + + it 'works with response headers' do + stub_request(:get, 'http://www.example.com').to_return( + headers: { + 'X-Token' => 'TOKEN' + } + ) + expect(make_request(:get, 'http://www.example.com')).to eq( + status: 200, + headers: { + 'x-token' => 'TOKEN' + }, + body: nil + ) + end + + it 'works with response body' do + stub_request(:get, 'http://www.example.com').to_return( + body: 'abc' + ) + expect(make_request(:get, 'http://www.example.com')).to eq( + status: 200, + headers: {}, + body: 'abc' + ) + end + + it 'works with to_timeout' do + stub_request(:get, 'http://www.example.com').to_timeout + expect { make_request(:get, 'http://www.example.com') }.to raise_error Async::TimeoutError + end + + it 'does not invoke "after real request" callbacks for stubbed requests' do + WebMock.allow_net_connect! + stub_request(:get, 'http://www.example.com').to_return(body: 'abc') + + callback_invoked = false + WebMock.after_request(real_requests_only: true) { |_| callback_invoked = true } + + make_request(:get, 'http://www.example.com') + expect(callback_invoked).to eq(false) + end + + it 'does invoke "after request" callbacks for stubbed requests' do + WebMock.allow_net_connect! + stub_request(:get, 'http://www.example.com').to_return(body: 'abc') + + callback_invoked = false + WebMock.after_request(real_requests_only: false) { |_| callback_invoked = true } + + make_request(:get, 'http://www.example.com') + expect(callback_invoked).to eq(true) + end + + context 'scheme and protocol' do + let(:default_response_headers) { {} } + + before do + stub_request( + :get, "#{scheme}://www.example.com" + ).and_return( + body: 'BODY' + ) + end + + subject do + make_request(:get, "#{scheme}://www.example.com", protocol: protocol) + end + + shared_examples :common do + specify do + expect(subject).to eq( + status: 200, + headers: default_response_headers, + body: 'BODY' + ) + end + end + + context 'http scheme' do + let(:scheme) { 'http' } + + context 'default protocol' do + let(:protocol) { nil } + + include_examples :common + end + + context 'HTTP10 protocol' do + let(:protocol) { Async::HTTP::Protocol::HTTP10 } + let(:default_response_headers) { {"connection"=>"keep-alive"} } + + include_examples :common + end
View file
_service:tar_scm:webmock-3.18.1.gem/data/spec/acceptance/async_http_client/async_http_client_spec_helper.rb
Added
@@ -0,0 +1,73 @@ +module AsyncHttpClientSpecHelper + def http_request(method, url, options = {}, &block) + endpoint = Async::HTTP::Endpoint.parse(url) + + path = endpoint.path + path = path + "?" + options:query if options:query + + headers = (options:headers || {}).each_with_object() do |(k, v), o| + Array(v).each do |v| + o.push k, v + end + end + headers.push( + 'authorization', 'Basic ' + Base64.strict_encode64(options:basic_auth.join(':')) + ) if options:basic_auth + + body = options:body + + Async do + begin + Async::HTTP::Client.open(endpoint) do |client| + response = client.send( + method, + path, + headers, + body + ) + + OpenStruct.new( + build_hash_response(response) + ) + end + rescue Exception => e + e + end + end.wait + end + + def client_timeout_exception_class + Async::TimeoutError + end + + def connection_refused_exception_class + Errno::ECONNREFUSED + end + + def http_library + :async_http_client + end + + private + + def build_hash_response(response) + { + + status: response.status.to_s, + message: Protocol::HTTP1::Reason::DESCRIPTIONSresponse.status, + headers: build_response_headers(response), + body: response.read + } + end + + def build_response_headers(response) + response.headers.each.each_with_object({}) do |(k, v), o| + ok ||= + ok << v + end.tap do |o| + o.each do |k, v| + ok = v.join(', ') + end + end + end +end
View file
_service:tar_scm:webmock-3.5.1.gem/data/spec/acceptance/curb/curb_spec.rb -> _service:tar_scm:webmock-3.18.1.gem/data/spec/acceptance/curb/curb_spec.rb
Changed
@@ -383,6 +383,17 @@ expect(c.body).to eq("abc") end + it "supports headers containing the ':' character" do + stub_request(:get, "www.example.com").with(headers: {'Referer'=>'http://www.example.com'}).to_return(body: "abc") + + c = Curl::Easy.new + c.url = "http://www.example.com" + c.headers = "Referer: http://www.example.com" + c.http(:GET) + expect(c.body).to eq("abc") + expect(c.headers).to eq("Referer: http://www.example.com") + end + describe 'match request body' do it 'for post' do stub_request(:post, "www.example.com").with(body: 'foo=nhe').to_return(body: "abc") @@ -411,6 +422,17 @@ it_should_behave_like "Curb" include CurbSpecHelper::NamedHttp + it "should reset @webmock_method after each call" do + stub_request(:post, "www.example.com").with(body: "01234") + c = Curl::Easy.new + c.url = "http://www.example.com" + c.post_body = "01234" + c.http_post + expect { + c.perform + }.to raise_error(WebMock::NetConnectNotAllowedError, %r(Real HTTP connections are disabled. Unregistered request: GET http://www.example.com)) + end + it "should work with blank arguments for post" do stub_request(:post, "www.example.com").with(body: "01234") c = Curl::Easy.new @@ -463,18 +485,25 @@ include CurbSpecHelper::ClassPerform end - describe "using .reset" do + describe "using #reset" do before do @curl = Curl::Easy.new @curl.url = "http://example.com" - body = "on_success fired" - stub_request(:any, "example.com").to_return(body: body) + stub_request(:any, "example.com"). + to_return(body: "abc", + headers: { "Content-Type" => "application/json" }) @curl.http_get end - it "should clear the body_str" do + it "should clear all memoized response fields" do @curl.reset - expect(@curl.body_str).to eq(nil) + expect(@curl).to have_attributes( + body_str: nil, + content_type: nil, + header_str: nil, + last_effective_url: nil, + response_code: 0, + ) end end end
View file
_service:tar_scm:webmock-3.5.1.gem/data/spec/acceptance/em_http_request/em_http_request_spec.rb -> _service:tar_scm:webmock-3.18.1.gem/data/spec/acceptance/em_http_request/em_http_request_spec.rb
Changed
@@ -22,7 +22,7 @@ def make_request EM.run do - request = EM::HttpRequest.new(http_url).get(redirects: 1) + request = EM::HttpRequest.new(http_url, ssl: {verify_peer: true}).get(redirects: 1) request.callback { EM.stop } end end @@ -71,6 +71,35 @@ end end + it "only calls request middleware once" do + stub_request(:get, "www.example.com") + + middleware = Class.new do + def self.called! + @called = called + 1 + end + + def self.called + @called || 0 + end + + def request(client, head, body) + self.class.called! + head, body + end + end + + EM.run do + conn = EventMachine::HttpRequest.new('http://www.example.com/') + conn.use middleware + http = conn.get + http.callback do + expect(middleware.called).to eq(1) + EM.stop + end + end + end + let(:response_middleware) do Class.new do def response(resp) @@ -119,6 +148,33 @@ context 'making a real request', net_connect: true do before { WebMock.allow_net_connect! } include_examples "em-http-request middleware/after_request hook integration" + + it "only calls request middleware once" do + middleware = Class.new do + def self.called! + @called = called + 1 + end + + def self.called + @called || 0 + end + + def request(client, head, body) + self.class.called! + head, body + end + end + + EM.run do + conn = EventMachine::HttpRequest.new(webmock_server_url) + conn.use middleware + http = conn.get + http.callback do + expect(middleware.called).to eq(1) + EM.stop + end + end + end end context 'when the request is stubbed' do
View file
_service:tar_scm:webmock-3.5.1.gem/data/spec/acceptance/em_http_request/em_http_request_spec_helper.rb -> _service:tar_scm:webmock-3.18.1.gem/data/spec/acceptance/em_http_request/em_http_request_spec_helper.rb
Changed
@@ -16,7 +16,7 @@ error_set = false uri = Addressable::URI.heuristic_parse(uri) EventMachine.run { - request = EventMachine::HttpRequest.new("#{uri.normalize.to_s}") + request = EventMachine::HttpRequest.new("#{uri.normalize.to_s}", ssl: {verify_peer: true}) http = request.send(method, { timeout: 30, body: options:body, @@ -50,7 +50,7 @@ end def client_timeout_exception_class - "WebMock timeout error" + 'Errno::ETIMEDOUT' end def connection_refused_exception_class
View file
_service:tar_scm:webmock-3.5.1.gem/data/spec/acceptance/excon/excon_spec.rb -> _service:tar_scm:webmock-3.18.1.gem/data/spec/acceptance/excon/excon_spec.rb
Changed
@@ -20,7 +20,7 @@ it "should support excon response_block for real requests", net_connect: true do a = WebMock.allow_net_connect! - r = Excon.new('http://httpstat.us/200', headers: { "Accept" => "*" }). + r = Excon.new('https://httpstat.us/200', headers: { "Accept" => "*" }). get(response_block: lambda {|e, remaining, total| a << e}, chunk_size: 1) expect(a).to eq("2", "0", "0", " ", "O", "K") expect(r.body).to eq("") @@ -41,7 +41,7 @@ WebMock.after_request { |_, res| response = res } - r = Excon.new('http://httpstat.us/200', headers: { "Accept" => "*" }). + r = Excon.new('https://httpstat.us/200', headers: { "Accept" => "*" }). get(response_block: lambda {|e, remaining, total| a << e}, chunk_size: 1) expect(response.body).to eq("200 OK") expect(a).to eq("2", "0", "0", " ", "O", "K")
View file
_service:tar_scm:webmock-3.5.1.gem/data/spec/acceptance/excon/excon_spec_helper.rb -> _service:tar_scm:webmock-3.18.1.gem/data/spec/acceptance/excon/excon_spec_helper.rb
Changed
@@ -28,6 +28,8 @@ res end + Excon.set_raise_on_warnings!(true) + OpenStruct.new \ body: response.body, headers: headers,
View file
_service:tar_scm:webmock-3.5.1.gem/data/spec/acceptance/http_rb/http_rb_spec.rb -> _service:tar_scm:webmock-3.18.1.gem/data/spec/acceptance/http_rb/http_rb_spec.rb
Changed
@@ -72,6 +72,17 @@ end context "streamer" do + it "can be read to a provided buffer" do + stub_request(:get, "example.com/foo") + .to_return(status: 200, body: "Hello world! ") + response = HTTP.get "http://example.com/foo" + + buffer = "" + response.body.readpartial(1024, buffer) + + expect(buffer).to eq "Hello world! " + end + it "can be closed" do stub_request :get, "example.com/foo" response = HTTP.get "http://example.com/foo"
View file
_service:tar_scm:webmock-3.5.1.gem/data/spec/acceptance/manticore/manticore_spec.rb -> _service:tar_scm:webmock-3.18.1.gem/data/spec/acceptance/manticore/manticore_spec.rb
Changed
@@ -51,6 +51,57 @@ response = Manticore.head("http://example-foo.com") expect(response.code).to eq(204) end + + context "when a custom failure handler is defined" do + let(:failure_handler) { proc {} } + + before do + allow(failure_handler).to receive(:call).with(kind_of(Manticore::Timeout)) do |ex| + raise ex + end + end + + it "handles timeouts by invoking the failure handler" do + stub_request(:get, "http://example-foo.com").to_timeout + request = Manticore.get("http://example-foo.com").tap do |req| + req.on_failure(&failure_handler) + end + expect { request.call }.to raise_error(Manticore::Timeout) + expect(failure_handler).to have_received(:call) + end + end + + context 'when used in a streaming mode' do + let(:webmock_server_url) {"http://#{WebMockServer.instance.host_with_port}/"} + let(:result_chunks) { } + + def manticore_streaming_get + Manticore.get(webmock_server_url).tap do |req| + req.on_success do |response| + response.body do |chunk| + result_chunks << chunk + end + end + end + end + + context 'when connections are allowed' do + it 'works' do + WebMock.allow_net_connect! + expect { manticore_streaming_get.call }.to_not raise_error + expect(result_chunks).to_not be_empty + end + end + + context 'when stubbed' do + it 'works' do + stub_body = 'hello!' + stub_request(:get, webmock_server_url).to_return(body: stub_body) + expect { manticore_streaming_get.call }.to_not raise_error + expect(result_chunks).to eq stub_body + end + end + end end end end
View file
_service:tar_scm:webmock-3.5.1.gem/data/spec/acceptance/net_http/net_http_shared.rb -> _service:tar_scm:webmock-3.18.1.gem/data/spec/acceptance/net_http/net_http_shared.rb
Changed
@@ -1,3 +1,5 @@ +require 'set' + shared_examples_for "Net::HTTP" do describe "when making real requests", net_connect: true do let(:port){ WebMockServer.instance.port } @@ -26,21 +28,56 @@ it "should connect only once when connected on start", net_connect: true do @http = Net::HTTP.new('localhost', port) - socket_id_before_request = socket_id_after_request = nil + socket_before_request = socket_after_request = nil @http.start {|conn| - socket_id_before_request = conn.instance_variable_get(:@socket).object_id + socket_before_request = conn.instance_variable_get(:@socket) conn.request(Net::HTTP::Get.new("/")) - socket_id_after_request = conn.instance_variable_get(:@socket).object_id + socket_after_request = conn.instance_variable_get(:@socket) } - if !defined?(WebMock::Config) || WebMock::Config.instance.net_http_connect_on_start - expect(socket_id_before_request).not_to eq(nil.object_id) - expect(socket_id_after_request).not_to eq(nil.object_id) - expect(socket_id_after_request).to eq(socket_id_before_request) + if !defined?(WebMock::NetHTTPUtility) || WebMock::Config.instance.net_http_connect_on_start + expect(socket_before_request).to be_a(Net::BufferedIO) + expect(socket_after_request).to be_a(Net::BufferedIO) + expect(socket_after_request).to be(socket_before_request) + else + expect(socket_before_request).to be_a(StubSocket) + expect(socket_after_request).to be_a(Net::BufferedIO) + end + end + + it "should allow sending multiple requests when persisted", net_connect: true do + @http = Net::HTTP.new('example.org') + @http.start + expect(@http.get("/")).to be_a(Net::HTTPSuccess) + expect(@http.get("/")).to be_a(Net::HTTPSuccess) + expect(@http.get("/")).to be_a(Net::HTTPSuccess) + @http.finish + end + + it "should not leak file descriptors", net_connect: true do + sockets = Set.new + + @http = Net::HTTP.new('example.org') + @http.start + sockets << @http.instance_variable_get(:@socket) + @http.get("/") + sockets << @http.instance_variable_get(:@socket) + @http.get("/") + sockets << @http.instance_variable_get(:@socket) + @http.get("/") + sockets << @http.instance_variable_get(:@socket) + @http.finish + + if !defined?(WebMock::NetHTTPUtility) || WebMock.net_http_connect_on_start?(Addressable::URI.parse("http://example.com/")) + expect(sockets.length).to eq(1) + expect(sockets.to_a0).to be_a(Net::BufferedIO) else - expect(socket_id_before_request).to eq(nil.object_id) - expect(socket_id_after_request).not_to eq(nil.object_id) + expect(sockets.length).to eq(2) + expect(sockets.to_a0).to be_a(StubSocket) + expect(sockets.to_a1).to be_a(Net::BufferedIO) end + + expect(sockets.all?(&:closed?)).to be(true) end it "should pass the read_timeout value on", net_connect: true do
View file
_service:tar_scm:webmock-3.5.1.gem/data/spec/acceptance/net_http/net_http_spec.rb -> _service:tar_scm:webmock-3.18.1.gem/data/spec/acceptance/net_http/net_http_spec.rb
Changed
@@ -115,33 +115,16 @@ expect(Net::HTTP.start("www.example.com") { |http| http.request(req)}.body).to eq("abc") end - it "raises an ArgumentError if passed headers as symbols if RUBY_VERSION < 2.3.0" do + it "raises an ArgumentError if passed headers as symbols" do uri = URI.parse("http://google.com/") http = Net::HTTP.new(uri.host, uri.port) request = Net::HTTP::Get.new(uri.request_uri) + request:InvalidHeaderSinceItsASymbol = "this will not be valid" - # Net::HTTP calls downcase on header keys assigned with = - # In Ruby 1.8.7 symbols do not respond to downcase - # - # Meaning you can not assign header keys as symbols in ruby 1.8.7 using = - if :symbol.respond_to?(:downcase) - request:InvalidHeaderSinceItsASymbol = "this will not be valid" - else - request.instance_eval do - @header = request.to_hash.merge({InvalidHeaderSinceItsASymbol: "this will not be valid"}) - end - end - - if Gem::Version.new(RUBY_VERSION.dup) < Gem::Version.new('2.3.0') - expect do - http.request(request) - end.to raise_error ArgumentError, "Net:HTTP does not accept headers as symbols" - else - stub_http_request(:get, "google.com").with(headers: { InvalidHeaderSinceItsASymbol: "this will not be valid" }) - expect do - http.request(request) - end.not_to raise_error - end + stub_http_request(:get, "google.com").with(headers: { InvalidHeaderSinceItsASymbol: "this will not be valid" }) + expect do + http.request(request) + end.not_to raise_error end it "should handle multiple values for the same response header" do @@ -201,6 +184,34 @@ expect(Net::HTTP.get_response(Addressable::URI.parse('http://www.example.com/hello?a=1')).body).to eq("abc") end + it "should support method calls on stubbed socket" do + WebMock.allow_net_connect! + stub_request(:get, 'www.google.com')#.with(headers: {"My-Header" => 99}) + req = Net::HTTP::Get.new('/') + Net::HTTP.start('www.google.com') do |http| + http.request(req, '') + socket = http.instance_variable_get(:@socket) + expect(socket).to be_a(StubSocket) + expect { socket.io.setsockopt(Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1) }.to_not raise_error + end + end + + if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('2.7.0') + it "uses the StubSocket to provide IP address" do + Net::HTTP.start("http://example.com") do |http| + expect(http.ipaddr).to eq("127.0.0.1") + end + end + end + + it "defines common socket methods" do + Net::HTTP.start("http://example.com") do |http| + socket = http.instance_variable_get(:@socket) + expect(socket.io.ssl_version).to eq("TLSv1.3") + expect(socket.io.cipher).to eq("TLS_AES_128_GCM_SHA256", "TLSv1.3", 128, 128) + end + end + describe "connecting on Net::HTTP.start" do before(:each) do @http = Net::HTTP.new('www.google.com', 443) @@ -242,6 +253,21 @@ } end + it "should connect to the server on start when allowlisted", net_connect: true do + WebMock.disable_net_connect!(allow: "www.google.com", net_http_connect_on_start: "www.google.com") + @http.start {|conn| + cert = OpenSSL::X509::Certificate.new conn.peer_cert + expect(cert).to be_a(OpenSSL::X509::Certificate) + } + end + + it "should not connect to the server on start when not allowlisted", net_connect: true do + WebMock.disable_net_connect!(allow: "www.google.com", net_http_connect_on_start: "www.yahoo.com") + @http.start {|conn| + expect(conn.peer_cert).to be_nil + } + end + it "should connect to the server if the URI matches an regex", net_connect: true do WebMock.disable_net_connect!(allow: /google.com/) Net::HTTP.get('www.google.com','/') @@ -270,6 +296,13 @@ it_should_behave_like "Net::HTTP" end + describe "when net_http_connect_on_start is a specific host" do + before(:each) do + WebMock.allow_net_connect!(net_http_connect_on_start: "localhost") + end + it_should_behave_like "Net::HTTP" + end + describe 'after_request callback support', net_connect: true do let(:expected_body_regex) { /hello world/ } @@ -328,4 +361,35 @@ http.request(req, '') end end + + describe "hostname handling" do + it "should set brackets around the hostname if it is an IPv6 address" do + net_http = Net::HTTP.new('b2dc:5bdf:4f0d::3014:e0ca', 80) + path = '/example.jpg' + expect(WebMock::NetHTTPUtility.get_uri(net_http, path)).to eq('http://b2dc:5bdf:4f0d::3014:e0ca:80/example.jpg') + end + + it "should not set brackets around the hostname if it is already wrapped by brackets" do + net_http = Net::HTTP.new('b2dc:5bdf:4f0d::3014:e0ca', 80) + path = '/example.jpg' + expect(WebMock::NetHTTPUtility.get_uri(net_http, path)).to eq('http://b2dc:5bdf:4f0d::3014:e0ca:80/example.jpg') + end + + it "should not set brackets around the hostname if it is an IPv4 address" do + net_http = Net::HTTP.new('181.152.137.168', 80) + path = '/example.jpg' + expect(WebMock::NetHTTPUtility.get_uri(net_http, path)).to eq('http://181.152.137.168:80/example.jpg') + end + + it "should not set brackets around the hostname if it is a domain" do + net_http = Net::HTTP.new('www.example.com', 80) + path = '/example.jpg' + expect(WebMock::NetHTTPUtility.get_uri(net_http, path)).to eq('http://www.example.com:80/example.jpg') + end + + it "does not require a path" do + net_http = Net::HTTP.new('www.example.com', 80) + expect(WebMock::NetHTTPUtility.get_uri(net_http)).to eq('http://www.example.com:80') + end + end end
View file
_service:tar_scm:webmock-3.5.1.gem/data/spec/acceptance/net_http/real_net_http_spec.rb -> _service:tar_scm:webmock-3.18.1.gem/data/spec/acceptance/net_http/real_net_http_spec.rb
Changed
@@ -17,4 +17,4 @@ end it_should_behave_like "Net::HTTP" -end \ No newline at end of file +end
View file
_service:tar_scm:webmock-3.5.1.gem/data/spec/acceptance/patron/patron_spec.rb -> _service:tar_scm:webmock-3.18.1.gem/data/spec/acceptance/patron/patron_spec.rb
Changed
@@ -93,31 +93,29 @@ @sess.copy("/abc", "/def") end - if /^1\.9/ === RUBY_VERSION - describe "handling encoding same way as patron" do - around(:each) do |example| - @encoding = Encoding.default_internal - Encoding.default_internal = "UTF-8" - example.run - Encoding.default_internal = @encoding - end + describe "handling encoding same way as patron" do + around(:each) do |example| + @encoding = Encoding.default_internal + Encoding.default_internal = "UTF-8" + example.run + Encoding.default_internal = @encoding + end - it "should not encode body with default encoding" do - stub_request(:get, "www.example.com"). - to_return(body: "Øl") + it "should not encode body with default encoding" do + stub_request(:get, "www.example.com"). + to_return(body: "Øl") - expect(@sess.get("").body.encoding).to eq(Encoding::ASCII_8BIT) - expect(@sess.get("").inspectable_body.encoding).to eq(Encoding::UTF_8) - end + expect(@sess.get("").body.encoding).to eq(Encoding::ASCII_8BIT) + expect(@sess.get("").inspectable_body.encoding).to eq(Encoding::UTF_8) + end - it "should not encode body to default internal" do - stub_request(:get, "www.example.com"). - to_return(headers: {'Content-Type' => 'text/html; charset=iso-8859-1'}, - body: "Øl".encode("iso-8859-1")) + it "should not encode body to default internal" do + stub_request(:get, "www.example.com"). + to_return(headers: {'Content-Type' => 'text/html; charset=iso-8859-1'}, + body: "Øl".encode("iso-8859-1")) - expect(@sess.get("").body.encoding).to eq(Encoding::ASCII_8BIT) - expect(@sess.get("").decoded_body.encoding).to eq(Encoding.default_internal) - end + expect(@sess.get("").body.encoding).to eq(Encoding::ASCII_8BIT) + expect(@sess.get("").decoded_body.encoding).to eq(Encoding.default_internal) end end end
View file
_service:tar_scm:webmock-3.5.1.gem/data/spec/acceptance/patron/patron_spec_helper.rb -> _service:tar_scm:webmock-3.18.1.gem/data/spec/acceptance/patron/patron_spec_helper.rb
Changed
@@ -28,8 +28,8 @@ end end - status_line_pattern = %r(\AHTTP/(\d+\.\d+)\s+(\d\d\d)\s*(^\r\n+)?) - message = response.status_line.match(status_line_pattern)3 || "" + status_line_pattern = %r(\AHTTP/(\d+(\.\d+)?)\s+(\d\d\d)\s*(^\r\n+)?) + message = response.status_line.match(status_line_pattern)4 || "" OpenStruct.new({ body: response.body,
View file
_service:tar_scm:webmock-3.5.1.gem/data/spec/acceptance/shared/allowing_and_disabling_net_connect.rb -> _service:tar_scm:webmock-3.18.1.gem/data/spec/acceptance/shared/allowing_and_disabling_net_connect.rb
Changed
@@ -91,7 +91,7 @@ describe "is not allowed, with exceptions" do describe "allowing by host string" do before :each do - WebMock.disable_net_connect!(allow: 'httpstat.us') + WebMock.disable_net_connect!(allow: 'https://httpstat.us') end context "when the host is not allowed" do @@ -109,13 +109,13 @@ context "when the host is allowed" do it "should return stubbed response if request was stubbed" do - stub_request(:get, 'httpstat.us/200').to_return(body: "abc") - expect(http_request(:get, "http://httpstat.us/200").body).to eq("abc") + stub_request(:get, 'https://httpstat.us/200').to_return(body: "abc") + expect(http_request(:get, "https://httpstat.us/200").body).to eq("abc") end # WARNING: this makes a real HTTP request! it "should make a real request to allowed host", net_connect: true do - expect(http_request(:get, "http://httpstat.us/200").status).to eq('200') + expect(http_request(:get, "https://httpstat.us/200").status).to eq('200') end end end @@ -229,13 +229,13 @@ context "when the host is allowed" do it "should return stubbed response if request was stubbed" do - stub_request(:get, 'httpstat.us/200').to_return(body: "abc") - expect(http_request(:get, "http://httpstat.us/200").body).to eq("abc") + stub_request(:get, 'https://httpstat.us/200').to_return(body: "abc") + expect(http_request(:get, "https://httpstat.us/200").body).to eq("abc") end # WARNING: this makes a real HTTP request! it "should make a real request to allowed host", net_connect: true do - expect(http_request(:get, "http://httpstat.us/200").status).to eq('200') + expect(http_request(:get, "https://httpstat.us/200").status).to eq('200') end it "should make a real request if request is allowed by path regexp and url contains default port", net_connect: true do @@ -266,20 +266,20 @@ context "when the host is allowed" do it "should return stubbed response if request was stubbed" do - stub_request(:get, 'httpstat.us/200').to_return(body: "abc") - expect(http_request(:get, "http://httpstat.us/200").body).to eq("abc") + stub_request(:get, 'https://httpstat.us/200').to_return(body: "abc") + expect(http_request(:get, "https://httpstat.us/200").body).to eq("abc") end # WARNING: this makes a real HTTP request! it "should make a real request to allowed host", net_connect: true do - expect(http_request(:get, "http://httpstat.us/200").status).to eq('200') + expect(http_request(:get, "https://httpstat.us/200").status).to eq('200') end end end describe "allowing by a list of the above" do before :each do - WebMock.disable_net_connect!(allow: lambda{|_| false }, %r{foobar}, 'httpstat.us') + WebMock.disable_net_connect!(allow: lambda{|_| false }, %r{foobar}, 'https://httpstat.us') end context "when the host is not allowed" do @@ -297,13 +297,13 @@ context "when the host is allowed" do it "should return stubbed response if request was stubbed" do - stub_request(:get, 'httpstat.us/200').to_return(body: "abc") - expect(http_request(:get, "http://httpstat.us/200").body).to eq("abc") + stub_request(:get, 'https://httpstat.us/200').to_return(body: "abc") + expect(http_request(:get, "https://httpstat.us/200").body).to eq("abc") end # WARNING: this makes a real HTTP request! it "should make a real request to allowed host", net_connect: true do - expect(http_request(:get, "http://httpstat.us/200").status).to eq('200') + expect(http_request(:get, "https://httpstat.us/200").status).to eq('200') end end end
View file
_service:tar_scm:webmock-3.5.1.gem/data/spec/acceptance/shared/callbacks.rb -> _service:tar_scm:webmock-3.18.1.gem/data/spec/acceptance/shared/callbacks.rb
Changed
@@ -102,7 +102,7 @@ WebMock.after_request(except: :other_lib) do |_, response| @response = response end - http_request(:get, "http://httpstat.us/201", headers: { "Accept" => "*" }) + http_request(:get, "https://httpstat.us/201", headers: { "Accept" => "*" }) end it "should pass real response to callback with status and message" do @@ -111,7 +111,8 @@ end it "should pass real response to callback with headers" do - expect(@response.headers"Content-Length").to eq("11") + expect(@response.headers"Server").to eq( "Kestrel") + expect(@response.headers"Content-Length").to eq("11") unless adapter_info.include?(:no_content_length_header) end it "should pass response to callback with body" do
View file
_service:tar_scm:webmock-3.5.1.gem/data/spec/acceptance/shared/complex_cross_concern_behaviors.rb -> _service:tar_scm:webmock-3.18.1.gem/data/spec/acceptance/shared/complex_cross_concern_behaviors.rb
Changed
@@ -18,7 +18,7 @@ expect(played_back_response).to eq(real_response) end - let(:no_content_url) { 'http://httpstat.us/204' } + let(:no_content_url) { 'https://httpstat.us/204' } nil, ''.each do |stub_val| it "returns the same value (nil or "") for a request stubbed as #{stub_val.inspect} that a real empty response has", net_connect: true do unless http_library == :curb
View file
_service:tar_scm:webmock-3.5.1.gem/data/spec/acceptance/shared/request_expectations.rb -> _service:tar_scm:webmock-3.18.1.gem/data/spec/acceptance/shared/request_expectations.rb
Changed
@@ -172,6 +172,13 @@ expect(a_request(:get, "www.example.com").with(query: hash_excluding(a: 'b', 'c'))).to have_been_made }.not_to raise_error end + + it 'should satisfy expectation if the request was executed with an empty array in the query params' do + expect { + http_request(:get, "http://www.example.com/?a") + expect(a_request(:get, "www.example.com").with(query: hash_including(a: ))).to have_been_made + }.not_to raise_error + end end context "when using flat array notation" do
View file
_service:tar_scm:webmock-3.5.1.gem/data/spec/acceptance/shared/returning_declared_responses.rb -> _service:tar_scm:webmock-3.18.1.gem/data/spec/acceptance/shared/returning_declared_responses.rb
Changed
@@ -64,7 +64,10 @@ it "should return response with declared headers" do stub_request(:get, "www.example.com").to_return(headers: SAMPLE_HEADERS) response = http_request(:get, "http://www.example.com/") - expect(response.headers"Content-Length").to eq("8888") + expect(response.headers"Accept").to eq("application/json") + unless adapter_info.include?(:no_content_length_header) + expect(response.headers"Content-Length").to eq("8888") + end end it "should return response with declared headers even if there are multiple headers with the same key" do @@ -171,13 +174,22 @@ end it "should return recorded headers" do - expect(@response.headers).to eq({ - "Date"=>"Sat, 23 Jan 2010 01:01:05 GMT", - "Content-Type"=>"text/html; charset=UTF-8", - "Content-Length"=>"419", - "Connection"=>"Keep-Alive", - "Accept"=>"image/jpeg, image/png" - }) + if adapter_info.include?(:no_content_length_header) + expect(@response.headers).to eq({ + "Date"=>"Sat, 23 Jan 2010 01:01:05 GMT", + "Content-Type"=>"text/html; charset=UTF-8", + "Connection"=>"Keep-Alive", + "Accept"=>"image/jpeg, image/png" + }) + else + expect(@response.headers).to eq({ + "Date"=>"Sat, 23 Jan 2010 01:01:05 GMT", + "Content-Type"=>"text/html; charset=UTF-8", + "Content-Length"=>"419", + "Connection"=>"Keep-Alive", + "Accept"=>"image/jpeg, image/png" + }) + end end it "should return recorded body" do @@ -205,13 +217,22 @@ end it "should return recorded headers" do - expect(@response.headers).to eq({ - "Date"=>"Sat, 23 Jan 2010 01:01:05 GMT", - "Content-Type"=>"text/html; charset=UTF-8", - "Content-Length"=>"419", - "Connection"=>"Keep-Alive", - "Accept"=>"image/jpeg, image/png" - }) + if adapter_info.include?(:no_content_length_header) + expect(@response.headers).to eq({ + "Date"=>"Sat, 23 Jan 2010 01:01:05 GMT", + "Content-Type"=>"text/html; charset=UTF-8", + "Connection"=>"Keep-Alive", + "Accept"=>"image/jpeg, image/png" + }) + else + expect(@response.headers).to eq({ + "Date"=>"Sat, 23 Jan 2010 01:01:05 GMT", + "Content-Type"=>"text/html; charset=UTF-8", + "Content-Length"=>"419", + "Connection"=>"Keep-Alive", + "Accept"=>"image/jpeg, image/png" + }) + end end it "should return recorded body" do
View file
_service:tar_scm:webmock-3.5.1.gem/data/spec/acceptance/shared/stubbing_requests.rb -> _service:tar_scm:webmock-3.18.1.gem/data/spec/acceptance/shared/stubbing_requests.rb
Changed
@@ -68,6 +68,11 @@ stub_request(:get, 'www.example.com').with(query: hash_excluding(a: 'b', 'c')).to_return(body: 'abc') expect(http_request(:get, 'http://www.example.com/?a=c&a=d&b=1').body).to eq('abc') end + + it "should return stubbed response when stub expects an empty array" do + stub_request(:get, 'www.example.com').with(query: { a: }).to_return(body: 'abc') + expect(http_request(:get, 'http://www.example.com/?a').body).to eq('abc') + end end describe "based on method" do @@ -588,6 +593,23 @@ end end end + + context "when global stub should be invoked last" do + before do + WebMock.globally_stub_request(:after_local_stubs) do + { body: "global stub body" } + end + end + + it "uses global stub when non-global stub is not defined" do + expect(http_request(:get, "http://www.example.com/").body).to eq("global stub body") + end + + it "uses non-global stub first" do + stub_request(:get, "www.example.com").to_return(body: 'non-global stub body') + expect(http_request(:get, "http://www.example.com/").body).to eq("non-global stub body") + end + end end describe "when stubbing request with a block evaluated on request" do @@ -635,4 +657,22 @@ }.to raise_error(WebMock::NetConnectNotAllowedError, %r(Real HTTP connections are disabled. Unregistered request: GET http://www.example.com/)) end end + + describe "in Rspec around(:each) hook" do + # order goes + # around(:each) + # before(:each) + # after(:each) + # anything after example.run in around(:each) + around(:each) do |example| + example.run + expect { + http_request(:get, "http://www.example.com/") + }.to_not raise_error # WebMock::NetConnectNotAllowedError + end + + it "should still allow me to make a mocked request" do + stub_request(:get, "www.example.com") + end + end end
View file
_service:tar_scm:webmock-3.5.1.gem/data/spec/support/webmock_server.rb -> _service:tar_scm:webmock-3.18.1.gem/data/spec/support/webmock_server.rb
Changed
@@ -36,6 +36,7 @@ end end server.start do |socket| + socket.read(1) socket.puts <<-EOT.gsub(/^\s+\|/, '') |HTTP/1.1 200 OK\r |Date: Fri, 31 Dec 1999 23:59:59 GMT\r
View file
_service:tar_scm:webmock-3.5.1.gem/data/spec/unit/request_pattern_spec.rb -> _service:tar_scm:webmock-3.18.1.gem/data/spec/unit/request_pattern_spec.rb
Changed
@@ -58,7 +58,7 @@ end it "should raise an error if neither options or block is provided" do - expect { @request_pattern.with() }.to raise_error('#with method invoked with no arguments. Either options hash or block must be specified.') + expect { @request_pattern.with() }.to raise_error('#with method invoked with no arguments. Either options hash or block must be specified. Created a block with do..end? Try creating it with curly braces {} instead.') end end @@ -111,6 +111,21 @@ to match(WebMock::RequestSignature.new(:get, "www.example.com")) end + it "should match if uri matches requesst uri as URI object" do + expect(WebMock::RequestPattern.new(:get, URI.parse("www.example.com"))). + to match(WebMock::RequestSignature.new(:get, "www.example.com")) + end + + it "should match if uri proc pattern returning true" do + expect(WebMock::RequestPattern.new(:get, ->(uri) { true })). + to match(WebMock::RequestSignature.new(:get, "www.example.com")) + end + + it "should not match if uri proc pattern returns false" do + expect(WebMock::RequestPattern.new(:get, ->(uri) { false })). + not_to match(WebMock::RequestSignature.new(:get, "www.example.com")) + end + it "should match if uri Addressable::Template pattern matches unescaped form of request uri" do expect(WebMock::RequestPattern.new(:get, Addressable::Template.new("www.example.com/{any_path}"))). to match(WebMock::RequestSignature.new(:get, "www.example.com/my%20path")) @@ -121,12 +136,41 @@ to match(WebMock::RequestSignature.new(:get, "www.example.com")) end + it "should match if uri Addressable::Template pattern matches request uri without TLD" do + expect(WebMock::RequestPattern.new(:get, Addressable::Template.new("localhost"))). + to match(WebMock::RequestSignature.new(:get, "localhost")) + end + it "should match if Addressable::Template pattern that has ip address host matches request uri" do signature = WebMock::RequestSignature.new(:get, "127.0.0.1:3000/1234") uri = Addressable::Template.new("127.0.0.1:3000/{id}") expect(WebMock::RequestPattern.new(:get, uri)).to match(signature) end + it "should match if Addressable::Template pattern that has ip address host without port matches request uri" do + signature = WebMock::RequestSignature.new(:get, "127.0.0.1/1234") + uri = Addressable::Template.new("127.0.0.1/{id}") + expect(WebMock::RequestPattern.new(:get, uri)).to match(signature) + end + + it "should match if Addressable::Template pattern host matches request uri" do + signature = WebMock::RequestSignature.new(:get, "www.example.com") + uri = Addressable::Template.new("{subdomain}.example.com") + expect(WebMock::RequestPattern.new(:get, uri)).to match(signature) + end + + it "should not match if Addressable::Template pattern host does not match request uri" do + signature = WebMock::RequestSignature.new(:get, "www.bad-example.com") + uri = Addressable::Template.new("{subdomain}.example.com") + expect(WebMock::RequestPattern.new(:get, uri)).not_to match(signature) + end + + it "should match if uri Addressable::Template pattern matches request uri without a schema and a path " do + signature = WebMock::RequestSignature.new(:get, "127.0.0.1:3000") + uri = Addressable::Template.new("127.0.0.1:3000") + expect(WebMock::RequestPattern.new(:get, uri)).to match(signature) + end + it "should match for uris with same parameters as pattern" do expect(WebMock::RequestPattern.new(:get, "www.example.com?a=1&b=2")). to match(WebMock::RequestSignature.new(:get, "www.example.com?a=1&b=2")) @@ -194,7 +238,7 @@ to match(WebMock::RequestSignature.new(:get, "www.example.com?a=b&a=c")) end - it "should match request query params if params don't match" do + it "should not match request query params if params don't match" do expect(WebMock::RequestPattern.new(:get, /.*example.*/, query: {"x" => "b", "c"})). not_to match(WebMock::RequestSignature.new(:get, "www.example.com?a=b&a=c")) end @@ -224,13 +268,85 @@ end end + describe "when uri is described as URI" do + it "should match request query params" do + expect(WebMock::RequestPattern.new(:get, URI.parse("www.example.com"), query: {"a" => "b", "c"})). + to match(WebMock::RequestSignature.new(:get, "www.example.com?a=b&a=c")) + end + + it "should not match request query params if params don't match" do + expect(WebMock::RequestPattern.new(:get, URI.parse("www.example.com"), query: {"x" => "b", "c"})). + not_to match(WebMock::RequestSignature.new(:get, "www.example.com?a=b&a=c")) + end + + it "should match when query params are declared as HashIncluding matcher matching params" do + expect(WebMock::RequestPattern.new(:get, URI.parse("www.example.com"), + query: WebMock::Matchers::HashIncludingMatcher.new({"a" => "b", "c"}))). + to match(WebMock::RequestSignature.new(:get, "www.example.com?a=b&a=c&b=1")) + end + + it "should not match when query params are declared as HashIncluding matcher not matching params" do + expect(WebMock::RequestPattern.new(:get, URI.parse("www.example.com"), + query: WebMock::Matchers::HashIncludingMatcher.new({"x" => "b", "c"}))). + not_to match(WebMock::RequestSignature.new(:get, "www.example.com?a=b&a=c&b=1")) + end + + it "should match when query params are declared as RSpec HashIncluding matcher matching params" do + expect(WebMock::RequestPattern.new(:get, URI.parse("www.example.com"), + query: RSpec::Mocks::ArgumentMatchers::HashIncludingMatcher.new({"a" => "b", "c"}))). + to match(WebMock::RequestSignature.new(:get, "www.example.com?a=b&a=c&b=1")) + end + + it "should not match when query params are declared as RSpec HashIncluding matcher not matching params" do + expect(WebMock::RequestPattern.new(:get, URI.parse("www.example.com"), + query: RSpec::Mocks::ArgumentMatchers::HashIncludingMatcher.new({"a" => "b", "d"}))). + not_to match(WebMock::RequestSignature.new(:get, "www.example.com?a=b&a=c&b=1")) + end + end + + describe "when uri is described as a proc" do + it "should match request query params" do + expect(WebMock::RequestPattern.new(:get, ->(uri) { true }, query: {"a" => "b", "c"})). + to match(WebMock::RequestSignature.new(:get, "www.example.com?a=b&a=c")) + end + + it "should not match request query params if params don't match" do + expect(WebMock::RequestPattern.new(:get, ->(uri) { true }, query: {"x" => "b", "c"})). + not_to match(WebMock::RequestSignature.new(:get, "www.example.com?a=b&a=c")) + end + + it "should match when query params are declared as HashIncluding matcher matching params" do + expect(WebMock::RequestPattern.new(:get, ->(uri) { true }, + query: WebMock::Matchers::HashIncludingMatcher.new({"a" => "b", "c"}))). + to match(WebMock::RequestSignature.new(:get, "www.example.com?a=b&a=c&b=1")) + end + + it "should not match when query params are declared as HashIncluding matcher not matching params" do + expect(WebMock::RequestPattern.new(:get, ->(uri) { true }, + query: WebMock::Matchers::HashIncludingMatcher.new({"x" => "b", "c"}))). + not_to match(WebMock::RequestSignature.new(:get, "www.example.com?a=b&a=c&b=1")) + end + + it "should match when query params are declared as RSpec HashIncluding matcher matching params" do + expect(WebMock::RequestPattern.new(:get, ->(uri) { true }, + query: RSpec::Mocks::ArgumentMatchers::HashIncludingMatcher.new({"a" => "b", "c"}))). + to match(WebMock::RequestSignature.new(:get, "www.example.com?a=b&a=c&b=1")) + end + + it "should not match when query params are declared as RSpec HashIncluding matcher not matching params" do + expect(WebMock::RequestPattern.new(:get, ->(uri) { true }, + query: RSpec::Mocks::ArgumentMatchers::HashIncludingMatcher.new({"a" => "b", "d"}))). + not_to match(WebMock::RequestSignature.new(:get, "www.example.com?a=b&a=c&b=1")) + end + end + describe "when uri is described as Addressable::Template" do it "should raise error if query params are specified" do expect(WebMock::RequestPattern.new(:get, Addressable::Template.new("www.example.com"), query: {"a" => "b", "c"})). to match(WebMock::RequestSignature.new(:get, "www.example.com?a=b&a=c")) end - it "should match request query params if params don't match" do + it "should not match request query params if params don't match" do expect(WebMock::RequestPattern.new(:get, Addressable::Template.new("www.example.com"), query: {"x" => "b", "c"})). not_to match(WebMock::RequestSignature.new(:get, "www.example.com?a=b&a=c")) end @@ -418,69 +534,105 @@ end describe "for request with json body and content type is set to json" do - it "should match when hash matches body" do - expect(WebMock::RequestPattern.new(:post, 'www.example.com', body: body_hash)). - to match(WebMock::RequestSignature.new(:post, "www.example.com", headers: {content_type: 'application/json'}, - body: "{\"a\":\"1\",\"c\":{\"d\":\"e\",\"f\"},\"b\":\"five\"}")) - end + shared_examples "a json body" do + it "should match when hash matches body" do + expect(WebMock::RequestPattern.new(:post, 'www.example.com', body: body_hash)). + to match(WebMock::RequestSignature.new(:post, "www.example.com", headers: {content_type: content_type}, + body: "{\"a\":\"1\",\"c\":{\"d\":\"e\",\"f\"},\"b\":\"five\"}")) + end - it "should match if hash matches body in different form" do - expect(WebMock::RequestPattern.new(:post, 'www.example.com', body: body_hash)). - to match(WebMock::RequestSignature.new(:post, "www.example.com", headers: {content_type: 'application/json'}, - body: "{\"a\":\"1\",\"b\":\"five\",\"c\":{\"d\":\"e\",\"f\"}}")) - end + it "should match if hash matches body in different form" do + expect(WebMock::RequestPattern.new(:post, 'www.example.com', body: body_hash)). + to match(WebMock::RequestSignature.new(:post, "www.example.com", headers: {content_type: content_type}, + body: "{\"a\":\"1\",\"b\":\"five\",\"c\":{\"d\":\"e\",\"f\"}}")) + end + + it "should match if the request body has a top level array" do + expect(WebMock::RequestPattern.new(:post, 'www.example.com', body: {a: 1})). + to match(WebMock::RequestSignature.new(:post, "www.example.com", + headers: {content_type: content_type}, body: "{\"a\":1}"))
View file
_service:tar_scm:webmock-3.5.1.gem/data/spec/unit/request_signature_spec.rb -> _service:tar_scm:webmock-3.18.1.gem/data/spec/unit/request_signature_spec.rb
Changed
@@ -18,7 +18,7 @@ end it "assigns normalized headers" do - expect(WebMock::Util::Headers).to receive(:normalize_headers).with('A' => 'a').and_return('B' => 'b') + allow(WebMock::Util::Headers).to receive(:normalize_headers).with({'A' => 'a'}.freeze).and_return('B' => 'b') expect( WebMock::RequestSignature.new(:get, "www.example.com", headers: {'A' => 'a'}).headers ).to eq({'B' => 'b'}) @@ -125,11 +125,21 @@ expect(subject.url_encoded?).to be true end + it "returns true if the headers are urlencoded with a specified charset" do + subject.headers = { "Content-Type" => "application/x-www-form-urlencoded; charset=UTF-8" } + expect(subject.url_encoded?).to be true + end + it "returns false if the headers are NOT urlencoded" do subject.headers = { "Content-Type" => "application/made-up-format" } expect(subject.url_encoded?).to be false end + it "returns false when no content type header is present" do + subject.headers = { "Some-Header" => "some-value" } + expect(subject.url_encoded?).to be false + end + it "returns false when no headers are set" do subject.headers = nil expect(subject.url_encoded?).to be false @@ -142,11 +152,21 @@ expect(subject.json_headers?).to be true end + it "returns true if the headers are json with a specified charset" do + subject.headers = { "Content-Type" => "application/json; charset=UTF-8" } + expect(subject.json_headers?).to be true + end + it "returns false if the headers are NOT json" do subject.headers = { "Content-Type" => "application/made-up-format" } expect(subject.json_headers?).to be false end + it "returns false when no content type header is present" do + subject.headers = { "Some-Header" => "some-value" } + expect(subject.json_headers?).to be false + end + it "returns false when no headers are set" do subject.headers = nil expect(subject.json_headers?).to be false
View file
_service:tar_scm:webmock-3.5.1.gem/data/spec/unit/request_stub_spec.rb -> _service:tar_scm:webmock-3.18.1.gem/data/spec/unit/request_stub_spec.rb
Changed
@@ -50,6 +50,41 @@ end + describe "to_return_json" do + + it "should raise if a block is given" do + expect { + @request_stub.to_return_json(body: "abc", status: 500) { puts "don't call me" } + }.to raise_error(ArgumentError, '#to_return_json does not support passing a block') + end + + it "should assign responses normally" do + @request_stub.to_return_json({body: "abc"}, {body: "def"}) + expect(@request_stub.response.body, @request_stub.response.body).to eq("abc", "def") + end + + it "should json-ify a Hash body" do + @request_stub.to_return_json(body: {abc: "def"}, status: 500) + expect(@request_stub.response.body).to eq({abc: "def"}.to_json) + expect(@request_stub.response.status).to eq(500, "") + end + + it "should apply the content_type header" do + @request_stub.to_return_json(body: {abc: "def"}, status: 500) + expect(@request_stub.response.headers).to eq({"Content-Type"=>"application/json"}) + end + + it "should preserve existing headers" do + @request_stub.to_return_json(headers: {"A" => "a"}, body: "") + expect(@request_stub.response.headers).to eq({"A"=>"a", "Content-Type"=>"application/json"}) + end + + it "should allow callsites to override content_type header" do + @request_stub.to_return_json(headers: {content_type: 'application/super-special-json'}) + expect(@request_stub.response.headers).to eq({"Content-Type"=>"application/super-special-json"}) + end + end + describe "then" do it "should return stub without any modifications, acting as syntactic sugar" do expect(@request_stub.then).to eq(@request_stub)
View file
_service:tar_scm:webmock-3.5.1.gem/data/spec/unit/response_spec.rb -> _service:tar_scm:webmock-3.18.1.gem/data/spec/unit/response_spec.rb
Changed
@@ -31,7 +31,7 @@ end it "should report normalized headers" do - expect(WebMock::Util::Headers).to receive(:normalize_headers).with('A' => 'a').and_return('B' => 'b') + allow(WebMock::Util::Headers).to receive(:normalize_headers).with({'A' => 'a'}.freeze).and_return('B' => 'b') @response = WebMock::Response.new(headers: {'A' => 'a'}) expect(@response.headers).to eq({'B' => 'b'}) end @@ -130,14 +130,46 @@ # Users of webmock commonly make the mistake of stubbing the response # body to return a hash, to prevent this: # - it "should error if not given one of the allowed types" do + it "should error if given a non-allowed type: a hash" do expect { WebMock::Response.new(body: Hash.new) }.to \ raise_error(WebMock::Response::InvalidBody) end + it "should error if given a non-allowed type: something that is not a hash" do + expect { WebMock::Response.new(body: 123) }.to \ + raise_error(WebMock::Response::InvalidBody) + end end describe "from raw response" do + describe "when input is a StringIO" do + before(:each) do + @io = StringIO.new(File.read(CURL_EXAMPLE_OUTPUT_PATH)) + @response = WebMock::Response.new(@io) + end + + it "should read status" do + expect(@response.status).to eq(202, "OK") + end + + it "should read headers" do + expect(@response.headers).to eq( + "Date"=>"Sat, 23 Jan 2010 01:01:05 GMT", + "Content-Type"=>"text/html; charset=UTF-8", + "Content-Length"=>"419", + "Connection"=>"Keep-Alive", + "Accept"=>"image/jpeg, image/png" + ) + end + + it "should read body" do + expect(@response.body.size).to eq(419) + end + + it "should close IO" do + expect(@io).to be_closed + end + end describe "when input is IO" do before(:each) do @@ -152,12 +184,12 @@ it "should read headers" do expect(@response.headers).to eq({ - "Date"=>"Sat, 23 Jan 2010 01:01:05 GMT", - "Content-Type"=>"text/html; charset=UTF-8", - "Content-Length"=>"419", - "Connection"=>"Keep-Alive", - "Accept"=>"image/jpeg, image/png" - }) + "Date"=>"Sat, 23 Jan 2010 01:01:05 GMT", + "Content-Type"=>"text/html; charset=UTF-8", + "Content-Length"=>"419", + "Connection"=>"Keep-Alive", + "Accept"=>"image/jpeg, image/png" + }) end it "should read body" do @@ -182,12 +214,12 @@ it "should read headers" do expect(@response.headers).to eq({ - "Date"=>"Sat, 23 Jan 2010 01:01:05 GMT", - "Content-Type"=>"text/html; charset=UTF-8", - "Content-Length"=>"419", - "Connection"=>"Keep-Alive", - "Accept"=>"image/jpeg, image/png" - }) + "Date"=>"Sat, 23 Jan 2010 01:01:05 GMT", + "Content-Type"=>"text/html; charset=UTF-8", + "Content-Length"=>"419", + "Connection"=>"Keep-Alive", + "Accept"=>"image/jpeg, image/png" + }) end it "should read body" do @@ -234,11 +266,11 @@ it "should evaluate new response with evaluated options" do request_signature = WebMock::RequestSignature.new(:post, "www.example.com", body: "abc", headers: {'A' => 'a'}) response = WebMock::DynamicResponse.new(lambda {|request| - { - body: request.body, - headers: request.headers, - status: 302 - } + { + body: request.body, + headers: request.headers, + status: 302 + } }) evaluated_response = response.evaluate(request_signature) expect(evaluated_response.body).to eq("abc")
View file
_service:tar_scm:webmock-3.5.1.gem/data/spec/unit/util/query_mapper_spec.rb -> _service:tar_scm:webmock-3.18.1.gem/data/spec/unit/util/query_mapper_spec.rb
Changed
@@ -147,4 +147,11 @@ expect(subject.values_to_query values).to eq query expect(subject.query_to_values query).to eq values end + + it 'converts an empty array to ?' do + query = "one%5B%5D" + values = {"one" => } + expect(subject.values_to_query values).to eq query + expect(subject.query_to_values query).to eq values + end end
View file
_service:tar_scm:webmock-3.5.1.gem/data/spec/unit/util/uri_spec.rb -> _service:tar_scm:webmock-3.18.1.gem/data/spec/unit/util/uri_spec.rb
Changed
@@ -1,6 +1,5 @@ require 'spec_helper' - URIS_WITHOUT_PATH_OR_PARAMS = "www.example.com", @@ -65,7 +64,6 @@ "http://www.example.com:88/" .sort - URIS_FOR_HTTPS = "https://www.example.com", @@ -74,6 +72,49 @@ "https://www.example.com:443/" .sort +URIS_FOR_LOCALHOST = + + "localhost", + "localhost/", + "localhost:80", + "localhost:80/", + "http://localhost", + "http://localhost/", + "http://localhost:80", + "http://localhost:80/" +.sort + +URIS_WITH_SCHEME = + + "http://www.example.com", + "http://www.example.com/", + "http://www.example.com:80", + "http://www.example.com:80/" +.sort + +URIS_WITH_COLON_IN_PATH = + + + "https://example.com/a/b:80", + "https://example.com:443/a/b:80", + .sort, + + "https://example.com:443/a/b:443", + "https://example.com/a/b:443", + .sort, + + "http://example.com/a/b:443", + "example.com/a/b:443", + "http://example.com:80/a/b:443", + "example.com:80/a/b:443", + .sort, + + "http://example.com/a/b:80", + "example.com/a/b:80", + "http://example.com:80/a/b:80", + "example.com:80/a/b:80", + .sort + describe WebMock::Util::URI do @@ -115,6 +156,37 @@ end end + it "should find all variations of the same uri for all variations of host names uris without a period" do + URIS_FOR_LOCALHOST.each do |uri| + expect(WebMock::Util::URI.variations_of_uri_as_strings(uri).sort).to eq(URIS_FOR_LOCALHOST) + end + end + + it "should find all variations of the same uri with scheme for all variations when only_with_scheme is true" do + URIS_WITHOUT_PATH_OR_PARAMS.each do |uri| + variations_of_uri_with_scheme = WebMock::Util::URI.variations_of_uri_as_strings(uri, only_with_scheme: true) + expect(variations_of_uri_with_scheme.sort).to eq(URIS_WITH_SCHEME) + end + end + + it "should not replace :80 or :443 in path" do + URIS_WITH_COLON_IN_PATH.each do |uris| + uris.each do |uri| + expect(WebMock::Util::URI.variations_of_uri_as_strings(uri).sort).to eq(uris) + end + end + end + + it "should find all variations of uris with https, basic auth, a non-standard port and a path" do + uri = "https://~%8A:pass@www.example.com:9000/foo" + variations = + "https://~%8A:pass@www.example.com:9000/foo", + "https://~\x8A:pass@www.example.com:9000/foo".force_encoding(Encoding::ASCII_8BIT) + + + expect(WebMock::Util::URI.variations_of_uri_as_strings(uri)).to eq(variations) + end + end describe "normalized uri equality" do
View file
_service:tar_scm:webmock-3.5.1.gem/data/spec/unit/webmock_spec.rb -> _service:tar_scm:webmock-3.18.1.gem/data/spec/unit/webmock_spec.rb
Changed
@@ -1,11 +1,114 @@ require 'spec_helper' -describe "WebMock version" do - it "should report version" do - expect(WebMock.version).to eq(WebMock::VERSION) +describe "WebMock" do + + describe ".version" do + it "should report version" do + expect(WebMock.version).to eq(WebMock::VERSION) + end + + it "should not require safe_yaml" do + expect(defined?SafeYAML).to eq(nil) + end + + it "should alias enable_net_connect! to allow_net_connect!" do + expect(WebMock.method(:enable_net_connect!)).to eq(WebMock.method(:allow_net_connect!)) + end + + it "should alias disallow_net_connect! to disable_net_connect!" do + expect(WebMock.method(:disallow_net_connect!)).to eq(WebMock.method(:disable_net_connect!)) + end + end + + describe ".net_connect_allowed?" do + context 'enabled globally' do + before do + WebMock.enable_net_connect! + end + + context 'without arguments' do + it 'returns WebMock::Config.instance.allow_net_connect' do + expect(WebMock.net_connect_allowed?).to eql(true) + end + end + end + + context 'disabled with allowed remote string' do + before do + WebMock.disable_net_connect!(allow: "http://192.168.64.2:20031") + end + + context 'without arguments' do + it 'returns WebMock::Config.instance.allow_net_connect' do + expect(WebMock.net_connect_allowed?).to eql(false) + end + end + end + + context 'disabled globally' do + before do + WebMock.disable_net_connect! + end + + context 'without arguments' do + it 'returns WebMock::Config.instance.allow_net_connect' do + expect(WebMock.net_connect_allowed?).to eql(false) + end + end + end end - it "should not require safe_yaml" do - expect(defined?SafeYAML).to eq(nil) + describe ".net_http_connect_on_start?" do + let(:uri) { Addressable::URI.parse("http://example.org:5432") } + + it "will not connect on start when false" do + WebMock.disable_net_connect! + expect(WebMock.net_http_connect_on_start?(uri)).to be(false) + end + + it "will connect on start when true" do + WebMock.disable_net_connect!(net_http_connect_on_start: true) + expect(WebMock.net_http_connect_on_start?(uri)).to be(true) + end + + it "will connect on start when regexp matches" do + WebMock.disable_net_connect!(net_http_connect_on_start: /example/) + expect(WebMock.net_http_connect_on_start?(uri)).to be(true) + end + + it "will not connect on start when regexp does not match" do + WebMock.disable_net_connect!(net_http_connect_on_start: /nope/) + expect(WebMock.net_http_connect_on_start?(uri)).to be(false) + end + + it "will connect on start when host matches" do + WebMock.disable_net_connect!(net_http_connect_on_start: "example.org") + expect(WebMock.net_http_connect_on_start?(uri)).to be(true) + end + + it "will not connect on start when host does not match" do + WebMock.disable_net_connect!(net_http_connect_on_start: "localhost") + expect(WebMock.net_http_connect_on_start?(uri)).to be(false) + end + + it "will connect on start when host + port matches" do + WebMock.disable_net_connect!(net_http_connect_on_start: "example.org:5432") + expect(WebMock.net_http_connect_on_start?(uri)).to be(true) + end + + it "will not connect on start when host + port does not match" do + WebMock.disable_net_connect!(net_http_connect_on_start: "example.org:80") + expect(WebMock.net_http_connect_on_start?(uri)).to be(false) + end + + it "will connect on start when scheme + host + port matches" do + WebMock.disable_net_connect!(net_http_connect_on_start: "http://example.org:5432") + expect(WebMock.net_http_connect_on_start?(uri)).to be(true) + end + + it "will not connect on start when scheme + host + port does not match" do + WebMock.disable_net_connect!(net_http_connect_on_start: "https://example.org:5432") + expect(WebMock.net_http_connect_on_start?(uri)).to be(false) + end end end
View file
_service:tar_scm:webmock-3.5.1.gem/data/test/test_webmock.rb -> _service:tar_scm:webmock-3.18.1.gem/data/test/test_webmock.rb
Changed
@@ -3,4 +3,10 @@ class TestWebMock < Test::Unit::TestCase include SharedTest + + def teardown + # Ensure global Test::Unit teardown was called + assert_empty WebMock::RequestRegistry.instance.requested_signatures.hash + assert_empty WebMock::StubRegistry.instance.request_stubs + end end
View file
_service:tar_scm:webmock-3.5.1.gem/data/webmock.gemspec -> _service:tar_scm:webmock-3.18.1.gem/data/webmock.gemspec
Changed
@@ -8,23 +8,31 @@ s.platform = Gem::Platform::RUBY s.authors = 'Bartosz Blimke' s.email = 'bartosz.blimke@gmail.com' - s.homepage = 'http://github.com/bblimke/webmock' + s.homepage = 'https://github.com/bblimke/webmock' s.summary = %q{Library for stubbing HTTP requests in Ruby.} s.description = %q{WebMock allows stubbing HTTP requests and setting expectations on HTTP requests.} s.license = "MIT" - s.rubyforge_project = 'webmock' + s.metadata = { + 'bug_tracker_uri' => 'https://github.com/bblimke/webmock/issues', + 'changelog_uri' => "https://github.com/bblimke/webmock/blob/v#{s.version}/CHANGELOG.md", + 'documentation_uri' => "https://www.rubydoc.info/gems/webmock/#{s.version}", + 'source_code_uri' => "https://github.com/bblimke/webmock/tree/v#{s.version}", + 'wiki_uri' => 'https://github.com/bblimke/webmock/wiki' + } - s.required_ruby_version = '>= 2.0' + s.required_ruby_version = '>= 2.3' - s.add_dependency 'addressable', '>= 2.3.6' + s.add_dependency 'addressable', '>= 2.8.0' s.add_dependency 'crack', '>= 0.3.2' - s.add_dependency 'hashdiff' + s.add_dependency 'hashdiff', '>= 0.4.0', '< 2.0.0' unless RUBY_PLATFORM =~ /java/ s.add_development_dependency 'patron', '>= 0.4.18' s.add_development_dependency 'curb', '>= 0.7.16' s.add_development_dependency 'typhoeus', '>= 0.5.0' + s.add_development_dependency 'em-http-request', '>= 1.0.2' + s.add_development_dependency 'em-synchrony', '>= 1.0.0' end s.add_development_dependency 'http', '>= 0.8.0' @@ -32,12 +40,12 @@ s.add_development_dependency 'rack', ((RUBY_VERSION < '2.2.2') ? '1.6.0' : '> 1.6') s.add_development_dependency 'rspec', '>= 3.1.0' s.add_development_dependency 'httpclient', '>= 2.2.4' - s.add_development_dependency 'em-http-request', '>= 1.0.2' - s.add_development_dependency 'em-synchrony', '>= 1.0.0' s.add_development_dependency 'excon', '>= 0.27.5' + s.add_development_dependency 'async-http', '>= 0.48.0' s.add_development_dependency 'minitest', '>= 5.0.0' s.add_development_dependency 'test-unit', '>= 3.0.0' s.add_development_dependency 'rdoc', '> 3.5.0' + s.add_development_dependency 'webrick' s.files = `git ls-files`.split("\n") s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
View file
_service:tar_scm:webmock-3.5.1.gem/metadata.gz -> _service:tar_scm:webmock-3.18.1.gem/metadata.gz
Changed
@@ -1,14 +1,14 @@ --- !ruby/object:Gem::Specification name: webmock version: !ruby/object:Gem::Version - version: 3.5.1 + version: 3.18.1 platform: ruby authors: - Bartosz Blimke -autorequire: +autorequire: bindir: bin cert_chain: -date: 2018-12-27 00:00:00.000000000 Z +date: 2022-08-18 00:00:00.000000000 Z dependencies: - !ruby/object:Gem::Dependency name: addressable @@ -16,14 +16,14 @@ requirements: - - ">=" - !ruby/object:Gem::Version - version: 2.3.6 + version: 2.8.0 type: :runtime prerelease: false version_requirements: !ruby/object:Gem::Requirement requirements: - - ">=" - !ruby/object:Gem::Version - version: 2.3.6 + version: 2.8.0 - !ruby/object:Gem::Dependency name: crack requirement: !ruby/object:Gem::Requirement @@ -44,14 +44,20 @@ requirements: - - ">=" - !ruby/object:Gem::Version - version: '0' + version: 0.4.0 + - - "<" + - !ruby/object:Gem::Version + version: 2.0.0 type: :runtime prerelease: false version_requirements: !ruby/object:Gem::Requirement requirements: - - ">=" - !ruby/object:Gem::Version - version: '0' + version: 0.4.0 + - - "<" + - !ruby/object:Gem::Version + version: 2.0.0 - !ruby/object:Gem::Dependency name: patron requirement: !ruby/object:Gem::Requirement @@ -95,6 +101,34 @@ - !ruby/object:Gem::Version version: 0.5.0 - !ruby/object:Gem::Dependency + name: em-http-request + requirement: !ruby/object:Gem::Requirement + requirements: + - - ">=" + - !ruby/object:Gem::Version + version: 1.0.2 + type: :development + prerelease: false + version_requirements: !ruby/object:Gem::Requirement + requirements: + - - ">=" + - !ruby/object:Gem::Version + version: 1.0.2 +- !ruby/object:Gem::Dependency + name: em-synchrony + requirement: !ruby/object:Gem::Requirement + requirements: + - - ">=" + - !ruby/object:Gem::Version + version: 1.0.0 + type: :development + prerelease: false + version_requirements: !ruby/object:Gem::Requirement + requirements: + - - ">=" + - !ruby/object:Gem::Version + version: 1.0.0 +- !ruby/object:Gem::Dependency name: http requirement: !ruby/object:Gem::Requirement requirements: @@ -151,47 +185,33 @@ - !ruby/object:Gem::Version version: 2.2.4 - !ruby/object:Gem::Dependency - name: em-http-request - requirement: !ruby/object:Gem::Requirement - requirements: - - - ">=" - - !ruby/object:Gem::Version - version: 1.0.2 - type: :development - prerelease: false - version_requirements: !ruby/object:Gem::Requirement - requirements: - - - ">=" - - !ruby/object:Gem::Version - version: 1.0.2 -- !ruby/object:Gem::Dependency - name: em-synchrony + name: excon requirement: !ruby/object:Gem::Requirement requirements: - - ">=" - !ruby/object:Gem::Version - version: 1.0.0 + version: 0.27.5 type: :development prerelease: false version_requirements: !ruby/object:Gem::Requirement requirements: - - ">=" - !ruby/object:Gem::Version - version: 1.0.0 + version: 0.27.5 - !ruby/object:Gem::Dependency - name: excon + name: async-http requirement: !ruby/object:Gem::Requirement requirements: - - ">=" - !ruby/object:Gem::Version - version: 0.27.5 + version: 0.48.0 type: :development prerelease: false version_requirements: !ruby/object:Gem::Requirement requirements: - - ">=" - !ruby/object:Gem::Version - version: 0.27.5 + version: 0.48.0 - !ruby/object:Gem::Dependency name: minitest requirement: !ruby/object:Gem::Requirement @@ -234,6 +254,20 @@ - - ">" - !ruby/object:Gem::Version version: 3.5.0 +- !ruby/object:Gem::Dependency + name: webrick + requirement: !ruby/object:Gem::Requirement + requirements: + - - ">=" + - !ruby/object:Gem::Version + version: '0' + type: :development + prerelease: false + version_requirements: !ruby/object:Gem::Requirement + requirements: + - - ">=" + - !ruby/object:Gem::Version + version: '0' description: WebMock allows stubbing HTTP requests and setting expectations on HTTP requests. email: @@ -243,9 +277,9 @@ extra_rdoc_files: files: - ".gemtest" +- ".github/workflows/CI.yml" - ".gitignore" - ".rspec-tm" -- ".travis.yml" - CHANGELOG.md - Gemfile - LICENSE @@ -259,6 +293,7 @@ - lib/webmock/cucumber.rb - lib/webmock/deprecation.rb - lib/webmock/errors.rb +- lib/webmock/http_lib_adapters/async_http_client_adapter.rb - lib/webmock/http_lib_adapters/curb_adapter.rb - lib/webmock/http_lib_adapters/em_http_request_adapter.rb - lib/webmock/http_lib_adapters/excon_adapter.rb @@ -312,6 +347,8 @@ - minitest/test_helper.rb - minitest/test_webmock.rb - minitest/webmock_spec.rb +- spec/acceptance/async_http_client/async_http_client_spec.rb +- spec/acceptance/async_http_client/async_http_client_spec_helper.rb - spec/acceptance/curb/curb_spec.rb - spec/acceptance/curb/curb_spec_helper.rb - spec/acceptance/em_http_request/em_http_request_spec.rb @@ -379,11 +416,16 @@ - test/test_helper.rb - test/test_webmock.rb - webmock.gemspec
View file
_service:tar_scm:webmock-3.5.1.gem/data/.travis.yml
Deleted
@@ -1,21 +0,0 @@ -before_install: - - gem update --system - - gem update bundler -rvm: - - 2.3.8 - - 2.4.5 - - 2.5.3 - - 2.6.0 - - rbx-2 - - ruby-head - - jruby-9.1.17.0 - - jruby-9.2.5.0 - - jruby-head -matrix: - allow_failures: - - rvm: jruby-head - - rvm: ruby-head - - rvm: rbx-2 -# Send builds to container-based infrastructure -# http://docs.travis-ci.com/user/workers/container-based-infrastructure/ -sudo: false
Locations
Projects
Search
Status Monitor
Help
Open Build Service
OBS Manuals
API Documentation
OBS Portal
Reporting a Bug
Contact
Mailing List
Forums
Chat (IRC)
Twitter
Open Build Service (OBS)
is an
openSUSE project
.
浙ICP备2022010568号-2