Class: Dupe::MockServiceResponse
- Inherits:
-
Object
- Object
- Dupe::MockServiceResponse
- Defined in:
- lib/dupe/mock_service_response.rb
Overview
:nodoc:
Instance Attribute Summary collapse
-
#format ⇒ Object
readonly
Returns the value of attribute format.
-
#mocks ⇒ Object
readonly
Returns the value of attribute mocks.
-
#resource_name ⇒ Object
readonly
Returns the value of attribute resource_name.
Instance Method Summary collapse
- #define_mock(prock) ⇒ Object
-
#initialize(resource_name, format = :xml) ⇒ MockServiceResponse
constructor
A new instance of MockServiceResponse.
- #method_missing(method_name, *args, &block) ⇒ Object
- #run_mocks(records, identifiers) ⇒ Object
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
#format ⇒ Object (readonly)
Returns the value of attribute format.
5 6 7 |
# File 'lib/dupe/mock_service_response.rb', line 5 def format @format end |
#mocks ⇒ Object (readonly)
Returns the value of attribute mocks.
3 4 5 |
# File 'lib/dupe/mock_service_response.rb', line 3 def mocks @mocks end |
#resource_name ⇒ Object (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 |