poisol 0.0.7 → 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/poisol/domain.rb +2 -5
- data/lib/poisol/stub_config.rb +7 -1
- data/lib/poisol/stub_factory.rb +3 -3
- data/lib/poisol/template/build.rb +2 -2
- data/lib/poisol/template/url_handler.rb +2 -1
- data/spec/data/domain/first/domain.yml +2 -0
- data/spec/data/domain/first/first.yml +7 -0
- data/spec/data/domain/second/domain.yml +2 -0
- data/spec/data/domain/second/second.yml +7 -0
- data/spec/data/main/array/columns.yml +9 -0
- data/spec/data/main/array/rows.yml +11 -0
- data/spec/data/main/book.yml +17 -0
- data/spec/data/main/domain.yml +2 -0
- data/spec/data/main/key_value/explicit.yml +9 -0
- data/spec/data/main/key_value/key_value.yml +8 -0
- data/spec/data/main/nested_array.yml +13 -0
- data/spec/data/main/url.yml +5 -0
- data/spec/data/main/user/config.yml +3 -0
- data/spec/data/main/user/request.json +3 -0
- data/spec/data/main/user/response.json +3 -0
- data/spec/functional/array_spec.rb +2 -2
- data/spec/functional/dumb_response_spec.rb +2 -2
- data/spec/functional/get_spec.rb +2 -2
- data/spec/functional/key_value/explicit_inclusion_spec.rb +2 -2
- data/spec/functional/key_value/implicit_inclusion_spec.rb +3 -3
- data/spec/functional/multi_domain_spec.rb +13 -0
- data/spec/functional/nested_array_spec.rb +5 -5
- data/spec/functional/post_spec.rb +2 -2
- data/spec/functional/url_spec.rb +3 -3
- data/spec/spec_helper.rb +3 -1
- metadata +33 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 534d85b7e97186a0fb7bb51365f92dd513431be2
|
4
|
+
data.tar.gz: ad63697e35dce8bef219598deef37270b0f67afb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 998572b0699167bbc9ed8bacfee2b9e31a44bf61fb018b330094d821af9fd91539a056513130742509fba0ef1a1b19db800b94405b62180fedb153b3a50ec217
|
7
|
+
data.tar.gz: d6c72a945f02c74fd70098399a3f0ee386a8414a26d04c1edd515ec283a2d9541dcdacc2c379d9dae584413db5de3b3d87d6eea2155521ba5d97c7ab09f7d43e
|
data/lib/poisol/domain.rb
CHANGED
@@ -1,12 +1,9 @@
|
|
1
1
|
class Domain
|
2
|
-
def
|
2
|
+
def load domain_config
|
3
3
|
base_hash = Parse.yaml_file domain_config
|
4
4
|
domain = base_hash["domain"]
|
5
5
|
port = base_hash["port"]
|
6
|
-
|
6
|
+
"#{domain.chomp('\\')}#{ port.present? ? ":#{port}" : "" }"
|
7
7
|
end
|
8
8
|
|
9
|
-
def self.base_url
|
10
|
-
@@base_url
|
11
|
-
end
|
12
9
|
end
|
data/lib/poisol/stub_config.rb
CHANGED
@@ -7,6 +7,11 @@ class StubConfig
|
|
7
7
|
self
|
8
8
|
end
|
9
9
|
|
10
|
+
def with_domain domain
|
11
|
+
@domain = domain
|
12
|
+
self
|
13
|
+
end
|
14
|
+
|
10
15
|
def is_inline
|
11
16
|
@is_inline = true
|
12
17
|
self
|
@@ -26,6 +31,7 @@ class StubConfig
|
|
26
31
|
private
|
27
32
|
def build_request
|
28
33
|
@request = Request.new
|
34
|
+
@request.domain=@domain.clone
|
29
35
|
@request.url = @config_yml["request"]["url"]
|
30
36
|
@request.type = @config_yml["request"]["type"].intern
|
31
37
|
@request.query = @config_yml["request"]["query"]
|
@@ -80,7 +86,7 @@ end
|
|
80
86
|
|
81
87
|
|
82
88
|
class Request
|
83
|
-
attr_accessor :url,:type,:query,:body,:is_body_key_value,:include_explicit_only
|
89
|
+
attr_accessor :domain,:url,:type,:query,:body,:is_body_key_value,:include_explicit_only
|
84
90
|
end
|
85
91
|
|
86
92
|
class Response
|
data/lib/poisol/stub_factory.rb
CHANGED
@@ -4,7 +4,7 @@ class StubFactory
|
|
4
4
|
domain_config = Dir["#{folder}/domain.yml"].first
|
5
5
|
explolded_configs = Dir["#{folder}/**/config.yml"]
|
6
6
|
inline_configs = Dir["#{folder}/**/*.yml"] - ( (explolded_configs.nil?) ? [] : explolded_configs) - [domain_config]
|
7
|
-
Domain.load domain_config
|
7
|
+
@domain = Domain.new.load domain_config
|
8
8
|
generate_exploded_config explolded_configs unless explolded_configs.nil?
|
9
9
|
generate_inline_config inline_configs unless inline_configs.nil?
|
10
10
|
end
|
@@ -15,7 +15,7 @@ class StubFactory
|
|
15
15
|
def generate_exploded_config explolded_configs
|
16
16
|
explolded_configs.each do |config_file|
|
17
17
|
dynamic_name = FileUtil.titilze_parent_dir config_file
|
18
|
-
config = StubConfig.new.is_exploded.with_file(config_file).build
|
18
|
+
config = StubConfig.new.is_exploded.with_file(config_file).with_domain(@domain).build
|
19
19
|
create_class dynamic_name,config
|
20
20
|
end
|
21
21
|
end
|
@@ -23,7 +23,7 @@ class StubFactory
|
|
23
23
|
def generate_inline_config inline_configs
|
24
24
|
inline_configs.each do |config_file|
|
25
25
|
dynamic_name = FileUtil.titilze_file_name config_file
|
26
|
-
config = StubConfig.new.is_inline.with_file(config_file).build
|
26
|
+
config = StubConfig.new.is_inline.with_file(config_file).with_domain(@domain).build
|
27
27
|
create_class dynamic_name,config
|
28
28
|
end
|
29
29
|
end
|
@@ -8,7 +8,7 @@ module ClassTemplate
|
|
8
8
|
|
9
9
|
def build_url
|
10
10
|
remove_path_param_name_from_url
|
11
|
-
@stub = stub_request(@type, "http://#{
|
11
|
+
@stub = stub_request(@type, "http://#{@config.request.domain}/#{@url}")
|
12
12
|
end
|
13
13
|
|
14
14
|
def build_query
|
@@ -23,7 +23,7 @@ module ClassTemplate
|
|
23
23
|
|
24
24
|
def build_response_body
|
25
25
|
@response_body = Parse.hash_array_to_column_hash(@response_body) if @config.response.is_column_array
|
26
|
-
@stub.to_return(:status => 200, :body => @response_body.
|
26
|
+
@stub.to_return(:status => 200, :body => @response_body.to_json, :headers => {'Content-Type' => 'application/json'})
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
@@ -1,6 +1,8 @@
|
|
1
1
|
module ClassTemplate
|
2
2
|
def generate_methods_to_alter_path_params
|
3
3
|
@url = @config.request.url.clone
|
4
|
+
@url.strip!
|
5
|
+
@url.sub!("/","") if @url[0].eql? "/"
|
4
6
|
@url.scan(/{(.+?)}/).each do |path_params|
|
5
7
|
path_param = path_params[0]
|
6
8
|
param_name = path_param.split("|")[0]
|
@@ -14,7 +16,6 @@ module ClassTemplate
|
|
14
16
|
end
|
15
17
|
end
|
16
18
|
|
17
|
-
|
18
19
|
def remove_path_param_name_from_url
|
19
20
|
@url.scan(/{(.+?)}/).each do |path_params|
|
20
21
|
path_param = path_params[0]
|
@@ -9,7 +9,7 @@ describe ClassTemplate, "#array" do
|
|
9
9
|
it "column array" do
|
10
10
|
Columns.new.has_column.has_column.with_title("abc").with_category("12").build
|
11
11
|
response = RestClient.get "http://localhost:80/column"
|
12
|
-
expect(response.body).to eq({"title"=>["independance", "abc"], "category"=>["10","12"]}.
|
12
|
+
expect(response.body).to eq({"title"=>["independance", "abc"], "category"=>["10","12"]}.to_json)
|
13
13
|
end
|
14
14
|
|
15
15
|
it "empty row array" do
|
@@ -21,7 +21,7 @@ describe ClassTemplate, "#array" do
|
|
21
21
|
it "row array" do
|
22
22
|
Rows.new.has_row.has_row.with_title("abc").with_category("age_group" => "12").build
|
23
23
|
response = RestClient.get "http://localhost:80/row"
|
24
|
-
expect(response.body).to eq([{"title"=>"independance", "category"=>{"age_group"=>"10"}}, {"title"=>"abc", "category"=>{"age_group"=>"12"}}].
|
24
|
+
expect(response.body).to eq([{"title"=>"independance", "category"=>{"age_group"=>"10"}}, {"title"=>"abc", "category"=>{"age_group"=>"12"}}].to_json)
|
25
25
|
end
|
26
26
|
|
27
27
|
|
@@ -1,9 +1,9 @@
|
|
1
1
|
describe ClassTemplate, "#dumb response" do
|
2
2
|
|
3
3
|
it "column array" do
|
4
|
-
Columns.new.set_dumb_response("data/user/response.json").build
|
4
|
+
Columns.new.set_dumb_response("spec/data/main/user/response.json").build
|
5
5
|
response = RestClient.get "http://localhost:80/column"
|
6
|
-
expect(response.body).to eq(
|
6
|
+
expect(response.body).to eq({"job"=>"sleeping_bag"}.to_json)
|
7
7
|
end
|
8
8
|
|
9
9
|
end
|
data/spec/functional/get_spec.rb
CHANGED
@@ -3,13 +3,13 @@ describe ClassTemplate, "#get_books" do
|
|
3
3
|
it "dynamic response" do
|
4
4
|
Book.new.has_category({"age_group"=>"11", "publisher"=>{"name"=>"oxford"}}).build()
|
5
5
|
response = RestClient.get "http://localhost:80/book",{:params => {:author=>'bharathi'}}
|
6
|
-
expect(response.body).to eq({"title"=>"independance", "category"=>{"age_group"=>"11", "genre"=>"action", "publisher"=>{"name"=>"oxford", "place"=>"erode"}}}.
|
6
|
+
expect(response.body).to eq({"title"=>"independance", "category"=>{"age_group"=>"11", "genre"=>"action", "publisher"=>{"name"=>"oxford", "place"=>"erode"}}}.to_json)
|
7
7
|
end
|
8
8
|
|
9
9
|
it "default request and response" do
|
10
10
|
Book.new.build()
|
11
11
|
response = RestClient.get "http://localhost:80/book",{:params => {:author=>'bharathi'}}
|
12
|
-
expect(response.body).to eq({"title"=>"independance", "category"=>{"age_group"=>"10", "genre"=>"action", "publisher"=>{"name"=>"summa", "place"=>"erode"}}}.
|
12
|
+
expect(response.body).to eq({"title"=>"independance", "category"=>{"age_group"=>"10", "genre"=>"action", "publisher"=>{"name"=>"summa", "place"=>"erode"}}}.to_json)
|
13
13
|
end
|
14
14
|
|
15
15
|
end
|
@@ -3,13 +3,13 @@ describe ClassTemplate, "#key_value" do
|
|
3
3
|
it "partial dynamic request" do
|
4
4
|
Explicit.new.by_name("ram").build()
|
5
5
|
response = RestClient.post "http://localhost:80/explicit","name=ram"
|
6
|
-
expect(response.body).to eq({"hi"=>1}.
|
6
|
+
expect(response.body).to eq({"hi"=>1}.to_json)
|
7
7
|
end
|
8
8
|
|
9
9
|
it "dynamic request" do
|
10
10
|
Explicit.new.by_name("ram").by_age(11).build()
|
11
11
|
response = RestClient.post "http://localhost:80/explicit","name=ram&age=11"
|
12
|
-
expect(response.body).to eq({"hi"=>1}.
|
12
|
+
expect(response.body).to eq({"hi"=>1}.to_json)
|
13
13
|
end
|
14
14
|
|
15
15
|
end
|
@@ -3,19 +3,19 @@ describe ClassTemplate, "#key_value" do
|
|
3
3
|
it "default request" do
|
4
4
|
KeyValue.new.build()
|
5
5
|
response = RestClient.post "http://localhost:80/keyvalue","name=sea&age=10"
|
6
|
-
expect(response.body).to eq({"hi"=>1}.
|
6
|
+
expect(response.body).to eq({"hi"=>1}.to_json)
|
7
7
|
end
|
8
8
|
|
9
9
|
it "partial dynamic request" do
|
10
10
|
KeyValue.new.by_name("ram").build()
|
11
11
|
response = RestClient.post "http://localhost:80/keyvalue","name=ram&age=10"
|
12
|
-
expect(response.body).to eq({"hi"=>1}.
|
12
|
+
expect(response.body).to eq({"hi"=>1}.to_json)
|
13
13
|
end
|
14
14
|
|
15
15
|
it "dynamic request" do
|
16
16
|
KeyValue.new.by_name("ram").by_age(11).build()
|
17
17
|
response = RestClient.post "http://localhost:80/keyvalue","name=ram&age=11"
|
18
|
-
expect(response.body).to eq({"hi"=>1}.
|
18
|
+
expect(response.body).to eq({"hi"=>1}.to_json)
|
19
19
|
end
|
20
20
|
|
21
21
|
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
describe ClassTemplate, "#multi domain" do
|
2
|
+
|
3
|
+
it "support multi domain" do
|
4
|
+
First.new.build
|
5
|
+
response = RestClient.get "http://localhos:801/first"
|
6
|
+
expect(response.body).to eq({"title"=>"1"}.to_json)
|
7
|
+
Second.new.build
|
8
|
+
response = RestClient.get "http://localhos:802/second"
|
9
|
+
expect(response.body).to eq({"title"=>"1"}.to_json)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
|
@@ -3,31 +3,31 @@ describe ClassTemplate, "#nested array" do
|
|
3
3
|
it "empty" do
|
4
4
|
NestedArray.new.has_no_role.build()
|
5
5
|
response = RestClient.get "http://localhost:80/nested_array"
|
6
|
-
expect(response.body).to eq({"title"=>"ind", "roles"=>[]}.
|
6
|
+
expect(response.body).to eq({"title"=>"ind", "roles"=>[]}.to_json)
|
7
7
|
end
|
8
8
|
|
9
9
|
it "without mentioning field" do
|
10
10
|
NestedArray.new.build()
|
11
11
|
response = RestClient.get "http://localhost:80/nested_array"
|
12
|
-
expect(response.body).to eq({"title"=>"ind", "roles"=>[{"role_id"=>"chumma", "role_name"=>"sol"}]}.
|
12
|
+
expect(response.body).to eq({"title"=>"ind", "roles"=>[{"role_id"=>"chumma", "role_name"=>"sol"}]}.to_json)
|
13
13
|
end
|
14
14
|
|
15
15
|
it "mentioning one field" do
|
16
16
|
NestedArray.new.has_role.build()
|
17
17
|
response = RestClient.get "http://localhost:80/nested_array"
|
18
|
-
expect(response.body).to eq({"title"=>"ind", "roles"=>[{"role_id"=>"chumma", "role_name"=>"sol"}]}.
|
18
|
+
expect(response.body).to eq({"title"=>"ind", "roles"=>[{"role_id"=>"chumma", "role_name"=>"sol"}]}.to_json)
|
19
19
|
end
|
20
20
|
|
21
21
|
it "mentioning one field with altered values" do
|
22
22
|
NestedArray.new.has_role("role_id"=>"test1").build()
|
23
23
|
response = RestClient.get "http://localhost:80/nested_array"
|
24
|
-
expect(response.body).to eq({"title"=>"ind", "roles"=>[{"role_id"=>"test1", "role_name"=>"sol"}]}.
|
24
|
+
expect(response.body).to eq({"title"=>"ind", "roles"=>[{"role_id"=>"test1", "role_name"=>"sol"}]}.to_json)
|
25
25
|
end
|
26
26
|
|
27
27
|
it "multiple fields with altered values" do
|
28
28
|
NestedArray.new.has_role.has_another_role("role_id"=>"test").build()
|
29
29
|
response = RestClient.get "http://localhost:80/nested_array"
|
30
|
-
expect(response.body).to eq({"title"=>"ind", "roles"=>[{"role_id"=>"chumma", "role_name"=>"sol"},{"role_id"=>"test", "role_name"=>"sol"}]}.
|
30
|
+
expect(response.body).to eq({"title"=>"ind", "roles"=>[{"role_id"=>"chumma", "role_name"=>"sol"},{"role_id"=>"test", "role_name"=>"sol"}]}.to_json)
|
31
31
|
end
|
32
32
|
|
33
33
|
end
|
@@ -3,7 +3,7 @@ describe ClassTemplate, "#post_user" do
|
|
3
3
|
it "default request and response" do
|
4
4
|
User.new.build()
|
5
5
|
response = RestClient.post "http://localhost:80/users","name"=>"deepak"
|
6
|
-
expect(response.body).to eq({"job"=>'sleeping_bag'}.
|
6
|
+
expect(response.body).to eq({"job"=>'sleeping_bag'}.to_json)
|
7
7
|
end
|
8
8
|
|
9
9
|
it "dynamic request and response" do
|
@@ -11,7 +11,7 @@ describe ClassTemplate, "#post_user" do
|
|
11
11
|
job = "vetti"
|
12
12
|
User.new.by_name(name).has_job(job).build()
|
13
13
|
response = RestClient.post "http://localhost:80/users","name"=>name
|
14
|
-
expect(response.body).to eq({"job"=>job}.
|
14
|
+
expect(response.body).to eq({"job"=>job}.to_json)
|
15
15
|
end
|
16
16
|
|
17
17
|
end
|
data/spec/functional/url_spec.rb
CHANGED
@@ -3,19 +3,19 @@ describe ClassTemplate, "#url" do
|
|
3
3
|
it "default" do
|
4
4
|
Url.new.build()
|
5
5
|
response = RestClient.get "http://localhost:80/cda/cd/ragavan/get"
|
6
|
-
expect(response.body).to eq({"hi"=>1}.
|
6
|
+
expect(response.body).to eq({"hi"=>1}.to_json)
|
7
7
|
end
|
8
8
|
|
9
9
|
it "dynamic" do
|
10
10
|
Url.new.for_name("hitler").for_actor("mani").build()
|
11
11
|
response = RestClient.get "http://localhost:80/cda/hitler/mani/get"
|
12
|
-
expect(response.body).to eq({"hi"=>1}.
|
12
|
+
expect(response.body).to eq({"hi"=>1}.to_json)
|
13
13
|
end
|
14
14
|
|
15
15
|
it "partial" do
|
16
16
|
Url.new.for_actor("mani").build()
|
17
17
|
response = RestClient.get "http://localhost:80/cda/cd/mani/get"
|
18
|
-
expect(response.body).to eq({"hi"=>1}.
|
18
|
+
expect(response.body).to eq({"hi"=>1}.to_json)
|
19
19
|
end
|
20
20
|
|
21
21
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -21,7 +21,9 @@ RSpec.configure do |config|
|
|
21
21
|
|
22
22
|
config.before(:suite) do
|
23
23
|
WebMock.disable_net_connect!(:allow_localhost => true)
|
24
|
-
factory = StubFactory.new.build("data")
|
24
|
+
factory = StubFactory.new.build("spec/data/main")
|
25
|
+
factory = StubFactory.new.build("spec/data/domain/first/")
|
26
|
+
factory = StubFactory.new.build("spec/data/domain/second/")
|
25
27
|
end
|
26
28
|
|
27
29
|
end
|
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.0.
|
4
|
+
version: 0.0.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Deepak
|
@@ -142,11 +142,27 @@ files:
|
|
142
142
|
- lib/poisol/template/url_handler.rb
|
143
143
|
- lib/poisol/utils/file_util.rb
|
144
144
|
- lib/poisol/utils/parse.rb
|
145
|
+
- spec/data/domain/first/domain.yml
|
146
|
+
- spec/data/domain/first/first.yml
|
147
|
+
- spec/data/domain/second/domain.yml
|
148
|
+
- spec/data/domain/second/second.yml
|
149
|
+
- spec/data/main/array/columns.yml
|
150
|
+
- spec/data/main/array/rows.yml
|
151
|
+
- spec/data/main/book.yml
|
152
|
+
- spec/data/main/domain.yml
|
153
|
+
- spec/data/main/key_value/explicit.yml
|
154
|
+
- spec/data/main/key_value/key_value.yml
|
155
|
+
- spec/data/main/nested_array.yml
|
156
|
+
- spec/data/main/url.yml
|
157
|
+
- spec/data/main/user/config.yml
|
158
|
+
- spec/data/main/user/request.json
|
159
|
+
- spec/data/main/user/response.json
|
145
160
|
- spec/functional/array_spec.rb
|
146
161
|
- spec/functional/dumb_response_spec.rb
|
147
162
|
- spec/functional/get_spec.rb
|
148
163
|
- spec/functional/key_value/explicit_inclusion_spec.rb
|
149
164
|
- spec/functional/key_value/implicit_inclusion_spec.rb
|
165
|
+
- spec/functional/multi_domain_spec.rb
|
150
166
|
- spec/functional/nested_array_spec.rb
|
151
167
|
- spec/functional/post_spec.rb
|
152
168
|
- spec/functional/url_spec.rb
|
@@ -176,7 +192,23 @@ signing_key:
|
|
176
192
|
specification_version: 4
|
177
193
|
summary: Generate builders for http stubs
|
178
194
|
test_files:
|
195
|
+
- spec/data/domain/first/domain.yml
|
196
|
+
- spec/data/domain/first/first.yml
|
197
|
+
- spec/data/domain/second/domain.yml
|
198
|
+
- spec/data/domain/second/second.yml
|
199
|
+
- spec/data/main/user/config.yml
|
200
|
+
- spec/data/main/user/request.json
|
201
|
+
- spec/data/main/user/response.json
|
202
|
+
- spec/data/main/array/columns.yml
|
203
|
+
- spec/data/main/array/rows.yml
|
204
|
+
- spec/data/main/domain.yml
|
205
|
+
- spec/data/main/url.yml
|
206
|
+
- spec/data/main/nested_array.yml
|
207
|
+
- spec/data/main/key_value/explicit.yml
|
208
|
+
- spec/data/main/key_value/key_value.yml
|
209
|
+
- spec/data/main/book.yml
|
179
210
|
- spec/spec_helper.rb
|
211
|
+
- spec/functional/multi_domain_spec.rb
|
180
212
|
- spec/functional/array_spec.rb
|
181
213
|
- spec/functional/get_spec.rb
|
182
214
|
- spec/functional/key_value/explicit_inclusion_spec.rb
|