Sha256: 8c031a863cab98e29ae89c5158e9493b1c185c1006370cc45d688be724cf086b

Contents?: true

Size: 1.11 KB

Versions: 64

Compression:

Stored size: 1.11 KB

Contents

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

64 entries across 64 versions & 5 rubygems

Version Path
fluent-plugin-google-cloud-logging-on-prem-0.1.0 vendor/ruby/3.1.0/gems/webmock-3.18.1/lib/webmock/stub_request_snippet.rb
webmock-3.18.1 lib/webmock/stub_request_snippet.rb
webmock-3.18.0 lib/webmock/stub_request_snippet.rb
webmock-3.15.2 lib/webmock/stub_request_snippet.rb
webmock-3.16.2 lib/webmock/stub_request_snippet.rb
webmock-3.16.1 lib/webmock/stub_request_snippet.rb
webmock-3.15.1 lib/webmock/stub_request_snippet.rb
webmock-3.17.1 lib/webmock/stub_request_snippet.rb
webmock-3.17.0 lib/webmock/stub_request_snippet.rb
logstash-output-scalyr-0.2.1.beta vendor/bundle/jruby/2.5.0/gems/webmock-3.13.0/lib/webmock/stub_request_snippet.rb
logstash-output-scalyr-0.2.0 vendor/bundle/jruby/2.5.0/gems/webmock-3.13.0/lib/webmock/stub_request_snippet.rb
logstash-output-scalyr-0.2.0.beta vendor/bundle/jruby/2.5.0/gems/webmock-3.13.0/lib/webmock/stub_request_snippet.rb
logstash-output-scalyr-0.1.26.beta vendor/bundle/jruby/2.5.0/gems/webmock-3.13.0/lib/webmock/stub_request_snippet.rb
logstash-output-scalyr-0.1.25.beta vendor/bundle/jruby/2.5.0/gems/webmock-3.13.0/lib/webmock/stub_request_snippet.rb
logstash-output-scalyr-0.1.24.beta vendor/bundle/jruby/2.5.0/gems/webmock-3.13.0/lib/webmock/stub_request_snippet.rb
logstash-output-scalyr-0.1.23.beta vendor/bundle/jruby/2.5.0/gems/webmock-3.13.0/lib/webmock/stub_request_snippet.rb
logstash-output-scalyr-0.1.22.beta vendor/bundle/jruby/2.5.0/gems/webmock-3.13.0/lib/webmock/stub_request_snippet.rb
logstash-output-scalyr-0.1.21.beta vendor/bundle/jruby/2.5.0/gems/webmock-3.13.0/lib/webmock/stub_request_snippet.rb
logstash-output-scalyr-0.1.20.beta vendor/bundle/jruby/2.5.0/gems/webmock-3.13.0/lib/webmock/stub_request_snippet.rb
webmock-3.14.0 lib/webmock/stub_request_snippet.rb