poisol 0.1.2 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/poisol/stub/build_stub.rb +53 -0
- data/lib/poisol/stub/stub.rb +6 -32
- data/lib/poisol/stub/stub_builder.rb +36 -0
- data/lib/poisol/stub/{stub_class_builder.rb → stub_builder_class.rb} +0 -0
- data/lib/poisol/stub/{stub_instance.rb → stub_builder_instance.rb} +3 -2
- data/lib/poisol/stub_factory.rb +2 -2
- data/lib/poisol/stub_mapper/stubs.rb +8 -1
- data/lib/poisol.rb +4 -0
- data/spec/functional/response/array_spec.rb +5 -0
- data/spec/functional/wasted_spec.rb +14 -0
- metadata +8 -5
- data/lib/poisol/stub/webrick_stub_builder.rb +0 -42
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b1c5569b1dd57a37a9f736b8f08c9d7ec346f345
|
4
|
+
data.tar.gz: 49b4121cbebf8c66beae87918fe297fd0335b57d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5edede84a64c6fbf6b928ba02de24929359b32390fe46da5884b9f879a1f0d2f1b40be5d773b15e4f2b5ff0176ec507ca968953ba8285b0d01309cfc9c05f2fc
|
7
|
+
data.tar.gz: 6124dff351c4e4a059c7108fb817dc28367696319934735faa12907737893a2a244828e353ff89bacd3c696e28c5583627ebe9b707bfad1cdf45959d701c63ec
|
@@ -0,0 +1,53 @@
|
|
1
|
+
module Poisol
|
2
|
+
module BuildStub
|
3
|
+
def build
|
4
|
+
@stub = Stub.new
|
5
|
+
build_url
|
6
|
+
build_query
|
7
|
+
build_request_body
|
8
|
+
build_response
|
9
|
+
Stubs.add @stub
|
10
|
+
@stub
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
def build_url
|
15
|
+
remove_path_param_name_from_url
|
16
|
+
@stub.request.type = @request.type
|
17
|
+
@stub.request.url = "#{stub_config.request.domain}/#{@request.path}"
|
18
|
+
end
|
19
|
+
|
20
|
+
def build_query
|
21
|
+
return if @request.query.blank?
|
22
|
+
@stub.request.query = @request.query.to_query
|
23
|
+
end
|
24
|
+
|
25
|
+
def build_request_body
|
26
|
+
if stub_config.request.is_body_key_value
|
27
|
+
@stub.request.body = Parse.hash_to_concatenated_key_value(@request.body)
|
28
|
+
else
|
29
|
+
@stub.request.body = @request.body
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def build_response
|
34
|
+
@stub.response.status = @response.status
|
35
|
+
@stub.response.header = @response.header
|
36
|
+
if stub_config.response.is_column_array and !@is_response_dumped.present?
|
37
|
+
@stub.response.body = Parse.hash_array_to_column_hash(@response.body)
|
38
|
+
else
|
39
|
+
@stub.response.body = @response.body
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def remove_path_param_name_from_url
|
44
|
+
@request.path.scan(/{(.+?)}/).each do |path_params|
|
45
|
+
path_param = path_params[0]
|
46
|
+
param_name = path_param.split("|")[0]
|
47
|
+
param_value = path_param.split("|")[1]
|
48
|
+
@request.path.sub!("{#{path_param}}",param_value)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
end
|
data/lib/poisol/stub/stub.rb
CHANGED
@@ -1,36 +1,10 @@
|
|
1
|
-
|
2
|
-
require_relative "stub_class_builder"
|
3
|
-
require_relative "stub_instance"
|
4
|
-
|
5
|
-
module Poisol
|
1
|
+
module Poisol
|
6
2
|
class Stub
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
def set_stub_config stub_config
|
14
|
-
@stub_config = stub_config
|
15
|
-
define_method("stub_config") do
|
16
|
-
return stub_config
|
17
|
-
end
|
18
|
-
end
|
3
|
+
attr_accessor :request,:response,:called_count
|
4
|
+
def initialize
|
5
|
+
@called_count = 0
|
6
|
+
@request = Request.new
|
7
|
+
@response = Response.new
|
19
8
|
end
|
20
|
-
|
21
9
|
end
|
22
|
-
|
23
|
-
class Request
|
24
|
-
attr_accessor :url,:query,:body,:path,:type
|
25
|
-
|
26
|
-
def to_s
|
27
|
-
"#{self.type} #{self.url} #{"Query:#{self.query}" if self.query.present?} #{"\nBody: #{self.body}" if self.body.present?} "
|
28
|
-
end
|
29
|
-
|
30
|
-
end
|
31
|
-
|
32
|
-
class Response
|
33
|
-
attr_accessor :body,:status,:header
|
34
|
-
end
|
35
|
-
|
36
10
|
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require_relative "build_stub"
|
2
|
+
require_relative "stub_builder_class"
|
3
|
+
require_relative "stub_builder_instance"
|
4
|
+
|
5
|
+
module Poisol
|
6
|
+
class StubBuilder
|
7
|
+
include BuildStub
|
8
|
+
include StubInstance
|
9
|
+
attr_accessor :request,:response
|
10
|
+
class << self
|
11
|
+
include StubClassBuilder
|
12
|
+
|
13
|
+
def set_stub_config stub_config
|
14
|
+
@stub_config = stub_config
|
15
|
+
define_method("stub_config") do
|
16
|
+
return stub_config
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
class Request
|
24
|
+
attr_accessor :url,:query,:body,:path,:type
|
25
|
+
|
26
|
+
def to_s
|
27
|
+
"#{self.type} #{self.url} #{"Query:#{self.query}" if self.query.present?} #{"\nBody: #{self.body}" if self.body.present?} "
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
class Response
|
33
|
+
attr_accessor :body,:status,:header
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
File without changes
|
@@ -46,12 +46,13 @@ module Poisol
|
|
46
46
|
end
|
47
47
|
|
48
48
|
def has input_hash
|
49
|
-
@response.body.deep_merge! input_hash.
|
49
|
+
@response.body.deep_merge! input_hash.stringify_keys
|
50
50
|
self
|
51
51
|
end
|
52
52
|
|
53
53
|
def is_empty
|
54
|
-
@response.body = stub_config.response.is_column_array or stub_config.response.is_row_array ? [] : {}
|
54
|
+
@response.body = (stub_config.response.is_column_array or stub_config.response.is_row_array) ? [] : {}
|
55
|
+
@is_response_dumped = true
|
55
56
|
self
|
56
57
|
end
|
57
58
|
|
data/lib/poisol/stub_factory.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require_relative "stub/
|
1
|
+
require_relative "stub/stub_builder"
|
2
2
|
module Poisol
|
3
3
|
class StubFactory
|
4
4
|
def build folder
|
@@ -41,7 +41,7 @@ module Poisol
|
|
41
41
|
end
|
42
42
|
|
43
43
|
def create_class class_name,stub_config
|
44
|
-
dynamic_stub_class = Object.const_set class_name,Class.new(
|
44
|
+
dynamic_stub_class = Object.const_set class_name,Class.new(StubBuilder)
|
45
45
|
dynamic_stub_class.set_stub_config stub_config
|
46
46
|
dynamic_stub_class.generate_methods_to_alter_sutb
|
47
47
|
PoisolLog.info "Generated #{class_name}"
|
@@ -19,7 +19,14 @@ module Poisol
|
|
19
19
|
def get_match actual_request
|
20
20
|
return nil if @stubs.blank?
|
21
21
|
matches = @stubs.select{|stub| Poisol::RequestMatcher.matches? actual_request,stub.request}
|
22
|
-
return matches.present?
|
22
|
+
return nil unless matches.present?
|
23
|
+
match = matches[0]
|
24
|
+
match.called_count = match.called_count + 1
|
25
|
+
return match
|
26
|
+
end
|
27
|
+
|
28
|
+
def unused
|
29
|
+
@stubs.select{|stub| stub.called_count ==0}
|
23
30
|
end
|
24
31
|
|
25
32
|
|
data/lib/poisol.rb
CHANGED
@@ -0,0 +1,14 @@
|
|
1
|
+
describe Poisol,"#wasted" do
|
2
|
+
|
3
|
+
it "is wasted" do
|
4
|
+
url = Url.new.build()
|
5
|
+
url1 = Url.new.build()
|
6
|
+
expect(Poisol.wasted).to eq [url,url1]
|
7
|
+
end
|
8
|
+
|
9
|
+
it "is not wasted" do
|
10
|
+
url = Url.new.build()
|
11
|
+
response = RestClient.get "http://localhost:3030/cda/cd/ragavan/get"
|
12
|
+
expect(Poisol.wasted).to eq []
|
13
|
+
end
|
14
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: poisol
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Deepak
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-01-
|
11
|
+
date: 2015-01-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -134,6 +134,7 @@ files:
|
|
134
134
|
- lib/poisol/extensions/hash.rb
|
135
135
|
- lib/poisol/extensions/webmock_extensions.rb
|
136
136
|
- lib/poisol/server.rb
|
137
|
+
- lib/poisol/stub/build_stub.rb
|
137
138
|
- lib/poisol/stub/request/query_builder.rb
|
138
139
|
- lib/poisol/stub/request/request_body_builder.rb
|
139
140
|
- lib/poisol/stub/request/url_builder.rb
|
@@ -141,9 +142,9 @@ files:
|
|
141
142
|
- lib/poisol/stub/response/response_body_builder.rb
|
142
143
|
- lib/poisol/stub/response/status_builder.rb
|
143
144
|
- lib/poisol/stub/stub.rb
|
144
|
-
- lib/poisol/stub/
|
145
|
-
- lib/poisol/stub/
|
146
|
-
- lib/poisol/stub/
|
145
|
+
- lib/poisol/stub/stub_builder.rb
|
146
|
+
- lib/poisol/stub/stub_builder_class.rb
|
147
|
+
- lib/poisol/stub/stub_builder_instance.rb
|
147
148
|
- lib/poisol/stub_config/stub_config.rb
|
148
149
|
- lib/poisol/stub_config/stub_config_builder.rb
|
149
150
|
- lib/poisol/stub_factory.rb
|
@@ -181,6 +182,7 @@ files:
|
|
181
182
|
- spec/functional/response/hash_params_spec.rb
|
182
183
|
- spec/functional/response/nested_array_spec.rb
|
183
184
|
- spec/functional/url_spec.rb
|
185
|
+
- spec/functional/wasted_spec.rb
|
184
186
|
- spec/spec_helper.rb
|
185
187
|
- spec/unit/exception_spec.rb
|
186
188
|
- spec/unit/extension/hash_spec.rb
|
@@ -231,6 +233,7 @@ test_files:
|
|
231
233
|
- spec/unit/exception_spec.rb
|
232
234
|
- spec/unit/stub_spec.rb
|
233
235
|
- spec/spec_helper.rb
|
236
|
+
- spec/functional/wasted_spec.rb
|
234
237
|
- spec/functional/multi_domain_spec.rb
|
235
238
|
- spec/functional/key_value/explicit_inclusion_spec.rb
|
236
239
|
- spec/functional/key_value/implicit_inclusion_spec.rb
|
@@ -1,42 +0,0 @@
|
|
1
|
-
module Poisol
|
2
|
-
module WebrickStubBuilder
|
3
|
-
def build
|
4
|
-
build_url
|
5
|
-
build_query
|
6
|
-
build_request_body
|
7
|
-
build_response_body
|
8
|
-
Stubs.add self
|
9
|
-
self
|
10
|
-
end
|
11
|
-
|
12
|
-
private
|
13
|
-
def build_url
|
14
|
-
remove_path_param_name_from_url
|
15
|
-
@request.url = "#{stub_config.request.domain}/#{@request.path}"
|
16
|
-
end
|
17
|
-
|
18
|
-
def build_query
|
19
|
-
return if @request.query.blank?
|
20
|
-
@request.query = @request.query.to_query
|
21
|
-
end
|
22
|
-
|
23
|
-
def build_request_body
|
24
|
-
return if @request.body.blank?
|
25
|
-
@request.body = Parse.hash_to_concatenated_key_value(@request.body) if stub_config.request.is_body_key_value
|
26
|
-
end
|
27
|
-
|
28
|
-
def build_response_body
|
29
|
-
@response.body = Parse.hash_array_to_column_hash(@response.body) if stub_config.response.is_column_array and !@is_response_dumped.present?
|
30
|
-
end
|
31
|
-
|
32
|
-
def remove_path_param_name_from_url
|
33
|
-
@request.path.scan(/{(.+?)}/).each do |path_params|
|
34
|
-
path_param = path_params[0]
|
35
|
-
param_name = path_param.split("|")[0]
|
36
|
-
param_value = path_param.split("|")[1]
|
37
|
-
@request.path.sub!("{#{path_param}}",param_value)
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
end
|
42
|
-
end
|