Module: MyApiClient::Stub
- Defined in:
- lib/my_api_client/rspec/stub.rb
Overview
Test helper module for RSpec
Constant Summary collapse
- ERROR_MESSAGE =
'If you use the `raise` option as an error instance, the `response` option ' \ 'is ignored. If you want to use both options, you need to specify the ' \ '`raise` option as an error class.'
Instance Method Summary collapse
-
#stub_api_client(klass, **actions_and_options) ⇒ InstanceDouble
Returns a stubbed arbitrary MyApiClient instance.
-
#stub_api_client_all(klass, **actions_and_options) ⇒ InstanceDouble
Stubs all instance of arbitrary MyApiClient class.
Instance Method Details
#stub_api_client(klass, **actions_and_options) ⇒ InstanceDouble
Returns a stubbed arbitrary MyApiClient instance.
70 71 72 73 74 75 |
# File 'lib/my_api_client/rspec/stub.rb', line 70 def stub_api_client(klass, **) instance = instance_double(klass, logger: klass.logger, 'logger=': nil, error_handlers: klass.error_handlers) .each { |action, | stubbing(instance, action, ) } instance end |
#stub_api_client_all(klass, **actions_and_options) ⇒ InstanceDouble
Stubs all instance of arbitrary MyApiClient class. And returns a stubbed arbitrary MyApiClient instance.
38 39 40 41 42 |
# File 'lib/my_api_client/rspec/stub.rb', line 38 def stub_api_client_all(klass, **) instance = stub_api_client(klass, **) allow(klass).to receive(:new).and_return(instance) instance end |