contracto 0.3.3 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4465406c89d2015abf010adcff9b249a3037dbaa
4
- data.tar.gz: ae6b062c639841a4ac51b6a171acab7cb679ed9f
3
+ metadata.gz: 539e08faf6ec2176f82085c557bf154af64ef392
4
+ data.tar.gz: e229d835ff7227b6a154261f33bd9f8a5e108dea
5
5
  SHA512:
6
- metadata.gz: 003e9b8e2671be644d878e4aa463978863bab5249db1559b7317a5237de803a73ce496e59b4c264b98bb92116c64db5e26efa081a8fe183e00b413f197eb82d4
7
- data.tar.gz: 60d73c833de3fdc617911684bca8ab308d894a42fc5535c2a84be133c8e69d101f9164d4701247bc85eae465742e4e7d4b129227cad07f8bac66d7a36931dd46
6
+ metadata.gz: 42861847062ba686ec7bf2f1119d53bbb054b8292cc5fd79c51e203c922c4762a04c8354cebf7ba275c7dcad174a67cfd2c81870c8cd2acf7d405d1b4ac7aff8
7
+ data.tar.gz: 73a5d1e7bc398c71e55862cb67222872a9a158c9a43a379c2d934990abf48fda3c81be107d5a2874b836570bf66bb3057bbd17c589c190acfd083025d4136f8f
@@ -13,7 +13,7 @@ class Contracto::Command::Start::Remote
13
13
  def actions
14
14
  [
15
15
  :clone_repo_to_tmp_contracto_dir,
16
- :move_repo_files_to_root_dir,
16
+ :move_tmp_dir_files_to_root_dir,
17
17
  :remove_tmp_contracto_dir,
18
18
  :start_server
19
19
  ]
@@ -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
- json_string = File.read Contracto::Constants::CONTRACT_FILENAME
9
- json_strings = [json_string]
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(json_strings).contracts.each do |contract|
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.cp sample_contract_path, FileUtils.pwd
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 move_repo_files_to_root_dir
56
- system "mv #{contracto_tmp_dir}/* #{contracto_tmp_dir}/.[^.]* . 2> /dev/null" # Could not use FileUtils for some reason
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 contract_already_exists?
62
- File.exist?("#{root_dir}/#{contract_filename}")
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 sample_contract_path
66
- "#{ruby_server_dir}/#{contract_filename}"
62
+ def contract_already_exists?
63
+ File.exist?("#{root_dir}/#{contract_filename}")
67
64
  end
68
65
 
69
66
  def server_already_running?
@@ -1,3 +1,3 @@
1
1
  module Contracto
2
- VERSION = '0.3.3'
2
+ VERSION = '0.4.0'
3
3
  end
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env bash
2
+ for path in users users/1 users/2 users/1/posts users/2/posts; do curl 0.0.0.0:54321/$path; done
@@ -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
- curl 0.0.0.0:54321/users
7
- curl 0.0.0.0:54321/users/1
8
- curl 0.0.0.0:54321/users/2
6
+ ../send_test_requests.sh
7
+ contracto stop
8
+ contracto start
9
9
  contracto stop
10
10
  cd ..
11
11
  rm -rf tmp
@@ -4,6 +4,9 @@ mkdir tmp
4
4
  cd tmp
5
5
  contracto init
6
6
  contracto start
7
+ ../send_test_requests.sh
8
+ contracto stop
9
+ contracto start
7
10
  contracto stop
8
11
  cd ..
9
12
  rm -rf tmp
@@ -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
  ]
@@ -0,0 +1,7 @@
1
+ [
2
+ {
3
+ "id": 1,
4
+ "title": "When I got home",
5
+ "content": "I killed my wife"
6
+ }
7
+ ]
@@ -1,4 +1,5 @@
1
1
  {
2
+ "id": :id,
2
3
  "first_name": "Albert",
3
4
  "last_name": "Einstein",
4
5
  "age": 30
@@ -0,0 +1,7 @@
1
+ [
2
+ {
3
+ "id": 5,
4
+ "title": "I had fun once",
5
+ "content": "It was awful"
6
+ }
7
+ ]
@@ -1,4 +1,5 @@
1
1
  {
2
+ "id": :id,
2
3
  "first_name": "Kurt",
3
4
  "last_name": "Godel",
4
5
  "age": 35
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.3
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-10 00:00:00.000000000 Z
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