Module: Poisol::ResponseMapper

Extended by:
ResponseMapper
Included in:
ResponseMapper
Defined in:
lib/poisol/stub_mapper/response_mapper.rb

Instance Method Summary collapse

Instance Method Details

#get_stub_request(webrick_request) ⇒ Object



11
12
13
14
15
16
17
18
# File 'lib/poisol/stub_mapper/response_mapper.rb', line 11

def get_stub_request webrick_request
  stub_request = Request.new 
  stub_request.type = webrick_request.request_method.downcase
  stub_request.url = webrick_request.request_uri.path
  stub_request.query = webrick_request.query_string
  stub_request.body = webrick_request.body
  stub_request
end

#get_stub_response(stub_request) ⇒ Object



21
22
23
24
25
26
27
28
29
# File 'lib/poisol/stub_mapper/response_mapper.rb', line 21

def get_stub_response stub_request
  stub = Stubs.get_match stub_request
  if stub.blank?
    log_error stub_request
    raise "No match found for request: #{stub_request.to_s} "
  end
  PoisolLog.info JSON.pretty_generate(stub.response.body)
  stub.response if stub.present?
end

#log_error(request) ⇒ Object



31
32
33
34
35
36
37
# File 'lib/poisol/stub_mapper/response_mapper.rb', line 31

def log_error request
  Kernel.puts request.to_s
  Kernel.puts "^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^No match found for above request"
  Kernel.puts "Registered requests are: #{Stubs.all.map{|stub| "\n#{stub.request.to_s}"}.join}\n--end--"
  PoisolLog.error "^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^No match found for above request"
  PoisolLog.error "Registered requests are: #{Stubs.all.map{|stub| "\n#{stub.request.to_s}"}.join}\n--end--"
end

#map(webrick_request) ⇒ Object



5
6
7
8
9
# File 'lib/poisol/stub_mapper/response_mapper.rb', line 5

def map webrick_request
  stub_request = get_stub_request webrick_request
  PoisolLog.info stub_request.to_s
  get_stub_response stub_request
end