poisol 0.0.17 → 0.1.0
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 +7 -4
- data/lib/poisol/response_mapper.rb +26 -0
- data/lib/poisol/server.rb +46 -0
- data/lib/poisol/stub/request/url_builder.rb +1 -1
- data/lib/poisol/stub/stub.rb +4 -4
- data/lib/poisol/stub/stub_instance.rb +2 -1
- data/lib/poisol/stub/{webmock_stub_builder.rb → webrick_stub_builder.rb} +8 -8
- data/lib/poisol/stubs.rb +71 -0
- data/lib/poisol/utils/parse.rb +1 -0
- data/lib/poisol.rb +17 -5
- data/spec/data/domain/first/domain.yml +1 -2
- data/spec/data/domain/second/domain.yml +1 -2
- data/spec/data/main/domain.yml +1 -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 +2 -2
- data/spec/functional/post_request_spec.rb +2 -2
- data/spec/functional/query/query_explicit_spec.rb +3 -3
- data/spec/functional/query/query_implicit_spec.rb +3 -3
- data/spec/functional/response/array_spec.rb +8 -8
- data/spec/functional/response/dumb_response_spec.rb +1 -1
- data/spec/functional/response/hash_params_spec.rb +3 -3
- data/spec/functional/response/nested_array_spec.rb +6 -6
- data/spec/functional/url_spec.rb +3 -3
- data/spec/spec_helper.rb +9 -8
- data/spec/unit/exception_spec.rb +0 -1
- metadata +7 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c66331f663c993f5ad291f2947764e56f4b2c65a
|
4
|
+
data.tar.gz: 1156dc7a6b8d3bcfc7b03bb482c832cb9a30768c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cc9bef8c9cb1c1955f71bf7eeea8c85b016df9c0e69a23b844461d4c2b60f246137b0843a5bf6c735ed7ee4362dc173c0768e7351ae7b5eca4039dddb73480b4
|
7
|
+
data.tar.gz: a1c7bec0f36c8b5e9229fc8e794f3f985baa9185fa30583eb1058544a69318c57e71cb52a669fb39ff1bd9bfe9af1902b8d840fb319dfd92d8bd0fae2a891720
|
data/lib/poisol/domain.rb
CHANGED
@@ -3,10 +3,13 @@ class Domain
|
|
3
3
|
|
4
4
|
def initialize domain_config_file
|
5
5
|
@file = domain_config_file
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
6
|
+
path = ""
|
7
|
+
if File.exists? @file
|
8
|
+
base_hash = Parse.yaml_file @file
|
9
|
+
sub_domain = base_hash["sub_domain"]
|
10
|
+
path = "/#{sub_domain}" if sub_domain.present?
|
11
|
+
end
|
12
|
+
@full_url = "#{Server.base_url}#{ path.present? ? path: ''}"
|
10
13
|
end
|
11
14
|
|
12
15
|
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module ResponseMapper
|
2
|
+
extend self
|
3
|
+
|
4
|
+
def map webrick_request
|
5
|
+
stub_request = get_stub_request webrick_request
|
6
|
+
stub_response = get_stub_response stub_request
|
7
|
+
end
|
8
|
+
|
9
|
+
def get_stub_request webrick_request
|
10
|
+
stub_request = Request.new
|
11
|
+
stub_request.type = webrick_request.request_method.downcase
|
12
|
+
uri = webrick_request.request_uri
|
13
|
+
stub_request.url = uri.query.blank? ? uri.to_s : uri.to_s.sub(uri.query,"").sub("?","")
|
14
|
+
stub_request.query = webrick_request.query_string
|
15
|
+
stub_request.body = webrick_request.body
|
16
|
+
stub_request
|
17
|
+
end
|
18
|
+
|
19
|
+
|
20
|
+
def get_stub_response stub_request
|
21
|
+
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
|
+
return stub.response if stub.present?
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
module Server
|
2
|
+
extend self
|
3
|
+
|
4
|
+
def start port
|
5
|
+
require 'webrick'
|
6
|
+
@server = WEBrick::HTTPServer.new :Port => port, :Logger => log, :AccessLog => access_log
|
7
|
+
@port = port
|
8
|
+
attach_shutdown
|
9
|
+
attach_request_handling
|
10
|
+
Thread.new{@server.start}
|
11
|
+
end
|
12
|
+
|
13
|
+
def base_url
|
14
|
+
"http://localhost:#{@port}"
|
15
|
+
end
|
16
|
+
|
17
|
+
def attach_request_handling
|
18
|
+
@server.mount_proc '/' do |req, res|
|
19
|
+
stub_response = ResponseMapper.map(req)
|
20
|
+
res.status = stub_response.status
|
21
|
+
res.body = stub_response.body.to_json
|
22
|
+
res.content_type = 'application/json'
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def attach_shutdown
|
27
|
+
trap 'INT' do @server.shutdown end
|
28
|
+
end
|
29
|
+
|
30
|
+
def log
|
31
|
+
log_file = File.open 'log/poisol_webrick.log', 'a+'
|
32
|
+
WEBrick::Log.new log_file
|
33
|
+
end
|
34
|
+
|
35
|
+
def access_log
|
36
|
+
log_file = File.open 'log/poisol_webrick.log', 'a+'
|
37
|
+
[
|
38
|
+
[log_file, WEBrick::AccessLog::COMBINED_LOG_FORMAT],
|
39
|
+
]
|
40
|
+
end
|
41
|
+
|
42
|
+
def stop
|
43
|
+
@server.shutdown
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
@@ -8,7 +8,7 @@ module UrlBuilder
|
|
8
8
|
method_name = "of_#{param_name.underscore}"
|
9
9
|
define_method(method_name) do |*input_value|
|
10
10
|
input_value = input_value[0]
|
11
|
-
@request.
|
11
|
+
@request.path.sub!("{#{path_param}}","{#{param_name}|#{input_value}}") unless input_value.blank?
|
12
12
|
self
|
13
13
|
end
|
14
14
|
end
|
data/lib/poisol/stub/stub.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
|
-
require_relative "
|
1
|
+
require_relative "webrick_stub_builder"
|
2
2
|
require_relative "stub_class_builder"
|
3
3
|
require_relative "stub_instance"
|
4
4
|
|
5
5
|
class Stub
|
6
|
-
include
|
6
|
+
include WebrickStubBuilder
|
7
7
|
include StubInstance
|
8
8
|
attr_accessor :request,:response
|
9
9
|
class << self
|
@@ -20,11 +20,11 @@ class Stub
|
|
20
20
|
end
|
21
21
|
|
22
22
|
class Request
|
23
|
-
attr_accessor :url,:query,:body
|
23
|
+
attr_accessor :url,:query,:body,:path,:type
|
24
24
|
end
|
25
25
|
|
26
26
|
class Response
|
27
|
-
attr_accessor :body,:status
|
27
|
+
attr_accessor :body,:status,:header
|
28
28
|
end
|
29
29
|
|
30
30
|
|
@@ -6,7 +6,7 @@ module StubInstance
|
|
6
6
|
|
7
7
|
def init_request
|
8
8
|
@request = Request.new
|
9
|
-
@request.
|
9
|
+
@request.path = stub_config.request.url.deep_dup
|
10
10
|
@request.query = stub_config.request.query_explicit ? {} : stub_config.request.query.deep_dup
|
11
11
|
@request.body = stub_config.request.body_explicit ? {} : stub_config.request.body.deep_dup
|
12
12
|
end
|
@@ -19,6 +19,7 @@ module StubInstance
|
|
19
19
|
@response.body = stub_config.response.body.deep_dup
|
20
20
|
end
|
21
21
|
@response.status = 200
|
22
|
+
@response.header = {'Content-Type' => 'application/json'}
|
22
23
|
end
|
23
24
|
|
24
25
|
def set_dumb_response response_file
|
@@ -1,39 +1,39 @@
|
|
1
|
-
module
|
1
|
+
module WebrickStubBuilder
|
2
2
|
def build
|
3
3
|
build_url
|
4
4
|
build_query
|
5
5
|
build_request_body
|
6
6
|
build_response_body
|
7
|
-
|
7
|
+
Stubs.add self
|
8
|
+
self
|
8
9
|
end
|
9
10
|
|
10
11
|
private
|
11
12
|
def build_url
|
12
13
|
remove_path_param_name_from_url
|
13
|
-
@
|
14
|
+
@request.url = "#{stub_config.request.domain}/#{@request.path}"
|
14
15
|
end
|
15
16
|
|
16
17
|
def build_query
|
17
|
-
|
18
|
+
return if @request.query.blank?
|
19
|
+
@request.query = @request.query.to_query
|
18
20
|
end
|
19
21
|
|
20
22
|
def build_request_body
|
21
23
|
return if @request.body.blank?
|
22
24
|
@request.body = Parse.hash_to_concatenated_key_value(@request.body) if stub_config.request.is_body_key_value
|
23
|
-
@webmock_stub.with(:body => @request.body)
|
24
25
|
end
|
25
26
|
|
26
27
|
def build_response_body
|
27
28
|
@response.body = Parse.hash_array_to_column_hash(@response.body) if stub_config.response.is_column_array and !@is_response_dumped.present?
|
28
|
-
@webmock_stub.to_return(:status => @response.status, :body => @response.body.to_json, :headers => {'Content-Type' => 'application/json'})
|
29
29
|
end
|
30
30
|
|
31
31
|
def remove_path_param_name_from_url
|
32
|
-
@request.
|
32
|
+
@request.path.scan(/{(.+?)}/).each do |path_params|
|
33
33
|
path_param = path_params[0]
|
34
34
|
param_name = path_param.split("|")[0]
|
35
35
|
param_value = path_param.split("|")[1]
|
36
|
-
@request.
|
36
|
+
@request.path.sub!("{#{path_param}}",param_value)
|
37
37
|
end
|
38
38
|
end
|
39
39
|
|
data/lib/poisol/stubs.rb
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
module Stubs
|
2
|
+
extend self
|
3
|
+
|
4
|
+
def add stub
|
5
|
+
@stubs = [] if @stubs.blank?
|
6
|
+
@stubs << stub
|
7
|
+
end
|
8
|
+
|
9
|
+
def reset
|
10
|
+
@stubs = []
|
11
|
+
end
|
12
|
+
|
13
|
+
def get_match request
|
14
|
+
return nil if @stubs.blank?
|
15
|
+
matches = @stubs.select{|stub| stub.request.url == request.url }
|
16
|
+
matches = matches.select{|stub|query_matches?(request.query,stub.request.query)} if request.query.present? && matches.present?
|
17
|
+
matches = matches.select{|stub|body_matches? request.body,stub.request.body} if request.body.present? && matches.present?
|
18
|
+
return matches.present? ? matches[0] : nil
|
19
|
+
end
|
20
|
+
|
21
|
+
def query_matches? (actual,stub)
|
22
|
+
return false if stub.blank?
|
23
|
+
return actual==stub
|
24
|
+
end
|
25
|
+
|
26
|
+
def body_matches? (actual_request_body,stub_request_body)
|
27
|
+
return true if stub_request_body.present? && actual_request_body == stub_request_body
|
28
|
+
return false if stub_request_body.blank?
|
29
|
+
actual_request_body = load_as_json actual_request_body
|
30
|
+
stub_request_body = load_as_json stub_request_body
|
31
|
+
return false unless actual_request_body.class == stub_request_body.class
|
32
|
+
return matching_hashes? actual_request_body,stub_request_body if actual_request_body.is_a?(Hash)
|
33
|
+
return matching_array? actual_request_body,stub_request_body if actual_request_body.is_a?(Array)
|
34
|
+
return false
|
35
|
+
end
|
36
|
+
|
37
|
+
def load_as_json input
|
38
|
+
require 'json'
|
39
|
+
begin
|
40
|
+
return JSON.parse input
|
41
|
+
rescue
|
42
|
+
return input
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
|
47
|
+
def matching_hashes?(query_parameters, pattern)
|
48
|
+
return false unless query_parameters.is_a?(Hash)
|
49
|
+
return false unless query_parameters.keys.sort == pattern.keys.sort
|
50
|
+
query_parameters.each do |key, actual|
|
51
|
+
expected = pattern[key]
|
52
|
+
|
53
|
+
if actual.is_a?(Hash) && expected.is_a?(Hash)
|
54
|
+
return false unless matching_hashes?(actual, expected)
|
55
|
+
else
|
56
|
+
return false unless expected === actual
|
57
|
+
end
|
58
|
+
end
|
59
|
+
true
|
60
|
+
end
|
61
|
+
|
62
|
+
def matching_array actuals,expected
|
63
|
+
return false unless actuals.size == expected.size
|
64
|
+
return actuals.sort == expected.sort unless actual[0].is_a(Hash)
|
65
|
+
expect = expected.clone
|
66
|
+
actuals.each do |actual|
|
67
|
+
match = expect.detect {|pattern| matching_hashes? actual,expect}
|
68
|
+
return false if match.blank?
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
data/lib/poisol/utils/parse.rb
CHANGED
data/lib/poisol.rb
CHANGED
@@ -5,15 +5,27 @@ Dir["#{File.dirname(__FILE__)}/poisol/**/*.rb"].each { |f| require(f) }
|
|
5
5
|
module Poisol
|
6
6
|
extend self
|
7
7
|
|
8
|
+
def start (param={:at_port=>3030})
|
9
|
+
Server.start param[:at_port]
|
10
|
+
reset
|
11
|
+
end
|
12
|
+
|
8
13
|
def load folder
|
9
|
-
StubFactory.new.build folder
|
14
|
+
StubFactory.new.build folder
|
15
|
+
end
|
16
|
+
|
17
|
+
def reset
|
18
|
+
Stubs.reset
|
19
|
+
end
|
20
|
+
|
21
|
+
def stop
|
22
|
+
Server.stop
|
23
|
+
reset
|
10
24
|
end
|
11
25
|
|
12
26
|
def log_all_calls to_domain
|
13
|
-
|
14
|
-
|
15
|
-
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?}"
|
16
|
-
end
|
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?}"
|
17
29
|
end
|
18
30
|
end
|
19
31
|
end
|
@@ -1,2 +1 @@
|
|
1
|
-
|
2
|
-
port: "801"
|
1
|
+
sub_domain: "first"
|
@@ -1,2 +1 @@
|
|
1
|
-
|
2
|
-
port: "802"
|
1
|
+
sub_domain: "second"
|
data/spec/data/main/domain.yml
CHANGED
@@ -1,2 +1 @@
|
|
1
|
-
|
2
|
-
port: "80"
|
1
|
+
sub_domain: ""
|
@@ -2,13 +2,13 @@ describe Stub, "#key_value" do
|
|
2
2
|
|
3
3
|
it "partial dynamic request" do
|
4
4
|
Explicit.new.by_name("ram").build()
|
5
|
-
response = RestClient.post "http://localhost:
|
5
|
+
response = RestClient.post "http://localhost:3030/explicit","name=ram"
|
6
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
|
-
response = RestClient.post "http://localhost:
|
11
|
+
response = RestClient.post "http://localhost:3030/explicit","name=ram&age=11"
|
12
12
|
expect(response.body).to eq({"hi"=>1}.to_json)
|
13
13
|
end
|
14
14
|
|
@@ -2,19 +2,19 @@ describe Stub, "#key_value" do
|
|
2
2
|
|
3
3
|
it "default request" do
|
4
4
|
KeyValue.new.build()
|
5
|
-
response = RestClient.post "http://localhost:
|
5
|
+
response = RestClient.post "http://localhost:3030/keyvalue","name=sea&age=10"
|
6
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
|
-
response = RestClient.post "http://localhost:
|
11
|
+
response = RestClient.post "http://localhost:3030/keyvalue","name=ram&age=10"
|
12
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
|
-
response = RestClient.post "http://localhost:
|
17
|
+
response = RestClient.post "http://localhost:3030/keyvalue","name=ram&age=11"
|
18
18
|
expect(response.body).to eq({"hi"=>1}.to_json)
|
19
19
|
end
|
20
20
|
|
@@ -2,10 +2,10 @@ describe Stub, "#multi domain" do
|
|
2
2
|
|
3
3
|
it "support multi domain" do
|
4
4
|
First.new.build
|
5
|
-
response = RestClient.get "http://
|
5
|
+
response = RestClient.get "http://localhost:3030/first/first"
|
6
6
|
expect(response.body).to eq({"title"=>"1"}.to_json)
|
7
7
|
Second.new.build
|
8
|
-
response = RestClient.get "http://
|
8
|
+
response = RestClient.get "http://localhost:3030/second/second"
|
9
9
|
expect(response.body).to eq({"title"=>"1"}.to_json)
|
10
10
|
end
|
11
11
|
end
|
@@ -2,7 +2,7 @@ describe Stub, "#post_user" do
|
|
2
2
|
|
3
3
|
it "default request and response" do
|
4
4
|
User.new.build()
|
5
|
-
response = RestClient.post "http://localhost:
|
5
|
+
response = RestClient.post "http://localhost:3030/users",{"name"=>"deepak"}.to_json, :content_type => :json, :accept => :json
|
6
6
|
expect(response.body).to eq({"job"=>'sleeping_bag'}.to_json)
|
7
7
|
end
|
8
8
|
|
@@ -10,7 +10,7 @@ describe Stub, "#post_user" do
|
|
10
10
|
name = "ummy"
|
11
11
|
job = "vetti"
|
12
12
|
User.new.by_name(name).has_job(job).build()
|
13
|
-
response = RestClient.post "http://localhost:
|
13
|
+
response = RestClient.post "http://localhost:3030/users",{"name"=>name}.to_json, :content_type => :json, :accept => :json
|
14
14
|
expect(response.body).to eq({"job"=>job}.to_json)
|
15
15
|
end
|
16
16
|
|
@@ -2,19 +2,19 @@ describe Stub, "#query_explicit" do
|
|
2
2
|
|
3
3
|
it "partial" do
|
4
4
|
BookExplicit.new.for_author('bha').build()
|
5
|
-
response = RestClient.get "http://localhost:
|
5
|
+
response = RestClient.get "http://localhost:3030/book_explicit",{:params => {:author=>'bha'}}
|
6
6
|
expect(response.body).to eq({"title"=>"independance", "category"=>{"age_group"=>"10", "genre"=>"action", "publisher"=>{"name"=>"summa", "place"=>"erode"}}}.to_json)
|
7
7
|
end
|
8
8
|
|
9
9
|
it "full dymamic" do
|
10
10
|
Book.new.for_author('asd').for_name('don').build()
|
11
|
-
response = RestClient.get "http://localhost:
|
11
|
+
response = RestClient.get "http://localhost:3030/book",{:params => {:author=>'asd',:name=>'don'}}
|
12
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
|
it "full dymamic hash params" do
|
16
16
|
Book.new.for(:author => 'asd',:name =>'don').build
|
17
|
-
response = RestClient.get "http://localhost:
|
17
|
+
response = RestClient.get "http://localhost:3030/book",{:params => {:author=>'asd',:name=>'don'}}
|
18
18
|
expect(response.body).to eq({"title"=>"independance", "category"=>{"age_group"=>"10", "genre"=>"action", "publisher"=>{"name"=>"summa", "place"=>"erode"}}}.to_json)
|
19
19
|
end
|
20
20
|
|
@@ -2,19 +2,19 @@ describe Stub, "#implicit query params" do
|
|
2
2
|
|
3
3
|
it "dynamic response" do
|
4
4
|
Book.new.for_author("bha").has_category({"age_group"=>"11", "publisher"=>{"name"=>"oxford"}}).build()
|
5
|
-
response = RestClient.get "http://localhost:
|
5
|
+
response = RestClient.get "http://localhost:3030/book",{:params => {:author=>'bha',:name=>"doni"}}
|
6
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
|
-
response = RestClient.get "http://localhost:
|
11
|
+
response = RestClient.get "http://localhost:3030/book",{:params => {:author=>'bharathi',:name=>"doni"}}
|
12
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
|
it "hash params for query" do
|
16
16
|
Book.new.for(:author=>"val").build()
|
17
|
-
response = RestClient.get "http://localhost:
|
17
|
+
response = RestClient.get "http://localhost:3030/book",{:params => {:author=>'val',:name=>"doni"}}
|
18
18
|
expect(response.body).to eq({"title"=>"independance", "category"=>{"age_group"=>"10", "genre"=>"action", "publisher"=>{"name"=>"summa", "place"=>"erode"}}}.to_json)
|
19
19
|
end
|
20
20
|
|
@@ -2,49 +2,49 @@ describe Stub, "#array" do
|
|
2
2
|
|
3
3
|
it "empty column array" do
|
4
4
|
Columns.new.build
|
5
|
-
response = RestClient.get "http://localhost:
|
5
|
+
response = RestClient.get "http://localhost:3030/column"
|
6
6
|
expect(response.body).to eq("[]")
|
7
7
|
end
|
8
8
|
|
9
9
|
it "column array" do
|
10
10
|
Columns.new.has_column.has_column.with_title("abc").with_category(12).build
|
11
|
-
response = RestClient.get "http://localhost:
|
11
|
+
response = RestClient.get "http://localhost:3030/column"
|
12
12
|
expect(response.body).to eq({"title"=>["independance", "abc"], "category"=>["10",12]}.to_json)
|
13
13
|
end
|
14
14
|
|
15
15
|
it "column array hash params" do
|
16
16
|
Columns.new.has_column.has_column(:title=>"abc",:category => "12").build
|
17
|
-
response = RestClient.get "http://localhost:
|
17
|
+
response = RestClient.get "http://localhost:3030/column"
|
18
18
|
expect(response.body).to eq({"title"=>["independance", "abc"], "category"=>["10","12"]}.to_json)
|
19
19
|
end
|
20
20
|
|
21
21
|
it "column array full hash params" do
|
22
22
|
Columns.new.has_columns([{:title=>"abc"},{:title=>"c",:category => "1"}]).build
|
23
|
-
response = RestClient.get "http://localhost:
|
23
|
+
response = RestClient.get "http://localhost:3030/column"
|
24
24
|
expect(response.body).to eq({"title"=>["abc", "c"], "category"=>["10","1"]}.to_json)
|
25
25
|
end
|
26
26
|
|
27
27
|
it "empty row array" do
|
28
28
|
Rows.new.build
|
29
|
-
response = RestClient.get "http://localhost:
|
29
|
+
response = RestClient.get "http://localhost:3030/row"
|
30
30
|
expect(response.body).to eq("[]")
|
31
31
|
end
|
32
32
|
|
33
33
|
it "row array" do
|
34
34
|
Rows.new.has_row.with_item(3).has_row.with_title("abc").with_category("age_group" => "12").with_items([2,3]).build
|
35
|
-
response = RestClient.get "http://localhost:
|
35
|
+
response = RestClient.get "http://localhost:3030/row"
|
36
36
|
expect(response.body).to eq([{"title"=>"independance","items"=> [1,2,3],"category"=>{"age_group"=>"10"}}, {"title"=>"abc","items"=> [2,3],"category"=>{"age_group"=>"12"}}].to_json)
|
37
37
|
end
|
38
38
|
|
39
39
|
it "row array hash_params" do
|
40
40
|
Rows.new.has_row.has_row(:title=>"abc",:category=>{"age_group" => "12"}).build
|
41
|
-
response = RestClient.get "http://localhost:
|
41
|
+
response = RestClient.get "http://localhost:3030/row"
|
42
42
|
expect(response.body).to eq([{"title"=>"independance", "items"=> [1,2],"category"=>{"age_group"=>"10"}}, {"title"=>"abc", "items"=> [1,2],"category"=>{"age_group"=>"12"}}].to_json)
|
43
43
|
end
|
44
44
|
|
45
45
|
it "row array full hash_params" do
|
46
46
|
Rows.new.has_rows([{},{:title=>"abc",:category=>{"age_group" => "12"}}]).build
|
47
|
-
response = RestClient.get "http://localhost:
|
47
|
+
response = RestClient.get "http://localhost:3030/row"
|
48
48
|
expect(response.body).to eq([{"title"=>"independance", "items"=> [1,2],"category"=>{"age_group"=>"10"}}, {"title"=>"abc", "items"=> [1,2],"category"=>{"age_group"=>"12"}}].to_json)
|
49
49
|
end
|
50
50
|
|
@@ -2,7 +2,7 @@ describe Stub, "#dumb response" do
|
|
2
2
|
|
3
3
|
it "column array" do
|
4
4
|
Columns.new.set_dumb_response("spec/data/main/user/response.json").build
|
5
|
-
response = RestClient.get "http://localhost:
|
5
|
+
response = RestClient.get "http://localhost:3030/column"
|
6
6
|
expect(response.body).to eq({"job"=>"sleeping_bag"}.to_json)
|
7
7
|
end
|
8
8
|
|
@@ -1,19 +1,19 @@
|
|
1
1
|
describe StubInstance, "hash params" do
|
2
2
|
it "default" do
|
3
3
|
SimpleResponse.new.build
|
4
|
-
response = RestClient.get "http://localhost:
|
4
|
+
response = RestClient.get "http://localhost:3030/simple_response"
|
5
5
|
expect(response.body).to eq({:a=>1,:b=>2}.to_json)
|
6
6
|
end
|
7
7
|
|
8
8
|
it "partial" do
|
9
9
|
SimpleResponse.new.has(:a=>3).build
|
10
|
-
response = RestClient.get "http://localhost:
|
10
|
+
response = RestClient.get "http://localhost:3030/simple_response"
|
11
11
|
expect(response.body).to eq({:a=>3,:b=>2}.to_json)
|
12
12
|
end
|
13
13
|
|
14
14
|
it "full" do
|
15
15
|
SimpleResponse.new.has(:a=>3,:b=>5).build
|
16
|
-
response = RestClient.get "http://localhost:
|
16
|
+
response = RestClient.get "http://localhost:3030/simple_response"
|
17
17
|
expect(response.body).to eq({:a=>3,:b=>5}.to_json)
|
18
18
|
end
|
19
19
|
|
@@ -2,37 +2,37 @@ describe Stub, "#nested array" do
|
|
2
2
|
|
3
3
|
it "empty" do
|
4
4
|
NestedArray.new.has_no_role.build()
|
5
|
-
response = RestClient.get "http://localhost:
|
5
|
+
response = RestClient.get "http://localhost:3030/nested_array"
|
6
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
|
-
response = RestClient.get "http://localhost:
|
11
|
+
response = RestClient.get "http://localhost:3030/nested_array"
|
12
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
|
-
response = RestClient.get "http://localhost:
|
17
|
+
response = RestClient.get "http://localhost:3030/nested_array"
|
18
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
|
-
response = RestClient.get "http://localhost:
|
23
|
+
response = RestClient.get "http://localhost:3030/nested_array"
|
24
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
|
-
response = RestClient.get "http://localhost:
|
29
|
+
response = RestClient.get "http://localhost:3030/nested_array"
|
30
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
|
it "passing array of hashes" do
|
34
34
|
NestedArray.new.has_roles([{:role_id=>"test"},{:role_name=>"bla"}]).build()
|
35
|
-
response = RestClient.get "http://localhost:
|
35
|
+
response = RestClient.get "http://localhost:3030/nested_array"
|
36
36
|
expect(response.body).to eq({"title"=>"ind", "roles"=>[{"role_id"=>"test", "role_name"=>"sol"},{"role_id"=>"chumma", "role_name"=>"bla"}]}.to_json)
|
37
37
|
end
|
38
38
|
|
data/spec/functional/url_spec.rb
CHANGED
@@ -2,19 +2,19 @@ describe Stub, "#url" do
|
|
2
2
|
|
3
3
|
it "default" do
|
4
4
|
Url.new.build()
|
5
|
-
response = RestClient.get "http://localhost:
|
5
|
+
response = RestClient.get "http://localhost:3030/cda/cd/ragavan/get"
|
6
6
|
expect(response.body).to eq({"hi"=>1}.to_json)
|
7
7
|
end
|
8
8
|
|
9
9
|
it "dynamic" do
|
10
10
|
Url.new.of_name("hitler").of_actor("mani").build()
|
11
|
-
response = RestClient.get "http://localhost:
|
11
|
+
response = RestClient.get "http://localhost:3030/cda/hitler/mani/get"
|
12
12
|
expect(response.body).to eq({"hi"=>1}.to_json)
|
13
13
|
end
|
14
14
|
|
15
15
|
it "partial" do
|
16
16
|
Url.new.of_actor("mani").build()
|
17
|
-
response = RestClient.get "http://localhost:
|
17
|
+
response = RestClient.get "http://localhost:3030/cda/cd/mani/get"
|
18
18
|
expect(response.body).to eq({"hi"=>1}.to_json)
|
19
19
|
end
|
20
20
|
|
data/spec/spec_helper.rb
CHANGED
@@ -1,7 +1,5 @@
|
|
1
1
|
require "rspec/expectations"
|
2
2
|
require 'rest_client'
|
3
|
-
require 'webmock'
|
4
|
-
include WebMock::API
|
5
3
|
|
6
4
|
require_relative '../lib/poisol'
|
7
5
|
require 'pry'
|
@@ -16,15 +14,18 @@ SimpleCov.start
|
|
16
14
|
RSpec.configure do |config|
|
17
15
|
|
18
16
|
config.before(:each) do
|
19
|
-
|
17
|
+
Poisol.reset
|
20
18
|
end
|
21
19
|
|
22
20
|
config.before(:suite) do
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
21
|
+
Poisol.start
|
22
|
+
Poisol.load "spec/data/main/"
|
23
|
+
Poisol.load "spec/data/domain/first/"
|
24
|
+
Poisol.load "spec/data/domain/second/"
|
27
25
|
end
|
28
26
|
|
29
|
-
|
27
|
+
config.after(:suite) do
|
28
|
+
Poisol.stop
|
29
|
+
end
|
30
30
|
|
31
|
+
end
|
data/spec/unit/exception_spec.rb
CHANGED
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.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Deepak
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-01-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -81,7 +81,7 @@ dependencies:
|
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
|
-
name:
|
84
|
+
name: webrick
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
87
|
- - ">="
|
@@ -133,6 +133,8 @@ files:
|
|
133
133
|
- lib/poisol/domain.rb
|
134
134
|
- lib/poisol/extensions/hash.rb
|
135
135
|
- lib/poisol/extensions/webmock_extensions.rb
|
136
|
+
- lib/poisol/response_mapper.rb
|
137
|
+
- lib/poisol/server.rb
|
136
138
|
- lib/poisol/stub/request/query_builder.rb
|
137
139
|
- lib/poisol/stub/request/request_body_builder.rb
|
138
140
|
- lib/poisol/stub/request/url_builder.rb
|
@@ -141,10 +143,11 @@ files:
|
|
141
143
|
- lib/poisol/stub/stub.rb
|
142
144
|
- lib/poisol/stub/stub_class_builder.rb
|
143
145
|
- lib/poisol/stub/stub_instance.rb
|
144
|
-
- lib/poisol/stub/
|
146
|
+
- lib/poisol/stub/webrick_stub_builder.rb
|
145
147
|
- lib/poisol/stub_config/stub_config.rb
|
146
148
|
- lib/poisol/stub_config/stub_config_builder.rb
|
147
149
|
- lib/poisol/stub_factory.rb
|
150
|
+
- lib/poisol/stubs.rb
|
148
151
|
- lib/poisol/utils/file_util.rb
|
149
152
|
- lib/poisol/utils/logger.rb
|
150
153
|
- lib/poisol/utils/parse.rb
|