spec/integration/e2e_spec.rb in pacto-0.3.0.pre vs spec/integration/e2e_spec.rb in pacto-0.3.0

- old
+ new

@@ -15,57 +15,48 @@ after :all do @server.terminate end it 'verifies the contract against a producer' do - contract = Pacto.build_from_file(contract_path, 'http://localhost:8000') - expect(contract.validate).to be_empty + contract = Pacto.load_contracts(contract_path, 'http://localhost:8000') + expect(contract.validate_all.flatten).to eq([]) end end - context 'Stub generation' do - it 'generates a stub to be used by a consumer' do - contract = Pacto.build_from_file(contract_path, 'http://dummyprovider.com') - Pacto.register_contract(contract, 'my_tag') - Pacto.use('my_tag') - expect(response.keys).to eq ['message'] - expect(response['message']).to be_kind_of(String) - end + context 'Stubbing a collection of contracts' do + it 'generates a server that stubs the contract for consumers' do + contracts = Pacto.load_contracts(contract_path, 'http://dummyprovider.com') + contracts.stub_all - let :response do - raw_response = HTTParty.get('http://dummyprovider.com/hello', headers: {'Accept' => 'application/json' }) - MultiJson.load(raw_response.body) + response = get_json('http://dummyprovider.com/hello') + expect(response['message']).to eq 'bar' end end context 'Journey' do it 'stubs multiple services with a single use' do Pacto.configure do |c| c.strict_matchers = false - c.postprocessor = Pacto::ERBProcessor.new - c.preprocessor = nil - c.register_callback Pacto::Hooks::ERBHook.new + c.register_hook Pacto::Hooks::ERBHook.new end - # Preprocessor must be off before building! - login_contract = Pacto.build_from_file(contract_path, 'http://dummyprovider.com') - contract = Pacto.build_from_file(strict_contract_path, 'http://dummyprovider.com') - Pacto.configure do |c| - c.register_contract login_contract, :default - c.register_contract contract, :devices - end + contracts = Pacto.load_contracts 'spec/integration/data/', 'http://dummyprovider.com' + contracts.stub_all(:device_id => 42) - Pacto.use(:devices, {:device_id => 42}) - - raw_response = HTTParty.get('http://dummyprovider.com/hello', headers: {'Accept' => 'application/json' }) - login_response = MultiJson.load(raw_response.body) + login_response = get_json('http://dummyprovider.com/hello') expect(login_response.keys).to eq ['message'] expect(login_response['message']).to be_kind_of(String) - devices_response = HTTParty.get('http://dummyprovider.com/strict', headers: {'Accept' => 'application/json' }) - devices_response = MultiJson.load(devices_response.body) + devices_response = get_json('http://dummyprovider.com/strict') expect(devices_response['devices']).to have(2).items - expect(devices_response['devices'][0]).to eq '/dev/42' - # devices_response['devices'][1].should == '/dev/43' + expect(devices_response['devices'][0]).to eq('/dev/42') + expect(devices_response['devices'][1]).to eq('/dev/43') end + end + + def get_json(url) + response = Faraday.get(url) do |req| + req.headers = {'Accept' => 'application/json' } + end + MultiJson.load(response.body) end end