contracto 0.3.1 → 0.3.2
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/README.md +19 -11
- data/lib/contracto/command/init.rb +0 -2
- data/lib/contracto/command/start/remote.rb +0 -1
- data/lib/contracto/constants.rb +1 -1
- data/lib/contracto/contract/response.rb +16 -1
- data/lib/contracto/server/ruby/contract.con.json +19 -11
- data/lib/contracto/system_action.rb +4 -19
- data/lib/contracto/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: edf170bc3055b6d07143821280feb345d918dcd2
|
4
|
+
data.tar.gz: b12accb1f9fdafdce5f3ec05317fefe391f6d383
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 07fb46243e80a4bc8995624451200d75a66081dbfe9ec2f4463a1984bab9ec2875dafb25367489dafeda1006eac18ea6166a42b132302f08e8a22dcd0eb1a357
|
7
|
+
data.tar.gz: 3d8c554626d42f8d279a12b8126d47602c3e9487b44386648482034ba8dbf6054856ecae3fe57db8dcb3d9d2c127d0a73614b02056ddbb0ba38512889e562519
|
data/README.md
CHANGED
@@ -1,26 +1,34 @@
|
|
1
|
+
# IN DEVELOPMENT
|
2
|
+
|
1
3
|
# Contracto
|
2
4
|
|
3
|
-
|
5
|
+
Creates HTTP server based on your contract.
|
4
6
|
|
5
7
|
## Installation
|
8
|
+
|
9
|
+
$ gem install contracto
|
10
|
+
|
11
|
+
## Usage
|
6
12
|
|
7
|
-
|
13
|
+
Start server:
|
8
14
|
|
9
|
-
|
10
|
-
|
11
|
-
|
15
|
+
$ contracto start git@github.com:kv109/contracto_sample-contract.git
|
16
|
+
|
17
|
+
Test server (default port is __54321__):
|
12
18
|
|
13
|
-
|
19
|
+
$ curl 0.0.0.0:54321/users; curl 0.0.0.0:54321/users/1; curl 0.0.0.0:54321/users/2
|
20
|
+
|
21
|
+
Stop server:
|
14
22
|
|
15
|
-
$
|
23
|
+
$ contracto stop
|
16
24
|
|
17
|
-
|
25
|
+
## How to write contract
|
18
26
|
|
19
|
-
|
27
|
+
See [documentation](https://github.com/kv109/contracto_sample-contract).
|
20
28
|
|
21
|
-
##
|
29
|
+
## About consumer-driven contracts pattern
|
22
30
|
|
23
|
-
|
31
|
+
http://martinfowler.com/articles/consumerDrivenContracts.html
|
24
32
|
|
25
33
|
## Contributing
|
26
34
|
|
data/lib/contracto/constants.rb
CHANGED
@@ -7,7 +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
|
-
CONTRACT_PID_FILEPATH = "#{
|
10
|
+
CONTRACT_PID_FILEPATH = "#{ROOT_DIR}/server.pid"
|
11
11
|
PORT = 54321
|
12
12
|
|
13
13
|
def gem_dir
|
@@ -23,6 +23,21 @@ class Contracto::Contract::Response
|
|
23
23
|
end
|
24
24
|
|
25
25
|
def body
|
26
|
-
|
26
|
+
set_body
|
27
|
+
@body.tap do
|
28
|
+
replace_params_placeholders_with_params_value
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def set_body
|
35
|
+
@body = File.read(root_dir + body_path)
|
36
|
+
end
|
37
|
+
|
38
|
+
def replace_params_placeholders_with_params_value
|
39
|
+
params.each do |key, value|
|
40
|
+
@body.gsub!(":#{key}", value.to_s) if value
|
41
|
+
end
|
27
42
|
end
|
28
43
|
end
|
@@ -4,19 +4,15 @@
|
|
4
4
|
"http_method": "get",
|
5
5
|
"path": "/users"
|
6
6
|
},
|
7
|
-
"
|
7
|
+
"responses": [
|
8
8
|
{
|
9
9
|
"request": {
|
10
10
|
"headers": {
|
11
11
|
"Content-Type": "application/json"
|
12
|
-
},
|
13
|
-
"body": {
|
14
|
-
"firstName": "Max",
|
15
|
-
"lastName": "Lincoln"
|
16
12
|
}
|
17
13
|
},
|
18
14
|
"response": {
|
19
|
-
"
|
15
|
+
"body_path": "/users.json"
|
20
16
|
}
|
21
17
|
}
|
22
18
|
]
|
@@ -26,19 +22,31 @@
|
|
26
22
|
"http_method": "get",
|
27
23
|
"path": "/users/:id"
|
28
24
|
},
|
29
|
-
"
|
25
|
+
"responses": [
|
26
|
+
{
|
27
|
+
"request": {
|
28
|
+
"headers": {
|
29
|
+
"Content-Type": "application/json"
|
30
|
+
},
|
31
|
+
"params": {
|
32
|
+
"id": 1
|
33
|
+
}
|
34
|
+
},
|
35
|
+
"response": {
|
36
|
+
"body_path": "/users/1.json"
|
37
|
+
}
|
38
|
+
},
|
30
39
|
{
|
31
40
|
"request": {
|
32
41
|
"headers": {
|
33
42
|
"Content-Type": "application/json"
|
34
43
|
},
|
35
|
-
"
|
36
|
-
"
|
37
|
-
"lastName": "Lincoln"
|
44
|
+
"params": {
|
45
|
+
"id": 2
|
38
46
|
}
|
39
47
|
},
|
40
48
|
"response": {
|
41
|
-
"
|
49
|
+
"body_path": "/users/2.json"
|
42
50
|
}
|
43
51
|
}
|
44
52
|
]
|
@@ -12,22 +12,11 @@ class Contracto::SystemAction
|
|
12
12
|
FileUtils.rm_rf contracto_tmp_dir
|
13
13
|
end
|
14
14
|
|
15
|
-
def copy_server_files
|
16
|
-
FileUtils.cp_r ruby_server_dir, contracto_tmp_dir
|
17
|
-
FileUtils.mv contracto_tmp_dir, contracto_dir
|
18
|
-
end
|
19
|
-
|
20
|
-
def revert_copy_server_files
|
21
|
-
remove_contracto_dir
|
22
|
-
remove_tmp_contracto_dir
|
23
|
-
end
|
24
|
-
|
25
15
|
def create_sample_contract
|
26
16
|
if contract_already_exists?
|
27
17
|
puts 'contract already exists, creating sample contract skipped'
|
28
|
-
remove_sample_contract
|
29
18
|
else
|
30
|
-
FileUtils.
|
19
|
+
FileUtils.cp sample_contract_path, FileUtils.pwd
|
31
20
|
puts "created: #{contract_filename}"
|
32
21
|
end
|
33
22
|
end
|
@@ -35,7 +24,7 @@ class Contracto::SystemAction
|
|
35
24
|
def start_server
|
36
25
|
raise Contracto::ServerAlreadyRunningError if server_already_running?
|
37
26
|
|
38
|
-
system "rackup #{
|
27
|
+
system "rackup #{ruby_server_dir}/config.ru -p #{port} -D -P #{contract_pid_filepath}"
|
39
28
|
# TODO: loop below should terminate after n tries
|
40
29
|
system "while ! echo exit | nc localhost #{port} > /dev/null && echo \"waiting for contracto server...\"; do sleep 1; done"
|
41
30
|
test_request
|
@@ -70,15 +59,11 @@ class Contracto::SystemAction
|
|
70
59
|
private
|
71
60
|
|
72
61
|
def contract_already_exists?
|
73
|
-
File.exist?(contract_filename)
|
74
|
-
end
|
75
|
-
|
76
|
-
def remove_sample_contract
|
77
|
-
FileUtils.rm sample_contract_path
|
62
|
+
File.exist?("#{root_dir}/#{contract_filename}")
|
78
63
|
end
|
79
64
|
|
80
65
|
def sample_contract_path
|
81
|
-
"#{
|
66
|
+
"#{ruby_server_dir}/#{contract_filename}"
|
82
67
|
end
|
83
68
|
|
84
69
|
def server_already_running?
|
data/lib/contracto/version.rb
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.3.
|
4
|
+
version: 0.3.2
|
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-
|
11
|
+
date: 2015-04-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sinatra
|