Class: Koine::RestClient::RspecMockClient
- Inherits:
-
Object
- Object
- Koine::RestClient::RspecMockClient
- Defined in:
- lib/koine/rest_client/rspec_mock_client.rb
Overview
mock client
Instance Attribute Summary collapse
-
#client_mock ⇒ Object
readonly
Returns the value of attribute client_mock.
Instance Method Summary collapse
- #async {|_self| ... } ⇒ Object
- #delete(*args, &block) ⇒ Object
- #get(*args, &block) ⇒ Object
-
#initialize(rspec, response_parser: ResponseParser.new) ⇒ RspecMockClient
constructor
A new instance of RspecMockClient.
- #mock {|@builder| ... } ⇒ Object
- #on_error(&block) ⇒ Object
- #patch(*args, &block) ⇒ Object
- #post(*args, &block) ⇒ Object
- #put(*args, &block) ⇒ Object
Constructor Details
#initialize(rspec, response_parser: ResponseParser.new) ⇒ RspecMockClient
Returns a new instance of RspecMockClient.
9 10 11 12 13 14 15 16 17 |
# File 'lib/koine/rest_client/rspec_mock_client.rb', line 9 def initialize(rspec, response_parser: ResponseParser.new) @client_mock = rspec.instance_double(Koine::RestClient::Client) @builder = MockFactory.new(rspec, self) @collected = [] @response_parser = response_parser @error_handler = proc do |error| raise error end end |
Instance Attribute Details
#client_mock ⇒ Object (readonly)
Returns the value of attribute client_mock.
7 8 9 |
# File 'lib/koine/rest_client/rspec_mock_client.rb', line 7 def client_mock @client_mock end |
Instance Method Details
#async {|_self| ... } ⇒ Object
47 48 49 50 51 52 53 54 55 |
# File 'lib/koine/rest_client/rspec_mock_client.rb', line 47 def async @async = true yield(self) @async = false responses = @collected.dup @collected.clear responses.map(&:parsed_response) end |
#delete(*args, &block) ⇒ Object
43 44 45 |
# File 'lib/koine/rest_client/rspec_mock_client.rb', line 43 def delete(*args, &block) parse(@client_mock.delete(*args), &block) end |
#get(*args, &block) ⇒ Object
27 28 29 |
# File 'lib/koine/rest_client/rspec_mock_client.rb', line 27 def get(*args, &block) parse(@client_mock.get(*args), &block) end |
#mock {|@builder| ... } ⇒ Object
23 24 25 |
# File 'lib/koine/rest_client/rspec_mock_client.rb', line 23 def mock yield(@builder) end |
#on_error(&block) ⇒ Object
19 20 21 |
# File 'lib/koine/rest_client/rspec_mock_client.rb', line 19 def on_error(&block) @error_handler = block end |
#patch(*args, &block) ⇒ Object
39 40 41 |
# File 'lib/koine/rest_client/rspec_mock_client.rb', line 39 def patch(*args, &block) parse(@client_mock.patch(*args), &block) end |
#post(*args, &block) ⇒ Object
31 32 33 |
# File 'lib/koine/rest_client/rspec_mock_client.rb', line 31 def post(*args, &block) parse(@client_mock.post(*args), &block) end |
#put(*args, &block) ⇒ Object
35 36 37 |
# File 'lib/koine/rest_client/rspec_mock_client.rb', line 35 def put(*args, &block) parse(@client_mock.put(*args), &block) end |