Module: FServiceResultHelpers
- Defined in:
- lib/f_service/rspec/support/helpers/result.rb
Overview
Methods to mock a FService result from a service call.
Instance Method Summary collapse
-
#f_service_result(result, value = nil, types = []) ⇒ Object
Create an Fservice result Success or Failure.
-
#mock_service(service, result: :success, value: nil, type: :not_passed, types: []) ⇒ Object
Mock a Fservice service call returning a result.
Instance Method Details
#f_service_result(result, value = nil, types = []) ⇒ Object
Create an Fservice result Success or Failure.
6 7 8 9 10 11 12 |
# File 'lib/f_service/rspec/support/helpers/result.rb', line 6 def f_service_result(result, value = nil, types = []) if result == :success FService::Result::Success.new(value, Array(types)) else FService::Result::Failure.new(value, Array(types)) end end |
#mock_service(service, result: :success, value: nil, type: :not_passed, types: []) ⇒ Object
Mock a Fservice service call returning a result.
15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/f_service/rspec/support/helpers/result.rb', line 15 def mock_service(service, result: :success, value: nil, type: :not_passed, types: []) result_types = Array(types) if type != :not_passed alternative = "mock_service(..., types: [#{type.inspect}])" name = 'mock_service' FService.deprecate_argument_name(name: name, argument_name: :type, alternative: alternative, from: caller[0]) result_types = Array(type) end service_result = f_service_result(result, value, result_types) allow(service).to receive(:call).and_return(service_result) end |