Class: HttpStub::Configurator::Server

Inherits:
Object
  • Object
show all
Defined in:
lib/http_stub/configurator/server.rb

Instance Method Summary collapse

Constructor Details

#initialize(state) ⇒ Server

Returns a new instance of Server.


12
13
14
15
# File 'lib/http_stub/configurator/server.rb', line 12

def initialize(state)
  @state                = state
  @server_stub_template = HttpStub::Configurator::Stub::Template.new
end

Instance Method Details

#add_scenario!(name) {|scenario| ... } ⇒ Object

Yields:

  • (scenario)

29
30
31
32
33
34
# File 'lib/http_stub/configurator/server.rb', line 29

def add_scenario!(name, &_block)
  scenario = HttpStub::Configurator::Scenario.new(name, @server_stub_template)
  yield scenario
  @state.add_scenario(scenario)
  scenario
end

#add_scenario_with_one_stub!(name, stub = nil, &block) ⇒ Object


36
37
38
39
40
41
42
# File 'lib/http_stub/configurator/server.rb', line 36

def add_scenario_with_one_stub!(name, stub=nil, &block)
  add_scenario!(name) do |scenario|
    built_stub = stub || scenario.build_stub
    built_stub.invoke(block.arity == 2 ? scenario : nil, &block) if block_given?
    scenario.add_stub!(built_stub)
  end
end

#add_stub!(stub = nil, &block) ⇒ Object


44
45
46
47
# File 'lib/http_stub/configurator/server.rb', line 44

def add_stub!(stub=nil, &block)
  resolved_stub = stub || self.build_stub(&block)
  @state.add_stub(resolved_stub)
end

#add_stubs!(stubs) ⇒ Object


49
50
51
# File 'lib/http_stub/configurator/server.rb', line 49

def add_stubs!(stubs)
  stubs.each { |stub| add_stub!(stub) }
end

#endpoint_template(&block) ⇒ Object


25
26
27
# File 'lib/http_stub/configurator/server.rb', line 25

def endpoint_template(&block)
  HttpStub::Configurator::EndpointTemplate.new(self, @server_stub_template, &block)
end

#request_defaults=(args) ⇒ Object


17
18
19
# File 'lib/http_stub/configurator/server.rb', line 17

def request_defaults=(args)
  @server_stub_template.match_requests(args)
end

#response_defaults=(args) ⇒ Object


21
22
23
# File 'lib/http_stub/configurator/server.rb', line 21

def response_defaults=(args)
  @server_stub_template.respond_with(args)
end