spec/unit/pacto/pacto_spec.rb in pacto-0.3.0.pre vs spec/unit/pacto/pacto_spec.rb in pacto-0.3.0
- old
+ new
@@ -1,7 +1,8 @@
-describe Pacto do
+require 'spec_helper'
+describe Pacto do
around(:each) do |example|
$stdout = StringIO.new
example.run
$stdout = STDOUT
end
@@ -17,20 +18,20 @@
describe '.validate_contract' do
context 'valid' do
it 'displays a success message and return true' do
mock_validation []
success = Pacto.validate_contract 'my_contract.json'
- expect(output).to eq 'All contracts successfully meta-validated'
+ expect(output).to eq 'Validating my_contract.json'
expect(success).to be_true
end
end
context 'invalid' do
it 'displays one error messages and return false' do
mock_validation ['Error 1']
success = Pacto.validate_contract 'my_contract.json'
- expect(output).to match /error/
+ expect(output).to match(/error/)
expect(success).to be_false
end
it 'displays several error messages and return false' do
mock_validation ['Error 1', 'Error 2']
@@ -38,23 +39,24 @@
expect(success).to be_false
end
end
end
- describe '.build_from_file' do
- let(:path) { 'contract/path' }
- let(:host) { 'http://localhost' }
- let(:file_pre_processor) { double('file_pre_processor') }
- let(:instantiated_contract) { double(:instantiated_contract) }
+ describe 'loading contracts' do
+ let(:contracts_path) { 'path/to/dir' }
+ let(:host) { 'localhost' }
+ let(:contract1) { double }
+ let(:contract2) { double }
+ let(:factory) { double(:factory) }
- it 'delegates to ContractFactory' do
- Pacto::ContractFactory.should_receive(:build_from_file).with(path, host, file_pre_processor)
- described_class.build_from_file(path, host, file_pre_processor)
+ before do
+ allow(Pacto::ContractFactory).to receive(:new).and_return(factory)
end
- it 'returns whatever the factory returns' do
- Pacto::ContractFactory.stub(:build_from_file => instantiated_contract)
- expect(described_class.build_from_file(path, host, file_pre_processor)).to eq instantiated_contract
+ it 'instantiates a contract list' do
+ allow(Pacto::ContractFiles).to receive(:for).with(contracts_path).and_return { %w{file1 file2} }
+ allow(factory).to receive(:build).with(%w{file1 file2}, host).and_return { [contract1, contract2] }
+ expect(Pacto::ContractList).to receive(:new).with([contract1, contract2])
+ Pacto.load_contracts(contracts_path, host)
end
end
-
end