module Poisol::StubInstance
Public Class Methods
new()
click to toggle source
# File lib/poisol/stub/stub_builder_instance.rb, line 3 def initialize init_request init_response @called_methods = [] end
Public Instance Methods
by(input_hash)
click to toggle source
# File lib/poisol/stub/stub_builder_instance.rb, line 47 def by input_hash @request.body.deep_merge! input_hash self end
for(input_hash)
click to toggle source
# File lib/poisol/stub/stub_builder_instance.rb, line 63 def for input_hash @request.query.deep_merge! input_hash.stringify_keys self end
get_assignment_value(actual_field_value, input_value)
click to toggle source
# File lib/poisol/stub/stub_builder_instance.rb, line 38 def get_assignment_value actual_field_value, input_value if actual_field_value.class.to_s == "Hash" input_value = {} if input_value.blank? actual_field_value.deep_merge(input_value.stringify_keys) else input_value end end
has(input_hash)
click to toggle source
# File lib/poisol/stub/stub_builder_instance.rb, line 52 def has input_hash @response.body.deep_merge! input_hash.stringify_keys self end
init_request()
click to toggle source
# File lib/poisol/stub/stub_builder_instance.rb, line 9 def init_request @request = Request.new @request.type = stub_config.request.type @request.path = stub_config.request.url.deep_dup @request.query = stub_config.request.query_explicit ? {} : stub_config.request.query.deep_dup @request.body = stub_config.request.body_explicit ? {} : stub_config.request.body.deep_dup end
init_response()
click to toggle source
# File lib/poisol/stub/stub_builder_instance.rb, line 17 def init_response @response = Response.new if stub_config.response.is_column_array or stub_config.response.is_row_array @response.body = [stub_config.response.body.deep_dup] else @response.body = stub_config.response.body.deep_dup end @response.status = 200 @response.header = {'Content-Type' => 'application/json'} if (stub_config.response.header) @response.header.merge! stub_config.response.header end end
is_empty()
click to toggle source
# File lib/poisol/stub/stub_builder_instance.rb, line 57 def is_empty @response.body = (stub_config.response.is_column_array or stub_config.response.is_row_array) ? [] : {} @is_response_dumped = true self end
remove_array_field_calls()
click to toggle source
# File lib/poisol/stub/stub_builder_instance.rb, line 73 def remove_array_field_calls method_of_array_fileds_of_array = self.methods.select { |method_name| method_name.to_s.start_with? "with_" } @called_methods = @called_methods - method_of_array_fileds_of_array end
set_dumb_response(response_file)
click to toggle source
# File lib/poisol/stub/stub_builder_instance.rb, line 32 def set_dumb_response response_file @response.body = Parse.json_file_to_hash(response_file) @is_response_dumped = true self end
status(input)
click to toggle source
# File lib/poisol/stub/stub_builder_instance.rb, line 68 def status input @response.status = input self end