Class: HttpDecoy::Definition

Inherits:
Object
  • Object
show all
Defined in:
lib/http_decoy/rspec.rb

Overview

Wraps a named RouteMap and generates an anonymous RSpec helper module.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, route_map) ⇒ Definition

Returns a new instance of Definition.



179
180
181
182
# File 'lib/http_decoy/rspec.rb', line 179

def initialize(name, route_map)
  @name      = name
  @route_map = route_map
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



177
178
179
# File 'lib/http_decoy/rspec.rb', line 177

def name
  @name
end

#route_mapObject (readonly)

Returns the value of attribute route_map.



177
178
179
# File 'lib/http_decoy/rspec.rb', line 177

def route_map
  @route_map
end

Instance Method Details

#rspec_helpersObject

Returns an anonymous module. Include it in RSpec.configure to register the server lifecycle for every example group in the suite.

RSpec.configure { |c| c.include FakeStripe.rspec_helpers }


189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
# File 'lib/http_decoy/rspec.rb', line 189

def rspec_helpers
  definition = self

  Module.new do
    include HttpDecoy::RSpec

    # define_singleton_method closes over `definition` from the outer scope.
    # `def self.included` would NOT — def never captures outer locals.
    define_singleton_method(:included) do |base|
      super(base)
      base._http_decoy_register(definition.name, definition.route_map)
    end

    define_method(:_http_decoy_definition) { definition }
  end
end