poisol 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c66331f663c993f5ad291f2947764e56f4b2c65a
4
- data.tar.gz: 1156dc7a6b8d3bcfc7b03bb482c832cb9a30768c
3
+ metadata.gz: 792f598402da3cf3e020eda9cbd549ae4a580557
4
+ data.tar.gz: 043b756d73700adc34239e7224c88fb674069af4
5
5
  SHA512:
6
- metadata.gz: cc9bef8c9cb1c1955f71bf7eeea8c85b016df9c0e69a23b844461d4c2b60f246137b0843a5bf6c735ed7ee4362dc173c0768e7351ae7b5eca4039dddb73480b4
7
- data.tar.gz: a1c7bec0f36c8b5e9229fc8e794f3f985baa9185fa30583eb1058544a69318c57e71cb52a669fb39ff1bd9bfe9af1902b8d840fb319dfd92d8bd0fae2a891720
6
+ metadata.gz: 3d754abd04577b373ad452161bab9337b5ef51a7fd90bc41d2c5c114400d83fd1bf651698a696678a0459397982298f13d756521e9df377d28578f4256719204
7
+ data.tar.gz: 0cfc85a52f8894577c12487610452e87542a53c74c2f43445f82ba47bcca3372b9957c273be187c7dc55b3e7246c6c9bbddb8d164b59bf1c5500272b0ba241ad
@@ -3,6 +3,7 @@ module ResponseMapper
3
3
 
4
4
  def map webrick_request
5
5
  stub_request = get_stub_request webrick_request
6
+ PoisolLog.info stub_request.to_s
6
7
  stub_response = get_stub_response stub_request
7
8
  end
8
9
 
@@ -19,7 +20,11 @@ module ResponseMapper
19
20
 
20
21
  def get_stub_response stub_request
21
22
  stub = Stubs.get_match stub_request
22
- raise "no match found for request \n #{stub_request.type} \n #{stub_request.url} \n #{stub_request.query} \n #{stub_request.body} " if stub.blank?
23
+ if stub.blank?
24
+ PoisolLog.error "^^^^^^^^^^^^\nNo match found for above request"
25
+ PoisolLog.error "Registered requests are #{Stubs.all.map{|stub| "#{stub.request.to_s}\n"}.join}"
26
+ raise "No match found for request: #{stub_request.to_s} "
27
+ end
23
28
  return stub.response if stub.present?
24
29
  end
25
30
 
@@ -21,6 +21,11 @@ end
21
21
 
22
22
  class Request
23
23
  attr_accessor :url,:query,:body,:path,:type
24
+
25
+ def to_s
26
+ "#{self.type} #{self.url} #{"Query:#{self.query}" if self.query.present?} #{"\nBody: #{self.body}" if self.body.present?} "
27
+ end
28
+
24
29
  end
25
30
 
26
31
  class Response
data/lib/poisol/stubs.rb CHANGED
@@ -1,6 +1,10 @@
1
1
  module Stubs
2
2
  extend self
3
3
 
4
+ def all
5
+ @stubs
6
+ end
7
+
4
8
  def add stub
5
9
  @stubs = [] if @stubs.blank?
6
10
  @stubs << stub
@@ -35,9 +39,8 @@ module Stubs
35
39
  end
36
40
 
37
41
  def load_as_json input
38
- require 'json'
39
42
  begin
40
- return JSON.parse input
43
+ return Parse.json_to_hash input
41
44
  rescue
42
45
  return input
43
46
  end
@@ -10,19 +10,19 @@ class PoisolLog
10
10
  end
11
11
 
12
12
  def error message
13
- logger.error "#{message}\n"
13
+ logger.error "#{message}"
14
14
  end
15
15
 
16
16
  def info message
17
- logger.info "#{message}\n"
17
+ logger.info "#{message}"
18
18
  end
19
19
 
20
20
  def warn message
21
- logger.warn "#{message}\n"
21
+ logger.warn "#{message}"
22
22
  end
23
23
 
24
24
  def debug message
25
- logger.debug "#{message}\n"
25
+ logger.debug "#{message}"
26
26
  end
27
27
 
28
28
  end
data/lib/poisol.rb CHANGED
@@ -7,25 +7,19 @@ module Poisol
7
7
 
8
8
  def start (param={:at_port=>3030})
9
9
  Server.start param[:at_port]
10
- reset
10
+ reset_data
11
11
  end
12
12
 
13
13
  def load folder
14
14
  StubFactory.new.build folder
15
15
  end
16
16
 
17
- def reset
17
+ def reset_data
18
18
  Stubs.reset
19
19
  end
20
20
 
21
21
  def stop
22
22
  Server.stop
23
- reset
24
- end
25
-
26
- def log_all_calls to_domain
27
- if req_signature.to_s.include? to_domain
28
- PoisolLog.info "========================\nRequest\n#{req_signature.uri}\n#{req_signature.body}\nResponse:#{response.status[0]}\n#{JSON.pretty_generate(JSON.parse(response.body)) if response.status.present?}"
29
- end
23
+ reset_data
30
24
  end
31
25
  end
data/spec/spec_helper.rb CHANGED
@@ -14,7 +14,7 @@ SimpleCov.start
14
14
  RSpec.configure do |config|
15
15
 
16
16
  config.before(:each) do
17
- Poisol.reset
17
+ Poisol.reset_data
18
18
  end
19
19
 
20
20
  config.before(:suite) do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: poisol
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Deepak
@@ -122,7 +122,7 @@ dependencies:
122
122
  - - ">="
123
123
  - !ruby/object:Gem::Version
124
124
  version: '0'
125
- description: Generate builders for http stubs
125
+ description: HTTP stub as DSL
126
126
  email:
127
127
  executables: []
128
128
  extensions: []
@@ -206,7 +206,7 @@ rubyforge_project:
206
206
  rubygems_version: 2.2.2
207
207
  signing_key:
208
208
  specification_version: 4
209
- summary: Generate builders for http stubs
209
+ summary: HTTP stub as DSL
210
210
  test_files:
211
211
  - spec/data/domain/first/domain.yml
212
212
  - spec/data/domain/first/first.yml