Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- describe Ec2pyParser do
- let(:default_ec2py_command) { '/etc/ansible/inventory/ec2.py' }
- subject { Ec2pyParser.new }
- describe '#new' do
- context 'no ec2.py command override is passed' do
- it 'sets the ec2py_command to the correct default' do
- expect(subject.ec2py_command).to eq default_ec2py_command
- end
- end
- context 'an ec2.py command override is passed' do
- let(:ec2py_command_override) do
- File.join(Dir.pwd, 'vendor', 'ec2.py')
- end
- subject { Ec2pyParser.new(ec2py_command_override) }
- it 'sets the ec2py_command to the override' do
- expect(subject.ec2py_command).to eq ec2py_command_override
- end
- end
- end
- describe '#parse' do
- after { ENV.delete('DEPLOY_ENV') }
- context 'when DEPLOY_ENV is not set' do
- it 'raises an error with the correct message' do
- expect { subject.parse }.to raise_error('DEPLOY_ENV must be set to staging, training, or production')
- end
- end
- context 'when DEPLOY_ENV is set' do
- let(:example_ec2py_output) do
- File.read(
- File.join(
- Dir.pwd,
- 'spec',
- 'fixtures',
- 'files',
- 'ec2py_output.json'
- )
- )
- end
- before { ENV['DEPLOY_ENV'] = 'staging' }
- it 'calls Kernel#system with the correct path' do
- expect(Kernel).to receive(:system).with(default_ec2py_command).and_return(example_ec2py_output)
- subject.parse
- end
- context 'deploy environment is staging' do
- let(:expected_parser_output) do
- File.read(
- File.join(
- Dir.pwd,
- 'spec',
- 'fixtures',
- 'files',
- 'expected_staging_output.json'
- )
- )
- end
- it 'produces the correct output' do
- allow(Kernel).to receive(:system).with(default_ec2py_command).and_return(example_ec2py_output)
- expect(subject.parse).to eq expected_parser_output
- end
- end
- context 'deploy environment is training' do
- let(:expected_parser_output) do
- File.read(
- File.join(
- Dir.pwd,
- 'spec',
- 'fixtures',
- 'files',
- 'expected_staging_output.json'
- )
- )
- end
- it 'produces the correct output'
- end
- context 'deploy environment is production' do
- let(:expected_parser_output) do
- File.read(
- File.join(
- Dir.pwd,
- 'spec',
- 'fixtures',
- 'files',
- 'expected_staging_output.json'
- )
- )
- end
- it 'produces the correct output'
- end
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement