class StubRequests::WebMock::Builder

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

@author Mikael Henriksson <mikael@zoolutions.se> @since 0.1.2

Attributes

callback[R]

@!attribute [r] callback

@return [Block] call back when given a block
webmock_stub[R]

@!attribute [r] webmock_stub

@return [WebMock::RequestStub] a stubbed webmock request

Public Class Methods

build(verb, uri, &callback) click to toggle source

Builds and registers a WebMock::RequestStub

@param [Symbol] verb a HTTP verb/method @param [String] uri a URI to call

@yield a callback to eventually yield to the caller

@return [WebMock::RequestStub]

# File lib/stub_requests/webmock/builder.rb, line 35
def self.build(verb, uri, &callback)
  new(verb, uri, &callback).build
end
new(verb, uri, &callback) click to toggle source

Initializes a new instance of

@param [Symbol] verb a HTTP verb/method @param [String] uri a URI to call

@yield a block to eventually yield to the caller

# File lib/stub_requests/webmock/builder.rb, line 57
def initialize(verb, uri, &callback)
  @webmock_stub = ::WebMock::RequestStub.new(verb, uri)
  @callback     = callback
end

Public Instance Methods

build() click to toggle source

Prepares a WebMock::RequestStub and registers it in WebMock

@return [WebMock::RequestStub] the registered stub

# File lib/stub_requests/webmock/builder.rb, line 68
def build
  Docile.dsl_eval(webmock_stub, &callback) if callback.present?
  webmock_stub
end