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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a01da4681838d0f188cd20228bd42200833142c4
4
- data.tar.gz: dbaaf04e0c3527125b236508b471e00ea7341d14
3
+ metadata.gz: edf170bc3055b6d07143821280feb345d918dcd2
4
+ data.tar.gz: b12accb1f9fdafdce5f3ec05317fefe391f6d383
5
5
  SHA512:
6
- metadata.gz: 2c1a3c2ec6b68d5263df13ec4e9ac598e72aedc63dccae7859576c5eb066a605bd92b1e9ec58575eb8ceaffe6d1847e03fe0b1b27665dee9efc888bfa2c7941b
7
- data.tar.gz: 1d8e16d382bc4c92b09cebd3e2683538cb2ef42a2b2d8da44652b69ca6573a56e6c865541ca05f9da31e5ca3018b43ec78beb20f8c609c5cb7a6888ad1fbff22
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
- TODO: Write a gem description
5
+ Creates HTTP server based on your contract.
4
6
 
5
7
  ## Installation
8
+
9
+ $ gem install contracto
10
+
11
+ ## Usage
6
12
 
7
- Add this line to your application's Gemfile:
13
+ Start server:
8
14
 
9
- ```ruby
10
- gem 'contracto'
11
- ```
15
+ $ contracto start git@github.com:kv109/contracto_sample-contract.git
16
+
17
+ Test server (default port is __54321__):
12
18
 
13
- And then execute:
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
- $ bundle
23
+ $ contracto stop
16
24
 
17
- Or install it yourself as:
25
+ ## How to write contract
18
26
 
19
- $ gem install contracto
27
+ See [documentation](https://github.com/kv109/contracto_sample-contract).
20
28
 
21
- ## Usage
29
+ ## About consumer-driven contracts pattern
22
30
 
23
- TODO: Write usage instructions here
31
+ http://martinfowler.com/articles/consumerDrivenContracts.html
24
32
 
25
33
  ## Contributing
26
34
 
@@ -16,8 +16,6 @@ class Contracto::Command::Init
16
16
 
17
17
  def actions
18
18
  [
19
- :remove_contracto_dir,
20
- :copy_server_files,
21
19
  :create_sample_contract
22
20
  ]
23
21
  end
@@ -15,7 +15,6 @@ class Contracto::Command::Start::Remote
15
15
  :clone_repo_to_tmp_contracto_dir,
16
16
  :move_repo_files_to_root_dir,
17
17
  :remove_tmp_contracto_dir,
18
- :copy_server_files,
19
18
  :start_server
20
19
  ]
21
20
  end
@@ -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 = "#{CONTRACTO_DIR}/server.pid"
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
- File.read(root_dir + body_path)
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
- "examples": [
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
- "body": {}
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
- "examples": [
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
- "body": {
36
- "firstName": "Max",
37
- "lastName": "Lincoln"
44
+ "params": {
45
+ "id": 2
38
46
  }
39
47
  },
40
48
  "response": {
41
- "body": {}
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.mv sample_contract_path, FileUtils.pwd
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 #{contracto_dir}/config.ru -p #{port} -D -P #{contract_pid_filepath}"
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
- "#{contracto_dir}/#{contract_filename}"
66
+ "#{ruby_server_dir}/#{contract_filename}"
82
67
  end
83
68
 
84
69
  def server_already_running?
@@ -1,3 +1,3 @@
1
1
  module Contracto
2
- VERSION = '0.3.1'
2
+ VERSION = '0.3.2'
3
3
  end
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.1
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-03-29 00:00:00.000000000 Z
11
+ date: 2015-04-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sinatra