Module: Heracles::Wrapper::TestHelper

Defined in:
lib/heracles-wrapper/test_helper.rb

Constant Summary collapse

RESPONSE_JOB_ID =
1234.freeze
RESPONSE_CODE =
201.freeze

Instance Method Summary collapse

Instance Method Details

#with_heracles_service_failure_stub(service_name, errors = []) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/heracles-wrapper/test_helper.rb', line 9

def with_heracles_service_failure_stub(service_name, errors = [])
  wrap_service_with_proxy(service_name) do
    Heracles::Wrapper.send(
      "#{service_name}_service=",
      lambda { |config,options|
        OpenStruct.new(
          :config => config,
          :workflow_name => options.fetch(:workflow_name),
          :parent_job_id => options.fetch(:parent_job_id, nil),
          :parameters => options.fetch(:parameters, {})
        ).tap { |obj|
          def obj.call
            raise Heracles::Wrapper::RequestFailure.new(errors)
          end
        }
      }
    )
    yield
  end
end

#with_heracles_service_stub(service_name, response = {}) ⇒ Object

Presently I’m leaning on the implementation details of :create_job for returning the API.



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/heracles-wrapper/test_helper.rb', line 31

def with_heracles_service_stub(service_name, response = {})
  wrap_service_with_proxy(service_name) do |proxy|

    response[:job_id] ||= RESPONSE_JOB_ID
    response[:location] ||= File.join(
      Heracles::Wrapper.config.heracles_base_url,
      "/jobs/#{response[:job_id]}"
    )
    response[:code] ||= RESPONSE_CODE
    response[:errors] ||= []

    Heracles::Wrapper.send(
      "#{service_name}_service=",
      lambda { |config,options|
        OpenStruct.new(
          :config => config,
          :workflow_name => options.fetch(:workflow_name),
          :parent_job_id => options.fetch(:parent_job_id, nil),
          :parameters => options.fetch(:parameters, {}),
          :call => OpenStruct.new(response)
        )
      }
    )
    yield
  end
end