Class: SkullIsland::RSpec::FakeRestClient
- Inherits:
-
Object
- Object
- SkullIsland::RSpec::FakeRestClient
- Defined in:
- lib/skull_island/rspec/fake_rest_client.rb
Overview
A Fake Rest Client for RSpec testing
Instance Attribute Summary collapse
-
#responses ⇒ Object
readonly
Returns the value of attribute responses.
Instance Method Summary collapse
- #[](uri) ⇒ Object
- #hash(data) ⇒ Object
-
#initialize ⇒ FakeRestClient
constructor
A new instance of FakeRestClient.
- #response_for(type, uri, data: nil, response: {}) ⇒ Object
Constructor Details
#initialize ⇒ FakeRestClient
Returns a new instance of FakeRestClient.
9 10 11 |
# File 'lib/skull_island/rspec/fake_rest_client.rb', line 9 def initialize @responses = {} end |
Instance Attribute Details
#responses ⇒ Object (readonly)
Returns the value of attribute responses.
7 8 9 |
# File 'lib/skull_island/rspec/fake_rest_client.rb', line 7 def responses @responses end |
Instance Method Details
#[](uri) ⇒ Object
27 28 29 |
# File 'lib/skull_island/rspec/fake_rest_client.rb', line 27 def [](uri) FakeClient::Request.new(self, uri) end |
#hash(data) ⇒ Object
13 14 15 16 17 18 19 |
# File 'lib/skull_island/rspec/fake_rest_client.rb', line 13 def hash(data) if data Digest::MD5.hexdigest(data.sort.to_s) else '' end end |
#response_for(type, uri, data: nil, response: {}) ⇒ Object
21 22 23 24 25 |
# File 'lib/skull_island/rspec/fake_rest_client.rb', line 21 def response_for(type, uri, data: nil, response: {}) @responses[type.to_s] ||= {} key = data ? uri.to_s + hash(data) : uri.to_s @responses[type.to_s][key] = JSON.dump(response) end |