Class: StubRequests::RequestStub

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Concerns::Property
Defined in:
lib/stub_requests/request_stub.rb

Overview

Class Stub tracks the WebMock::RequestStub life cycle

Author:

Since:

  • 0.1.2

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Concerns::Property

included

Methods included from Concerns::ArgumentValidation

#validate!, #validate_type!

Constructor Details

#initialize(endpoint_id, webmock_stub) ⇒ RequestStub

Initialize a new Record

Parameters:

  • endpoint_id (Endpoint)

    the id of a stubbed endpoint

  • webmock_stub (WebMock::RequestStub)

    the stubbed webmock request

Since:

  • 0.1.2



63
64
65
66
67
68
69
70
71
72
# File 'lib/stub_requests/request_stub.rb', line 63

def initialize(endpoint_id, webmock_stub)
  request_pattern     = webmock_stub.request_pattern
  self.endpoint_id    = endpoint_id
  self.verb           = request_pattern.method_pattern.to_s.to_sym
  self.request_uri    = request_pattern.uri_pattern.to_s
  self.webmock_stub   = webmock_stub
  self.recorded_at    = Time.now
  self.recorded_from  = RSpec.current_example.[:location]
  @responded_at = nil # ByPass the validation for the initializer
end

Instance Attribute Details

#endpointEndpoint (readonly)

Retrieve the endpoint for this request stub

Returns:

Since:

  • 0.1.2



30
# File 'lib/stub_requests/request_stub.rb', line 30

property :endpoint_id, type: Symbol

#recorded_atTime (readonly)

Returns the time this record was recorded

Returns:

  • (Time)

    the time this record was recorded



46
# File 'lib/stub_requests/request_stub.rb', line 46

property :recorded_at, type: Time

#recorded_fromString (readonly)

Returns the relative path to the spec that recorded it

Returns:

  • (String)

    the relative path to the spec that recorded it



50
# File 'lib/stub_requests/request_stub.rb', line 50

property :recorded_from, type: String

#responded_atTime (readonly)

Returns the time this stubs response was used

Returns:

  • (Time)

    the time this stubs response was used



54
# File 'lib/stub_requests/request_stub.rb', line 54

property :responded_at, type: Time

#uriString (readonly)

Returns the full URI for this endpoint

Returns:

  • (String)

    the full URI for this endpoint



38
# File 'lib/stub_requests/request_stub.rb', line 38

property :request_uri, type: String

#verbSymbol (readonly)

Returns a HTTP verb/method

Returns:

  • (Symbol)

    a HTTP verb/method



34
# File 'lib/stub_requests/request_stub.rb', line 34

property :verb, type: Symbol

#webmock_stubWebMock::RequestStub (readonly)

Returns a webmock stubbed request

Returns:

  • (WebMock::RequestStub)

    a webmock stubbed request



42
# File 'lib/stub_requests/request_stub.rb', line 42

property :webmock_stub, type: WebMock::RequestStub

Instance Method Details

#mark_as_respondedTime

Marks this record as having responded

Returns:

  • (Time)

    the time it was marked responded

Since:

  • 0.1.2



90
91
92
# File 'lib/stub_requests/request_stub.rb', line 90

def mark_as_responded
  self.responded_at = Time.now
end