Class: StubRequests::WebMock::Builder

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

Overview

Module Builder is responsible for building WebMock::RequestStub's

Author:

Since:

  • 0.1.2

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(verb, uri) { ... } ⇒ Builder

Initializes a new instance of

Parameters:

  • verb (Symbol)

    a HTTP verb/method

  • uri (String)

    a URI to call

Yields:

  • a block to eventually yield to the caller

Since:

  • 0.1.2



57
58
59
60
# File 'lib/stub_requests/webmock/builder.rb', line 57

def initialize(verb, uri, &callback)
  @webmock_stub = ::WebMock::RequestStub.new(verb, uri)
  @callback     = callback
end

Instance Attribute Details

#callbackObject (readonly)

Since:

  • 0.1.2



46
47
48
# File 'lib/stub_requests/webmock/builder.rb', line 46

def callback
  @callback
end

#webmock_stubObject (readonly)

Since:

  • 0.1.2



42
43
44
# File 'lib/stub_requests/webmock/builder.rb', line 42

def webmock_stub
  @webmock_stub
end

Class Method Details

.build(verb, uri) { ... } ⇒ WebMock::RequestStub

Builds and registers a WebMock::RequestStub

Parameters:

  • verb (Symbol)

    a HTTP verb/method

  • uri (String)

    a URI to call

Yields:

  • a callback to eventually yield to the caller

Returns:

  • (WebMock::RequestStub)

Since:

  • 0.1.2



35
36
37
# File 'lib/stub_requests/webmock/builder.rb', line 35

def self.build(verb, uri, &callback)
  new(verb, uri, &callback).build
end

Instance Method Details

#buildWebMock::RequestStub

Prepares a WebMock::RequestStub and registers it in WebMock

Returns:

  • (WebMock::RequestStub)

    the registered stub

Since:

  • 0.1.2



68
69
70
71
# File 'lib/stub_requests/webmock/builder.rb', line 68

def build
  Docile.dsl_eval(webmock_stub, &callback) if callback.present?
  webmock_stub
end