Class: Rester::Client::Adapters::StubAdapter
- Defined in:
- lib/rester/client/adapters/stub_adapter.rb
Overview
An adapter to be used to stub the responses needed from specified service requests via a yaml file. This will be used in spec tests to perform “contractual testing”
Note, this does not implement the “timeout” feature defined by the adapter interface.
Instance Attribute Summary collapse
-
#stub ⇒ Object
readonly
Returns the value of attribute stub.
Attributes inherited from Adapter
Class Method Summary collapse
Instance Method Summary collapse
-
#connect(stub_filepath) ⇒ Object
Connects to the StubFile.
- #connected? ⇒ Boolean
- #producer ⇒ Object
- #request!(verb, path, encoded_data) ⇒ Object
- #with_context(context) ⇒ Object
Methods inherited from Adapter
#headers, #initialize, #request
Constructor Details
This class inherits a constructor from Rester::Client::Adapters::Adapter
Instance Attribute Details
#stub ⇒ Object (readonly)
Returns the value of attribute stub.
15 16 17 |
# File 'lib/rester/client/adapters/stub_adapter.rb', line 15 def stub @stub end |
Class Method Details
.can_connect_to?(service) ⇒ Boolean
18 19 20 |
# File 'lib/rester/client/adapters/stub_adapter.rb', line 18 def can_connect_to?(service) service.is_a?(String) && Pathname(service).file? end |
Instance Method Details
#connect(stub_filepath) ⇒ Object
Connects to the StubFile.
25 26 27 |
# File 'lib/rester/client/adapters/stub_adapter.rb', line 25 def connect(stub_filepath) @stub = Utils::StubFile.new(stub_filepath) end |
#connected? ⇒ Boolean
29 30 31 |
# File 'lib/rester/client/adapters/stub_adapter.rb', line 29 def connected? !!stub end |
#producer ⇒ Object
33 34 35 |
# File 'lib/rester/client/adapters/stub_adapter.rb', line 33 def producer stub['producer'] end |
#request!(verb, path, encoded_data) ⇒ Object
37 38 39 40 41 42 43 44 |
# File 'lib/rester/client/adapters/stub_adapter.rb', line 37 def request!(verb, path, encoded_data) if verb == :get && path == '/ping' return [200, { 'X-Rester-Producer-Name' => producer }, ''] end params = Rack::Utils.parse_nested_query(encoded_data) _request(verb.to_s.upcase, path, params) end |
#with_context(context) ⇒ Object
46 47 48 49 50 |
# File 'lib/rester/client/adapters/stub_adapter.rb', line 46 def with_context(context) @_context = context yield @_context = nil end |