Advertisement
Guest User

Untitled

a guest
Mar 21st, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.72 KB | None | 0 0
  1. describe Ec2pyParser do
  2. let(:default_ec2py_command) { '/etc/ansible/inventory/ec2.py' }
  3.  
  4. subject { Ec2pyParser.new }
  5.  
  6. describe '#new' do
  7. context 'no ec2.py command override is passed' do
  8. it 'sets the ec2py_command to the correct default' do
  9. expect(subject.ec2py_command).to eq default_ec2py_command
  10. end
  11. end
  12.  
  13. context 'an ec2.py command override is passed' do
  14. let(:ec2py_command_override) do
  15. File.join(Dir.pwd, 'vendor', 'ec2.py')
  16. end
  17.  
  18. subject { Ec2pyParser.new(ec2py_command_override) }
  19.  
  20. it 'sets the ec2py_command to the override' do
  21. expect(subject.ec2py_command).to eq ec2py_command_override
  22. end
  23. end
  24. end
  25.  
  26.  
  27.  
  28. describe '#parse' do
  29. after { ENV.delete('DEPLOY_ENV') }
  30.  
  31. context 'when DEPLOY_ENV is not set' do
  32. it 'raises an error with the correct message' do
  33. expect { subject.parse }.to raise_error('DEPLOY_ENV must be set to staging, training, or production')
  34. end
  35. end
  36.  
  37. context 'when DEPLOY_ENV is set' do
  38. let(:example_ec2py_output) do
  39. File.read(
  40. File.join(
  41. Dir.pwd,
  42. 'spec',
  43. 'fixtures',
  44. 'files',
  45. 'ec2py_output.json'
  46. )
  47. )
  48. end
  49.  
  50. before { ENV['DEPLOY_ENV'] = 'staging' }
  51.  
  52. it 'calls Kernel#system with the correct path' do
  53. expect(Kernel).to receive(:system).with(default_ec2py_command).and_return(example_ec2py_output)
  54.  
  55. subject.parse
  56. end
  57.  
  58. context 'deploy environment is staging' do
  59. let(:expected_parser_output) do
  60. File.read(
  61. File.join(
  62. Dir.pwd,
  63. 'spec',
  64. 'fixtures',
  65. 'files',
  66. 'expected_staging_output.json'
  67. )
  68. )
  69. end
  70.  
  71. it 'produces the correct output' do
  72. allow(Kernel).to receive(:system).with(default_ec2py_command).and_return(example_ec2py_output)
  73.  
  74. expect(subject.parse).to eq expected_parser_output
  75. end
  76. end
  77.  
  78. context 'deploy environment is training' do
  79. let(:expected_parser_output) do
  80. File.read(
  81. File.join(
  82. Dir.pwd,
  83. 'spec',
  84. 'fixtures',
  85. 'files',
  86. 'expected_staging_output.json'
  87. )
  88. )
  89. end
  90.  
  91. it 'produces the correct output'
  92. end
  93.  
  94. context 'deploy environment is production' do
  95. let(:expected_parser_output) do
  96. File.read(
  97. File.join(
  98. Dir.pwd,
  99. 'spec',
  100. 'fixtures',
  101. 'files',
  102. 'expected_staging_output.json'
  103. )
  104. )
  105. end
  106.  
  107. it 'produces the correct output'
  108. end
  109. end
  110. end
  111. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement