Class: Zen::Service::SpecHelpers::ServiceMocker
- Inherits:
-
SimpleDelegator
- Object
- SimpleDelegator
- Zen::Service::SpecHelpers::ServiceMocker
- Defined in:
- lib/zen/service/spec_helpers.rb
Instance Attribute Summary collapse
-
#service ⇒ Object
readonly
Returns the value of attribute service.
-
#service_class ⇒ Object
readonly
Returns the value of attribute service_class.
Instance Method Summary collapse
-
#stub_service(service_class) ⇒ Object
rubocop:disable Metrics/AbcSize.
- #with_attributes(*attributes) ⇒ Object
- #with_stubs(stubs) ⇒ Object
Instance Attribute Details
#service ⇒ Object (readonly)
Returns the value of attribute service.
29 30 31 |
# File 'lib/zen/service/spec_helpers.rb', line 29 def service @service end |
#service_class ⇒ Object (readonly)
Returns the value of attribute service_class.
29 30 31 |
# File 'lib/zen/service/spec_helpers.rb', line 29 def service_class @service_class end |
Instance Method Details
#stub_service(service_class) ⇒ Object
rubocop:disable Metrics/AbcSize
31 32 33 34 35 36 37 38 39 40 |
# File 'lib/zen/service/spec_helpers.rb', line 31 def stub_service(service_class) # rubocop:disable Metrics/AbcSize @service_class = service_class @service = double(service_class.name) allow(service_class).to receive(:new).and_return(service) allow(service).to receive(:execute).and_return(service) allow(service).to receive(:executed?).and_return(true) self end |
#with_attributes(*attributes) ⇒ Object
42 43 44 45 46 |
# File 'lib/zen/service/spec_helpers.rb', line 42 def with_attributes(*attributes) expect(service_class).to receive(:new).with(*attributes).and_return(service) self end |
#with_stubs(stubs) ⇒ Object
48 49 50 51 52 53 54 55 56 57 |
# File 'lib/zen/service/spec_helpers.rb', line 48 def with_stubs(stubs) stubs[:success?] = !!stubs[:result] unless stubs.key?(:success) stubs[:failure?] = !stubs[:success?] stubs.each do |name, value| allow(service).to receive(name).and_return(value) end self end |