Module: Poisol::StubInstance

Included in:
StubBuilder
Defined in:
lib/poisol/stub/stub_builder_instance.rb

Instance Method Summary collapse

Instance Method Details

#by(input_hash) ⇒ Object



43
44
45
46
# File 'lib/poisol/stub/stub_builder_instance.rb', line 43

def by input_hash
  @request.body.deep_merge! input_hash
  self
end

#for(input_hash) ⇒ Object



59
60
61
62
# File 'lib/poisol/stub/stub_builder_instance.rb', line 59

def  for input_hash
  @request.query.deep_merge! input_hash.camelize_keys
  self
end

#get_assignment_value(actual_field_value, input_value) ⇒ Object



34
35
36
37
38
39
40
41
# File 'lib/poisol/stub/stub_builder_instance.rb', line 34

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) ⇒ Object



48
49
50
51
# File 'lib/poisol/stub/stub_builder_instance.rb', line 48

def has input_hash
  @response.body.deep_merge! input_hash.stringify_keys
  self
end

#init_requestObject



9
10
11
12
13
14
15
# 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_responseObject



17
18
19
20
21
22
23
24
25
26
# 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'}
end

#initializeObject



3
4
5
6
7
# File 'lib/poisol/stub/stub_builder_instance.rb', line 3

def initialize
  init_request
  init_response
  @called_methods = []
end

#is_emptyObject



53
54
55
56
57
# File 'lib/poisol/stub/stub_builder_instance.rb', line 53

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_callsObject



69
70
71
72
# File 'lib/poisol/stub/stub_builder_instance.rb', line 69

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) ⇒ Object



28
29
30
31
32
# File 'lib/poisol/stub/stub_builder_instance.rb', line 28

def set_dumb_response response_file
  @response.body = Parse.json_file_to_hash(response_file)
  @is_response_dumped = true
  self
end

#status(input) ⇒ Object



64
65
66
67
# File 'lib/poisol/stub/stub_builder_instance.rb', line 64

def  status input
  @response.status = input
  self
end