Class: WebMock::RequestSignatureSnippet

Inherits:
Object
  • Object
show all
Defined in:
lib/webmock/request_signature_snippet.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(request_signature) ⇒ RequestSignatureSnippet

Returns a new instance of RequestSignatureSnippet.



8
9
10
11
# File 'lib/webmock/request_signature_snippet.rb', line 8

def initialize(request_signature)
  @request_signature = request_signature
  @request_stub = RequestStub.from_request_signature(request_signature)
end

Instance Attribute Details

#request_signatureObject (readonly)

Returns the value of attribute request_signature.



6
7
8
# File 'lib/webmock/request_signature_snippet.rb', line 6

def request_signature
  @request_signature
end

#request_stubObject (readonly)

Returns the value of attribute request_stub.



6
7
8
# File 'lib/webmock/request_signature_snippet.rb', line 6

def request_stub
  @request_stub
end

Instance Method Details

#request_stubsObject



20
21
22
23
24
25
26
27
28
29
# File 'lib/webmock/request_signature_snippet.rb', line 20

def request_stubs
  return if WebMock::StubRegistry.instance.request_stubs.empty?

  text = "registered request stubs:\n".dup
  WebMock::StubRegistry.instance.request_stubs.each do |stub|
    text << "\n#{WebMock::StubRequestSnippet.new(stub).to_s(false)}"
    add_body_diff(stub, text) if WebMock.show_body_diff?
  end
  text
end

#stubbing_instructionsObject



13
14
15
16
17
18
# File 'lib/webmock/request_signature_snippet.rb', line 13

def stubbing_instructions
  return unless WebMock.show_stubbing_instructions?

  "You can stub this request with the following snippet:\n\n" +
    WebMock::StubRequestSnippet.new(request_stub).to_s
end