class TempoIQ::StubbedRemoter
Public Class Methods
new(pop_stubs = false)
click to toggle source
# File lib/tempoiq/remoter/stubbed_remoter.rb, line 7 def initialize(pop_stubs = false) @active_stubs = Hash.new do |stubs, key| stubs[key] = [] end @pop_stubs = pop_stubs end
Public Instance Methods
delete(route, body = nil, headers = {})
click to toggle source
# File lib/tempoiq/remoter/stubbed_remoter.rb, line 30 def delete(route, body = nil, headers = {}) return_stub(:delete, route, body, headers) end
get(route, body = nil, headers = {})
click to toggle source
# File lib/tempoiq/remoter/stubbed_remoter.rb, line 22 def get(route, body = nil, headers = {}) return_stub(:get, route, body, headers) end
post(route, body = nil, headers = {})
click to toggle source
# File lib/tempoiq/remoter/stubbed_remoter.rb, line 26 def post(route, body = nil, headers = {}) return_stub(:post, route, body, headers) end
put(route, body = nil, headers = {})
click to toggle source
# File lib/tempoiq/remoter/stubbed_remoter.rb, line 34 def put(route, body = nil, headers = {}) return_stub(:put, route, body, headers) end
stub(http_verb, route, code, body = nil, headers = {})
click to toggle source
# File lib/tempoiq/remoter/stubbed_remoter.rb, line 14 def stub(http_verb, route, code, body = nil, headers = {}) @active_stubs[key_for(http_verb, route)] << { :body => body, :code => code, :headers =>headers } end
Private Instance Methods
key_for(http_verb, route)
click to toggle source
# File lib/tempoiq/remoter/stubbed_remoter.rb, line 40 def key_for(http_verb, route) Digest::SHA1.hexdigest(http_verb.to_s+route) end
return_stub(http_verb, route, body, headers)
click to toggle source
# File lib/tempoiq/remoter/stubbed_remoter.rb, line 44 def return_stub(http_verb, route, body, headers) stubs = @active_stubs[key_for(http_verb, route)] if stubs.empty? raise "Real HTTP Connections are not allowed. #{http_verb} #{route} didn't match any active stubs" else stub = @pop_stubs ? stubs.shift : stubs.first HttpResult.new(stub[:code], stub[:headers], stub[:body]) end end