pacto 0.2.0 → 0.2.1
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.
- data/.rspec +2 -0
- data/.rspec_integration +4 -0
- data/Rakefile +11 -2
- data/lib/pacto.rb +2 -5
- data/lib/pacto/contract_factory.rb +11 -0
- data/lib/pacto/version.rb +1 -1
- data/spec/integration/data/simple_contract.json +25 -0
- data/spec/integration/e2e_spec.rb +26 -0
- data/spec/integration/spec_helper.rb +1 -0
- data/spec/integration/utils/dummy_server.rb +34 -0
- data/spec/spec_helper.rb +0 -3
- data/spec/{data → unit/data}/contract.json +0 -0
- data/spec/unit/pacto/contract_factory_spec.rb +22 -0
- data/spec/{pacto → unit/pacto}/contract_spec.rb +0 -0
- data/spec/{pacto → unit/pacto}/extensions_spec.rb +0 -0
- data/spec/{pacto → unit/pacto}/file_pre_processor_spec.rb +0 -0
- data/spec/{pacto → unit/pacto}/instantiated_contract_spec.rb +0 -0
- data/spec/{pacto → unit/pacto}/pacto_spec.rb +12 -13
- data/spec/{pacto → unit/pacto}/request_spec.rb +0 -0
- data/spec/{pacto → unit/pacto}/response_adapter_spec.rb +0 -0
- data/spec/{pacto → unit/pacto}/response_spec.rb +0 -0
- data/spec/unit/spec_helper.rb +2 -0
- metadata +34 -20
data/.rspec
CHANGED
data/.rspec_integration
ADDED
data/Rakefile
CHANGED
@@ -2,6 +2,15 @@ require "bundler/gem_tasks"
|
|
2
2
|
require 'rspec/core/rake_task'
|
3
3
|
|
4
4
|
if defined?(RSpec)
|
5
|
-
|
6
|
-
task :
|
5
|
+
desc "Run unit tests"
|
6
|
+
task :spec do
|
7
|
+
abort unless system('rspec --option .rspec')
|
8
|
+
end
|
9
|
+
|
10
|
+
desc "Run integration tests"
|
11
|
+
task :integration do
|
12
|
+
abort unless system('rspec --option .rspec_integration')
|
13
|
+
end
|
14
|
+
|
15
|
+
task :default => [:spec, :integration]
|
7
16
|
end
|
data/lib/pacto.rb
CHANGED
@@ -15,15 +15,12 @@ require "pacto/response_adapter"
|
|
15
15
|
require "pacto/response"
|
16
16
|
require "pacto/instantiated_contract"
|
17
17
|
require "pacto/contract"
|
18
|
+
require "pacto/contract_factory"
|
18
19
|
require "pacto/file_pre_processor"
|
19
20
|
|
20
21
|
module Pacto
|
21
22
|
def self.build_from_file(contract_path, host, file_pre_processor=FilePreProcessor.new)
|
22
|
-
|
23
|
-
definition = JSON.parse(contract_definition_expanded)
|
24
|
-
request = Request.new(host, definition["request"])
|
25
|
-
response = Response.new(definition["response"])
|
26
|
-
Contract.new(request, response)
|
23
|
+
ContractFactory.build_from_file(contract_path, host, file_pre_processor)
|
27
24
|
end
|
28
25
|
|
29
26
|
def self.register(name, contract)
|
@@ -0,0 +1,11 @@
|
|
1
|
+
module Pacto
|
2
|
+
class ContractFactory
|
3
|
+
def self.build_from_file(contract_path, host, file_pre_processor)
|
4
|
+
contract_definition_expanded = file_pre_processor.process(File.read(contract_path))
|
5
|
+
definition = JSON.parse(contract_definition_expanded)
|
6
|
+
request = Request.new(host, definition["request"])
|
7
|
+
response = Response.new(definition["response"])
|
8
|
+
Contract.new(request, response)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
data/lib/pacto/version.rb
CHANGED
@@ -0,0 +1,25 @@
|
|
1
|
+
{
|
2
|
+
"request": {
|
3
|
+
"method": "GET",
|
4
|
+
"path": "/simple_contract.json",
|
5
|
+
"headers": {
|
6
|
+
"Accept": "application/json"
|
7
|
+
},
|
8
|
+
"params": {}
|
9
|
+
},
|
10
|
+
|
11
|
+
"response": {
|
12
|
+
"status": 200,
|
13
|
+
"headers": {
|
14
|
+
"Content-Type": "application/json"
|
15
|
+
},
|
16
|
+
"body": {
|
17
|
+
"type": "object",
|
18
|
+
"properties": {
|
19
|
+
"message": {
|
20
|
+
"type": "string"
|
21
|
+
}
|
22
|
+
}
|
23
|
+
}
|
24
|
+
}
|
25
|
+
}
|
@@ -0,0 +1,26 @@
|
|
1
|
+
describe "Pacto" do
|
2
|
+
before :all do
|
3
|
+
@server = DummyServer.new
|
4
|
+
@server.start
|
5
|
+
end
|
6
|
+
|
7
|
+
after :all do
|
8
|
+
@server.terminate
|
9
|
+
end
|
10
|
+
|
11
|
+
let(:contract_path) { 'spec/integration/data/simple_contract.json' }
|
12
|
+
let(:end_point_address) { 'http://localhost:8000' }
|
13
|
+
|
14
|
+
it "validates a contract against a server" do
|
15
|
+
WebMock.allow_net_connect!
|
16
|
+
contract = Pacto.build_from_file(contract_path, end_point_address)
|
17
|
+
contract.validate.should == []
|
18
|
+
end
|
19
|
+
|
20
|
+
pending "generates a mocked response based on a contract specification" do
|
21
|
+
contract = Pacto.build_from_file(contract_path, end_point_address)
|
22
|
+
Pacto.register('my_contract', contract)
|
23
|
+
Pacto.use('my_contract')
|
24
|
+
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require_relative 'utils/dummy_server'
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'webrick'
|
2
|
+
|
3
|
+
class Servlet < WEBrick::HTTPServlet::AbstractServlet
|
4
|
+
def initialize(server, json)
|
5
|
+
super(server)
|
6
|
+
@json = json
|
7
|
+
end
|
8
|
+
|
9
|
+
def do_GET(request, response)
|
10
|
+
response.status = 200
|
11
|
+
response['Content-Type'] = 'application/json'
|
12
|
+
response.body = @json
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
class DummyServer
|
17
|
+
def initialize
|
18
|
+
@server = WEBrick::HTTPServer.new :Port => 8000,
|
19
|
+
:AccessLog => [],
|
20
|
+
:Logger => WEBrick::Log::new("/dev/null", 7)
|
21
|
+
@server.mount "/simple_contract.json", Servlet, '{"message": "Hello World!"}'
|
22
|
+
end
|
23
|
+
|
24
|
+
def start
|
25
|
+
@pid = fork do
|
26
|
+
trap 'INT' do @server.shutdown end
|
27
|
+
@server.start
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def terminate
|
32
|
+
Process.kill('INT', @pid)
|
33
|
+
end
|
34
|
+
end
|
data/spec/spec_helper.rb
CHANGED
File without changes
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module Pacto
|
2
|
+
describe ContractFactory do
|
3
|
+
let(:host) { 'http://localhost' }
|
4
|
+
let(:contract_name) { 'contract' }
|
5
|
+
let(:contract_path) { File.join('spec', 'unit', 'data', "#{contract_name}.json") }
|
6
|
+
let(:file_pre_processor) { double('file_pre_processor') }
|
7
|
+
let(:file_content) { File.read(contract_path)}
|
8
|
+
|
9
|
+
describe '.build_from_file' do
|
10
|
+
it 'should build a contract given a JSON file path and a host' do
|
11
|
+
file_pre_processor.stub(:process).and_return(file_content)
|
12
|
+
described_class.build_from_file(contract_path, host, file_pre_processor).
|
13
|
+
should be_a_kind_of(Pacto::Contract)
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'should process files using File Pre Processor module' do
|
17
|
+
file_pre_processor.should_receive(:process).with(file_content).and_return(file_content)
|
18
|
+
described_class.build_from_file(contract_path, host, file_pre_processor)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -1,5 +1,4 @@
|
|
1
1
|
describe Pacto do
|
2
|
-
let(:host) { 'http://localhost' }
|
3
2
|
let(:contract_name) { 'contract' }
|
4
3
|
let(:contract) { double('contract') }
|
5
4
|
|
@@ -24,19 +23,19 @@ describe Pacto do
|
|
24
23
|
end
|
25
24
|
|
26
25
|
describe '.build_from_file' do
|
27
|
-
let(:
|
28
|
-
let(:
|
29
|
-
let(:
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
26
|
+
let(:path) { 'contract/path' }
|
27
|
+
let(:host) { 'http://localhost' }
|
28
|
+
let(:file_pre_processor) { double('file_pre_processor') }
|
29
|
+
let(:instantiated_contract) { double(:instantiated_contract) }
|
30
|
+
|
31
|
+
it 'delegates to ContractFactory' do
|
32
|
+
Pacto::ContractFactory.should_receive(:build_from_file).with(path, host, file_pre_processor)
|
33
|
+
described_class.build_from_file(path, host, file_pre_processor)
|
35
34
|
end
|
36
|
-
|
37
|
-
it '
|
38
|
-
|
39
|
-
described_class.build_from_file(
|
35
|
+
|
36
|
+
it 'returns whatever the factory returns' do
|
37
|
+
Pacto::ContractFactory.stub(:build_from_file => instantiated_contract)
|
38
|
+
described_class.build_from_file(path, host, file_pre_processor).should == instantiated_contract
|
40
39
|
end
|
41
40
|
end
|
42
41
|
|
File without changes
|
File without changes
|
File without changes
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pacto
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-08-
|
12
|
+
date: 2013-08-16 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: webmock
|
@@ -229,6 +229,7 @@ extra_rdoc_files: []
|
|
229
229
|
files:
|
230
230
|
- .gitignore
|
231
231
|
- .rspec
|
232
|
+
- .rspec_integration
|
232
233
|
- .travis.yml
|
233
234
|
- Gemfile
|
234
235
|
- Guardfile
|
@@ -238,6 +239,7 @@ files:
|
|
238
239
|
- TODO.md
|
239
240
|
- lib/pacto.rb
|
240
241
|
- lib/pacto/contract.rb
|
242
|
+
- lib/pacto/contract_factory.rb
|
241
243
|
- lib/pacto/extensions.rb
|
242
244
|
- lib/pacto/file_pre_processor.rb
|
243
245
|
- lib/pacto/instantiated_contract.rb
|
@@ -247,16 +249,22 @@ files:
|
|
247
249
|
- lib/pacto/response_adapter.rb
|
248
250
|
- lib/pacto/version.rb
|
249
251
|
- pacto.gemspec
|
250
|
-
- spec/data/
|
251
|
-
- spec/
|
252
|
-
- spec/
|
253
|
-
- spec/
|
254
|
-
- spec/pacto/instantiated_contract_spec.rb
|
255
|
-
- spec/pacto/pacto_spec.rb
|
256
|
-
- spec/pacto/request_spec.rb
|
257
|
-
- spec/pacto/response_adapter_spec.rb
|
258
|
-
- spec/pacto/response_spec.rb
|
252
|
+
- spec/integration/data/simple_contract.json
|
253
|
+
- spec/integration/e2e_spec.rb
|
254
|
+
- spec/integration/spec_helper.rb
|
255
|
+
- spec/integration/utils/dummy_server.rb
|
259
256
|
- spec/spec_helper.rb
|
257
|
+
- spec/unit/data/contract.json
|
258
|
+
- spec/unit/pacto/contract_factory_spec.rb
|
259
|
+
- spec/unit/pacto/contract_spec.rb
|
260
|
+
- spec/unit/pacto/extensions_spec.rb
|
261
|
+
- spec/unit/pacto/file_pre_processor_spec.rb
|
262
|
+
- spec/unit/pacto/instantiated_contract_spec.rb
|
263
|
+
- spec/unit/pacto/pacto_spec.rb
|
264
|
+
- spec/unit/pacto/request_spec.rb
|
265
|
+
- spec/unit/pacto/response_adapter_spec.rb
|
266
|
+
- spec/unit/pacto/response_spec.rb
|
267
|
+
- spec/unit/spec_helper.rb
|
260
268
|
homepage: https://github.com/thoughtworks/pacto
|
261
269
|
licenses:
|
262
270
|
- MIT
|
@@ -283,13 +291,19 @@ signing_key:
|
|
283
291
|
specification_version: 3
|
284
292
|
summary: Consumer-Driven Contracts implementation
|
285
293
|
test_files:
|
286
|
-
- spec/data/
|
287
|
-
- spec/
|
288
|
-
- spec/
|
289
|
-
- spec/
|
290
|
-
- spec/pacto/instantiated_contract_spec.rb
|
291
|
-
- spec/pacto/pacto_spec.rb
|
292
|
-
- spec/pacto/request_spec.rb
|
293
|
-
- spec/pacto/response_adapter_spec.rb
|
294
|
-
- spec/pacto/response_spec.rb
|
294
|
+
- spec/integration/data/simple_contract.json
|
295
|
+
- spec/integration/e2e_spec.rb
|
296
|
+
- spec/integration/spec_helper.rb
|
297
|
+
- spec/integration/utils/dummy_server.rb
|
295
298
|
- spec/spec_helper.rb
|
299
|
+
- spec/unit/data/contract.json
|
300
|
+
- spec/unit/pacto/contract_factory_spec.rb
|
301
|
+
- spec/unit/pacto/contract_spec.rb
|
302
|
+
- spec/unit/pacto/extensions_spec.rb
|
303
|
+
- spec/unit/pacto/file_pre_processor_spec.rb
|
304
|
+
- spec/unit/pacto/instantiated_contract_spec.rb
|
305
|
+
- spec/unit/pacto/pacto_spec.rb
|
306
|
+
- spec/unit/pacto/request_spec.rb
|
307
|
+
- spec/unit/pacto/response_adapter_spec.rb
|
308
|
+
- spec/unit/pacto/response_spec.rb
|
309
|
+
- spec/unit/spec_helper.rb
|