Sha256: 1386e74b27faa5da7ffec3f6be2649f315e5f3853c9a36e87bc39017b4c78777

Contents?: true

Size: 1.14 KB

Versions: 16

Compression:

Stored size: 1.14 KB

Contents

# frozen_string_literal: true

module WebMock
  class StubRequestSnippet
    def initialize(request_stub)
      @request_stub = request_stub
    end

    def body_pattern
      request_pattern.body_pattern
    end

    def to_s(with_response = true)
      request_pattern = @request_stub.request_pattern
      string = "stub_request(:#{request_pattern.method_pattern.to_s},".dup
      string << " \"#{request_pattern.uri_pattern.to_s}\")"

      with = "".dup

      if (request_pattern.body_pattern)
        with << "\n    body: #{request_pattern.body_pattern.to_s}"
      end

      if (request_pattern.headers_pattern)
        with << "," unless with.empty?

        with << "\n    headers: #{request_pattern.headers_pattern.pp_to_s}"
      end
      string << ".\n  with(#{with})" unless with.empty?
      if with_response
        if request_pattern.headers_pattern && request_pattern.headers_pattern.matches?({ 'Accept' => "application/json" })
          string << ".\n  to_return(status: 200, body: \"{}\", headers: {})"
        else
          string << ".\n  to_return(status: 200, body: \"\", headers: {})"
        end
      end
      string
    end
  end
end

Version data entries

16 entries across 16 versions & 5 rubygems

Version Path
webmock-3.25.1 lib/webmock/stub_request_snippet.rb
webmock-3.25.0 lib/webmock/stub_request_snippet.rb
tailscale_middleware-0.0.3 vendor/cache/ruby/3.4.0/gems/webmock-3.24.0/lib/webmock/stub_request_snippet.rb
minato_ruby_api_client-0.2.2 vendor/bundle/ruby/3.2.0/gems/webmock-3.23.1/lib/webmock/stub_request_snippet.rb
webmock-3.24.0 lib/webmock/stub_request_snippet.rb
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/webmock-3.23.1/lib/webmock/stub_request_snippet.rb
webmock-3.23.0 lib/webmock/stub_request_snippet.rb
webmock-3.22.0 lib/webmock/stub_request_snippet.rb
webmock-3.21.2 lib/webmock/stub_request_snippet.rb
webmock-3.21.1 lib/webmock/stub_request_snippet.rb
webmock-3.21.0 lib/webmock/stub_request_snippet.rb
webmock-3.20.0 lib/webmock/stub_request_snippet.rb
honeybadger-5.4.0 vendor/bundle/ruby/3.2.0/gems/webmock-3.19.1/lib/webmock/stub_request_snippet.rb
honeybadger-5.3.0 vendor/bundle/ruby/3.2.0/gems/webmock-3.19.1/lib/webmock/stub_request_snippet.rb
webmock-3.19.1 lib/webmock/stub_request_snippet.rb
webmock-3.19.0 lib/webmock/stub_request_snippet.rb