Class: Hyperion
- Inherits:
-
Object
- Object
- Hyperion
- Extended by:
- Formats, Headers, Logger, TestFrameworkHooks
- Defined in:
- lib/hyperion/formats.rb,
lib/hyperion/headers.rb,
lib/hyperion/aux/util.rb,
lib/hyperion/hyperion.rb,
lib/hyperion_test/kim.rb,
lib/hyperion/aux/typho.rb,
lib/hyperion/requestor.rb,
lib/hyperion_test/fake.rb,
lib/hyperion/aux/logger.rb,
lib/hyperion_test/fake_server.rb,
lib/hyperion_test/kim/matcher.rb,
lib/hyperion_test/server_pool.rb,
lib/hyperion_test/kim/matchers.rb,
lib/hyperion_test/fake_server/types.rb,
lib/hyperion_test/fake_server/config.rb,
lib/hyperion/result_handling/dispatch_dsl.rb,
lib/hyperion/result_handling/result_maker.rb,
lib/hyperion/result_handling/dispatching_hyperion_result.rb
Defined Under Namespace
Modules: DispatchDsl, Formats, Headers, Logger, Requestor Classes: Config, DispatchingHyperionResult, FakeServer, Kim, ResultMaker, ServerPool, Typho, Util
Constant Summary
Constants included from Headers
Class Method Summary collapse
- .configure {|config| ... } ⇒ Object
-
.fake(base_uri, &routes) ⇒ Object
Configure routes on the server for the given base_uri.
-
.request(route, body: nil, additional_headers: {}, timeout: 0) {|result| ... } ⇒ HyperionResult, Object
If a block is provided, returns the block’s return value; otherwise, returns the result.
-
.reset ⇒ Object
Clear routes but don’t stop servers.
-
.teardown_cached_servers ⇒ Object
Stop all servers.
Instance Method Summary collapse
-
#initialize(route) ⇒ Hyperion
constructor
A new instance of Hyperion.
- #request(body, additional_headers, timeout, &dispatch) ⇒ Object
Methods included from Logger
log_result, log_stub, logger, with_request_logging
Methods included from TestFrameworkHooks
can_hook_reset?, hook_reset, reset_registered?, rspec_after_example_hooks, rspec_hooks
Methods included from Headers
content_type_for, format_for, route_headers, short_mimetype
Methods included from Formats
Constructor Details
#initialize(route) ⇒ Hyperion
Returns a new instance of Hyperion.
28 29 30 |
# File 'lib/hyperion/hyperion.rb', line 28 def initialize(route) @route = route end |
Class Method Details
.configure {|config| ... } ⇒ Object
45 46 47 |
# File 'lib/hyperion/hyperion.rb', line 45 def self.configure yield(config) end |
.fake(base_uri, &routes) ⇒ Object
Configure routes on the server for the given base_uri
18 19 20 21 22 23 24 25 |
# File 'lib/hyperion_test/fake.rb', line 18 def fake(base_uri, &routes) base_uri = normalized_base(base_uri) unless @configured hook_reset if can_hook_reset? && !reset_registered? @configured = true end servers[base_uri].configure(&routes) end |
.request(route, body: nil, additional_headers: {}, timeout: 0) {|result| ... } ⇒ HyperionResult, Object
If a block is provided, returns the block’s return value; otherwise, returns the result.
23 24 25 |
# File 'lib/hyperion/hyperion.rb', line 23 def self.request(route, body: nil, additional_headers: {}, timeout: 0, &block) self.new(route).request(body, additional_headers, timeout, &block) end |
.reset ⇒ Object
Clear routes but don’t stop servers. Meant to be called between tests. Starting/stopping servers is relatively slow. They can be reused.
29 30 31 32 33 |
# File 'lib/hyperion_test/fake.rb', line 29 def reset servers.values.each { |s| server_pool.check_in(s) } servers.clear @configured = false end |
.teardown_cached_servers ⇒ Object
Stop all servers. This should only need to be called by tests that use Kim directly (like kim_spec.rb).
37 38 39 40 |
# File 'lib/hyperion_test/fake.rb', line 37 def teardown_cached_servers reset server_pool.clear end |
Instance Method Details
#request(body, additional_headers, timeout, &dispatch) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/hyperion/hyperion.rb', line 33 def request(body, additional_headers, timeout, &dispatch) uri = transform_uri(route.uri).to_s with_request_logging(route, uri, route_headers(route)) do typho_result = Typho.request(uri, method: route.method, headers: build_headers(additional_headers), body: write(body, route.payload_descriptor), timeout: timeout) hyperion_result_for(typho_result, dispatch) end end |