Class: Zena::Integration::MockConnection
- Inherits:
-
ActiveResource::Connection
- Object
- ActiveResource::Connection
- Zena::Integration::MockConnection
- Defined in:
- lib/zena/integration/test_case.rb
Instance Method Summary collapse
-
#initialize(test, site = 'http://test.host') ⇒ MockConnection
constructor
A new instance of MockConnection.
- #logger ⇒ Object
-
#request(method, path, *arguments) ⇒ Object
Mock ActiveResource request to remote service by doing a call to the integration test.
-
#test_request(method, path, params, headers, parse_response = true) ⇒ Object
Mock HTTParty::Request request.
Constructor Details
#initialize(test, site = 'http://test.host') ⇒ MockConnection
Returns a new instance of MockConnection.
4 5 6 7 |
# File 'lib/zena/integration/test_case.rb', line 4 def initialize(test, site = 'http://test.host') @test = test super site end |
Instance Method Details
#logger ⇒ Object
9 10 11 |
# File 'lib/zena/integration/test_case.rb', line 9 def logger Page.logger end |
#request(method, path, *arguments) ⇒ Object
Mock ActiveResource request to remote service by doing a call to the integration test.
14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/zena/integration/test_case.rb', line 14 def request(method, path, *arguments) case method when :get, :delete, :head headers = arguments.first params = {} else headers = arguments.last # The params here contain an xml string representing the request body. params = arguments.first end test_request(method, path, params, headers) end |
#test_request(method, path, params, headers, parse_response = true) ⇒ Object
Mock HTTParty::Request request
28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/zena/integration/test_case.rb', line 28 def test_request(method, path, params, headers, parse_response = true) logger.info "#{method.to_s.upcase} #{site.scheme}://#{site.host}#{path} (#{headers.inspect})" if logger result = nil ms = Benchmark.ms do @test.send(method, "#{site.scheme}://#{site.host}#{path}", params, headers) result = @test.response end logger.info "--> %d %s (%d %.0fms)" % [result.code, result., result.body ? result.body.length : 0, ms] if logger parse_response ? handle_response(result) : result rescue Timeout::Error => e raise TimeoutError.new(e.) end |