Class: Dupe::MockServiceResponse

Inherits:
Object
  • Object
show all
Defined in:
lib/dupe/mock_service_response.rb

Overview

:nodoc:

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(resource_name, format = :xml) ⇒ MockServiceResponse

Returns a new instance of MockServiceResponse.



7
8
9
10
11
# File 'lib/dupe/mock_service_response.rb', line 7

def initialize(resource_name, format=:xml)
  @mocks = []
  @resource_name = resource_name
  @to_format = "to_#{format}"
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args, &block) ⇒ Object



17
18
19
# File 'lib/dupe/mock_service_response.rb', line 17

def method_missing(method_name, *args, &block)
  @mocks << block
end

Instance Attribute Details

#formatObject (readonly)

Returns the value of attribute format.



5
6
7
# File 'lib/dupe/mock_service_response.rb', line 5

def format
  @format
end

#mocksObject (readonly)

Returns the value of attribute mocks.



3
4
5
# File 'lib/dupe/mock_service_response.rb', line 3

def mocks
  @mocks
end

#resource_nameObject (readonly)

Returns the value of attribute resource_name.



4
5
6
# File 'lib/dupe/mock_service_response.rb', line 4

def resource_name
  @resource_name
end

Instance Method Details

#define_mock(prock) ⇒ Object



13
14
15
# File 'lib/dupe/mock_service_response.rb', line 13

def define_mock(prock)
  @mocks << prock
end

#run_mocks(records, identifiers) ⇒ Object



21
22
23
24
25
26
27
28
29
# File 'lib/dupe/mock_service_response.rb', line 21

def run_mocks(records, identifiers)
  ActiveResource::HttpMock.respond_to do |mock|
    @mocks.each do |a_mock|
      a_mock.call mock, records
    end
  end
  find_all(records)
  records.each {|r| find_one(r, identifiers)}
end