Class: Hyperion::FakeServer

Inherits:
Object
  • Object
show all
Includes:
Formats, Headers, Kim::Matchers
Defined in:
lib/hyperion_test/fake_server.rb,
lib/hyperion_test/fake_server/types.rb,
lib/hyperion_test/fake_server/config.rb

Defined Under Namespace

Classes: Config, Rule

Constant Summary collapse

Request =
ImmutableStruct.new(:body)

Constants included from Headers

Headers::ContentTypes

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Formats

get_from, #read, #write

Methods included from Logger

#log_result, #log_stub, #logger, #with_request_logging

Methods included from Headers

#content_type_for, #format_for, #route_headers, #short_mimetype

Methods included from Kim::Matchers

#req_headers, #req_params, #res, #verb

Constructor Details

#initialize(port) ⇒ FakeServer

Returns a new instance of FakeServer.



20
21
22
23
24
# File 'lib/hyperion_test/fake_server.rb', line 20

def initialize(port)
  @port = port
  @kim = Kim.new(port: port)
  @kim.start
end

Instance Attribute Details

#portObject

Returns the value of attribute port.



18
19
20
# File 'lib/hyperion_test/fake_server.rb', line 18

def port
  @port
end

Instance Method Details

#clear_routesObject



38
39
40
# File 'lib/hyperion_test/fake_server.rb', line 38

def clear_routes
  @kim.clear_handlers
end

#configure(&configure_routes) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
# File 'lib/hyperion_test/fake_server.rb', line 26

def configure(&configure_routes)
  config = Config.new
  configure_routes.call(config)
  config.rules.each do |rule|
    matcher = Kim::Matcher.and(verb(rule.verb),
                               res(rule.path),
                               req_headers(rule.headers))
    handler = wrap(rule.handler, rule.rest_route)
    @kim.add_handler(matcher, &handler)
  end
end

#teardownObject



42
43
44
# File 'lib/hyperion_test/fake_server.rb', line 42

def teardown
  @kim.stop
end