contracto 0.3.3 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/contracto/command/start/remote.rb +1 -1
- data/lib/contracto/constants.rb +5 -0
- data/lib/contracto/server/ruby/server.rb +4 -3
- data/lib/contracto/system_action.rb +8 -11
- data/lib/contracto/version.rb +1 -1
- data/script/send_test_requests.sh +2 -0
- data/script/start_from_remote.sh +3 -3
- data/script/start_locally.sh +3 -0
- data/{lib/contracto/server/ruby/contract.con.json → spec/fixtures/posts.con.json} +3 -21
- data/spec/fixtures/users/1/posts.json +7 -0
- data/spec/fixtures/users/1.json +1 -0
- data/spec/fixtures/users/2/posts.json +7 -0
- data/spec/fixtures/users/2.json +1 -0
- metadata +9 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 539e08faf6ec2176f82085c557bf154af64ef392
|
4
|
+
data.tar.gz: e229d835ff7227b6a154261f33bd9f8a5e108dea
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 42861847062ba686ec7bf2f1119d53bbb054b8292cc5fd79c51e203c922c4762a04c8354cebf7ba275c7dcad174a67cfd2c81870c8cd2acf7d405d1b4ac7aff8
|
7
|
+
data.tar.gz: 73a5d1e7bc398c71e55862cb67222872a9a158c9a43a379c2d934990abf48fda3c81be107d5a2874b836570bf66bb3057bbd17c589c190acfd083025d4136f8f
|
data/lib/contracto/constants.rb
CHANGED
@@ -7,6 +7,7 @@ module Contracto::Constants
|
|
7
7
|
CONTRACTO_TMP_DIR = '.tmp.contracto'
|
8
8
|
RUBY_SERVER_DIR = "#{GEM_DIR}/lib/contracto/server/ruby"
|
9
9
|
CONTRACT_FILENAME = 'contract.con.json'
|
10
|
+
SAMPLE_CONTRACT_DIR = "#{GEM_DIR}/spec/fixtures"
|
10
11
|
CONTRACT_PID_FILEPATH = "#{ROOT_DIR}/server.pid"
|
11
12
|
PORT = 54321
|
12
13
|
|
@@ -30,6 +31,10 @@ module Contracto::Constants
|
|
30
31
|
RUBY_SERVER_DIR
|
31
32
|
end
|
32
33
|
|
34
|
+
def sample_contract_dir
|
35
|
+
SAMPLE_CONTRACT_DIR
|
36
|
+
end
|
37
|
+
|
33
38
|
def contract_filename
|
34
39
|
CONTRACT_FILENAME
|
35
40
|
end
|
@@ -5,10 +5,11 @@ get '/contracto' do
|
|
5
5
|
"*** Contracto server is working! [#{Gem::Specification.find_by_name('contracto').version}] ***"
|
6
6
|
end
|
7
7
|
|
8
|
-
|
9
|
-
|
8
|
+
jsons_with_contracts = Dir["#{Contracto::Constants::ROOT_DIR}/**/*.con.json"].map do |file_with_contract|
|
9
|
+
File.read file_with_contract
|
10
|
+
end
|
10
11
|
|
11
|
-
Contracto::Parser.new(
|
12
|
+
Contracto::Parser.new(jsons_with_contracts).contracts.each do |contract|
|
12
13
|
send(contract.http_method, contract.url_pattern) do
|
13
14
|
contract.response_body(params)
|
14
15
|
end
|
@@ -4,10 +4,6 @@ class Contracto::SystemAction
|
|
4
4
|
class << self
|
5
5
|
include Contracto::Constants
|
6
6
|
|
7
|
-
def remove_contracto_dir
|
8
|
-
FileUtils.rm_rf contracto_dir
|
9
|
-
end
|
10
|
-
|
11
7
|
def remove_tmp_contracto_dir
|
12
8
|
FileUtils.rm_rf contracto_tmp_dir
|
13
9
|
end
|
@@ -16,7 +12,8 @@ class Contracto::SystemAction
|
|
16
12
|
if contract_already_exists?
|
17
13
|
puts 'contract already exists, creating sample contract skipped'
|
18
14
|
else
|
19
|
-
FileUtils.
|
15
|
+
FileUtils.cp_r sample_contract_dir, contracto_tmp_dir
|
16
|
+
move_tmp_dir_files_to_root_dir
|
20
17
|
puts "created: #{contract_filename}"
|
21
18
|
end
|
22
19
|
end
|
@@ -52,18 +49,18 @@ class Contracto::SystemAction
|
|
52
49
|
remove_tmp_contracto_dir
|
53
50
|
end
|
54
51
|
|
55
|
-
def
|
56
|
-
|
52
|
+
def move_tmp_dir_files_to_root_dir
|
53
|
+
move_dir_files_to_root_dir(contracto_tmp_dir)
|
57
54
|
end
|
58
55
|
|
59
56
|
private
|
60
57
|
|
61
|
-
def
|
62
|
-
|
58
|
+
def move_dir_files_to_root_dir(dir)
|
59
|
+
system "mv #{dir}/* #{dir}/.[^.]* . 2> /dev/null" # Could not use FileUtils for some reason
|
63
60
|
end
|
64
61
|
|
65
|
-
def
|
66
|
-
"#{
|
62
|
+
def contract_already_exists?
|
63
|
+
File.exist?("#{root_dir}/#{contract_filename}")
|
67
64
|
end
|
68
65
|
|
69
66
|
def server_already_running?
|
data/lib/contracto/version.rb
CHANGED
data/script/start_from_remote.sh
CHANGED
@@ -3,9 +3,9 @@ rm -rf tmp
|
|
3
3
|
mkdir tmp
|
4
4
|
cd tmp
|
5
5
|
contracto start git@github.com:kv109/contracto_sample-contract.git
|
6
|
-
|
7
|
-
|
8
|
-
|
6
|
+
../send_test_requests.sh
|
7
|
+
contracto stop
|
8
|
+
contracto start
|
9
9
|
contracto stop
|
10
10
|
cd ..
|
11
11
|
rm -rf tmp
|
data/script/start_locally.sh
CHANGED
@@ -2,25 +2,7 @@
|
|
2
2
|
{
|
3
3
|
"request": {
|
4
4
|
"http_method": "get",
|
5
|
-
"path": "/users"
|
6
|
-
},
|
7
|
-
"responses": [
|
8
|
-
{
|
9
|
-
"request": {
|
10
|
-
"headers": {
|
11
|
-
"Content-Type": "application/json"
|
12
|
-
}
|
13
|
-
},
|
14
|
-
"response": {
|
15
|
-
"body_path": "/users.json"
|
16
|
-
}
|
17
|
-
}
|
18
|
-
]
|
19
|
-
},
|
20
|
-
{
|
21
|
-
"request": {
|
22
|
-
"http_method": "get",
|
23
|
-
"path": "/users/:id"
|
5
|
+
"path": "/users/:id/posts"
|
24
6
|
},
|
25
7
|
"responses": [
|
26
8
|
{
|
@@ -33,7 +15,7 @@
|
|
33
15
|
}
|
34
16
|
},
|
35
17
|
"response": {
|
36
|
-
"body_path": "/users/1.json"
|
18
|
+
"body_path": "/users/1/posts.json"
|
37
19
|
}
|
38
20
|
},
|
39
21
|
{
|
@@ -46,7 +28,7 @@
|
|
46
28
|
}
|
47
29
|
},
|
48
30
|
"response": {
|
49
|
-
"body_path": "/users/2.json"
|
31
|
+
"body_path": "/users/2/posts.json"
|
50
32
|
}
|
51
33
|
}
|
52
34
|
]
|
data/spec/fixtures/users/1.json
CHANGED
data/spec/fixtures/users/2.json
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: contracto
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kacper Walanus
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-04-
|
11
|
+
date: 2015-04-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sinatra
|
@@ -95,17 +95,20 @@ files:
|
|
95
95
|
- lib/contracto/errors.rb
|
96
96
|
- lib/contracto/parser.rb
|
97
97
|
- lib/contracto/server/ruby/config.ru
|
98
|
-
- lib/contracto/server/ruby/contract.con.json
|
99
98
|
- lib/contracto/server/ruby/server.rb
|
100
99
|
- lib/contracto/system_action.rb
|
101
100
|
- lib/contracto/system_action_chain.rb
|
102
101
|
- lib/contracto/version.rb
|
102
|
+
- script/send_test_requests.sh
|
103
103
|
- script/start_from_remote.sh
|
104
104
|
- script/start_locally.sh
|
105
105
|
- spec/fixtures/contract.con.json
|
106
|
+
- spec/fixtures/posts.con.json
|
106
107
|
- spec/fixtures/users.json
|
107
108
|
- spec/fixtures/users/1.json
|
109
|
+
- spec/fixtures/users/1/posts.json
|
108
110
|
- spec/fixtures/users/2.json
|
111
|
+
- spec/fixtures/users/2/posts.json
|
109
112
|
- spec/spec_helper.rb
|
110
113
|
- spec/unit/contract_spec.rb
|
111
114
|
- spec/unit/parser_spec.rb
|
@@ -135,9 +138,12 @@ specification_version: 4
|
|
135
138
|
summary: XXX
|
136
139
|
test_files:
|
137
140
|
- spec/fixtures/contract.con.json
|
141
|
+
- spec/fixtures/posts.con.json
|
138
142
|
- spec/fixtures/users.json
|
139
143
|
- spec/fixtures/users/1.json
|
144
|
+
- spec/fixtures/users/1/posts.json
|
140
145
|
- spec/fixtures/users/2.json
|
146
|
+
- spec/fixtures/users/2/posts.json
|
141
147
|
- spec/spec_helper.rb
|
142
148
|
- spec/unit/contract_spec.rb
|
143
149
|
- spec/unit/parser_spec.rb
|