Module: WebMock::Twirp::StubRequestSnippet

Defined in:
lib/webmock/twirp/stub_request_snippet.rb

Instance Method Summary collapse

Instance Method Details

#to_s(with_response = true) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/webmock/twirp/stub_request_snippet.rb', line 4

def to_s(with_response = true)
  string = "stub_twirp_request"

  filters = [
    @request_stub.twirp_client,
    @request_stub.rpc_name&.inspect,
  ].compact.join(", ")
  string << "(#{filters})" unless filters.empty?

  if attrs = @request_stub.with_attrs
    string << ".with(\n"

    if attrs.is_a?(Hash)
      string << attrs.map do |k, v|
        "  #{k}: #{v.inspect},"
      end.join("\n")
    elsif attrs.is_a?(Proc)
      string << "  { ... }"
    else
      string << "  #{attrs}"
    end

    string << "\n)"
  end

  string
end