lib/and-son/client.rb in and-son-0.7.0 vs lib/and-son/client.rb in and-son-0.8.0
- old
+ new
@@ -54,38 +54,46 @@
end
class TestClient
include Client
- attr_accessor :timeout_value, :params_value, :logger_value
attr_reader :calls, :responses
+ attr_reader :before_call_procs, :after_call_procs
+ attr_accessor :timeout_value, :params_value, :logger_value
def initialize(host, port)
super
- @params_value = {}
@calls = []
@responses = AndSon::StoredResponses.new
+
+ @params_value = {}
+ @before_call_procs = []
+ @after_call_procs = []
end
def call(name, params = nil)
params ||= {}
+ callback_params = self.params_value.merge(params)
+
response = self.responses.get(name, params)
+ self.before_call_procs.each{ |p| p.call(name, callback_params, self) }
self.calls << Call.new(name, params, response.protocol_response)
+ self.after_call_procs.each{ |p| p.call(name, callback_params, self) }
if block_given?
yield response.protocol_response
else
response.data
end
end
def call_runner; self; end
- def add_response(*args, &block)
- self.responses.add(*args, &block)
+ def add_response(name, &block)
+ self.responses.add(name, &block)
end
- def remove_response(*args)
- self.responses.remove(*args)
+ def remove_responses(name)
+ self.responses.remove(name)
end
def reset
self.calls.clear
self.responses.remove_all