|
29 | 29 | end
|
30 | 30 |
|
31 | 31 | describe 'examples/api/v1/catalog-builder-local-files.rb' do
|
32 |
| - let(:script) { File.expand_path('../../../examples/api/v1/catalog-builder-local-files.rb', File.dirname(__FILE__)) } |
33 |
| - let(:ls_l) { Open3.capture2e("ls -l '#{script}'").first } |
| 32 | + before(:all) do |
| 33 | + @script = File.expand_path('../../../examples/api/v1/catalog-builder-local-files.rb', File.dirname(__FILE__)) |
| 34 | + end |
34 | 35 |
|
35 | 36 | it 'should exist' do
|
36 |
| - expect(File.file?(script)).to eq(true), ls_l |
| 37 | + ls_l = Open3.capture2e("ls -l '#{@script}'").first |
| 38 | + expect(File.file?(@script)).to eq(true), ls_l |
37 | 39 | end
|
38 | 40 |
|
39 | 41 | context 'executing' do
|
40 |
| - before(:each) do |
41 |
| - @stdout_obj = StringIO.new |
42 |
| - @old_stdout = $stdout |
43 |
| - $stdout = @stdout_obj |
| 42 | + before(:all) do |
| 43 | + @stdout, @stderr, @exitcode = Open3.capture3(@script) |
44 | 44 | end
|
45 | 45 |
|
46 |
| - after(:each) do |
47 |
| - $stdout = @old_stdout |
| 46 | + it 'should run without error' do |
| 47 | + expect(@exitcode.exitstatus).to eq(0) |
48 | 48 | end
|
49 | 49 |
|
50 |
| - it 'should compile and run' do |
51 |
| - load script |
52 |
| - output = @stdout_obj.string.split("\n") |
| 50 | + it 'should print the expected output' do |
| 51 | + output = @stdout.split("\n") |
53 | 52 | expect(output).to include('Object returned from OctocatalogDiff::API::V1.catalog is: OctocatalogDiff::API::V1::Catalog')
|
54 | 53 | expect(output).to include('The catalog is valid.')
|
55 | 54 | expect(output).to include('The catalog was built using OctocatalogDiff::Catalog::Computed')
|
56 | 55 | expect(output).to include('- System::User - bob')
|
57 | 56 | expect(output).to include('The resources are equal!')
|
58 | 57 | end
|
| 58 | + |
| 59 | + it 'should not output to STDERR' do |
| 60 | + expect(@stderr).to eq('') |
| 61 | + end |
| 62 | + end |
| 63 | +end |
| 64 | + |
| 65 | +describe 'examples/api/v1/catalog-diff-local-files.rb' do |
| 66 | + before(:all) do |
| 67 | + @script = File.expand_path('../../../examples/api/v1/catalog-diff-local-files.rb', File.dirname(__FILE__)) |
| 68 | + end |
| 69 | + |
| 70 | + it 'should exist' do |
| 71 | + ls_l = Open3.capture2e("ls -l '#{@script}'").first |
| 72 | + expect(File.file?(@script)).to eq(true), ls_l |
| 73 | + end |
| 74 | + |
| 75 | + context 'executing' do |
| 76 | + before(:all) do |
| 77 | + @stdout, @stderr, @exitcode = Open3.capture3(@script) |
| 78 | + end |
| 79 | + |
| 80 | + it 'should run without error' do |
| 81 | + expect(@exitcode.exitstatus).to eq(0) |
| 82 | + end |
| 83 | + |
| 84 | + it 'should print the expected output' do |
| 85 | + output = @stdout.split("\n") |
| 86 | + expect(output).to include('Object returned from OctocatalogDiff::API::V1.catalog_diff is: OpenStruct') |
| 87 | + expect(output).to include('The keys are: diffs, from, to') |
| 88 | + expect(output).to include('There are 36 diffs reported here') |
| 89 | + end |
| 90 | + |
| 91 | + it 'should not output to STDERR' do |
| 92 | + expect(@stderr).to eq('') |
| 93 | + end |
| 94 | + end |
| 95 | +end |
| 96 | + |
| 97 | +describe 'examples/api/v1/catalog-diff-git-repo.rb' do |
| 98 | + before(:all) do |
| 99 | + @script = File.expand_path('../../../examples/api/v1/catalog-diff-git-repo.rb', File.dirname(__FILE__)) |
| 100 | + end |
| 101 | + |
| 102 | + it 'should exist' do |
| 103 | + ls_l = Open3.capture2e("ls -l '#{@script}'").first |
| 104 | + expect(File.file?(@script)).to eq(true), ls_l |
| 105 | + end |
| 106 | + |
| 107 | + context 'executing' do |
| 108 | + before(:all) do |
| 109 | + @stdout, @stderr, @exitcode = Open3.capture3(@script) |
| 110 | + end |
| 111 | + |
| 112 | + it 'should run without error' do |
| 113 | + expect(@exitcode.exitstatus).to eq(0) |
| 114 | + end |
| 115 | + |
| 116 | + it 'should print the expected output' do |
| 117 | + output = @stdout.split("\n") |
| 118 | + expect(output).to include('Here is the directory containing the git repository.') |
| 119 | + expect(@stdout).to match(/DEBUG -- : Compiling catalogs for rspec-node.github.net/) |
| 120 | + expect(@stdout).to match(/Entering catdiff; catalog sizes: 6, 9/) |
| 121 | + expect(output).to include('The from-catalog has 6 resources') |
| 122 | + expect(output).to include('The to-catalog has 9 resources') |
| 123 | + expect(output).to include('There are 6 differences') |
| 124 | + expect(output).to include('Added a File resource called /tmp/bar!') |
| 125 | + expect(output).to include('Changed the File resource /tmp/foo attribute parameters::group') |
| 126 | + end |
| 127 | + |
| 128 | + it 'should not output to STDERR' do |
| 129 | + expect(@stderr).to eq('') |
| 130 | + end |
59 | 131 | end
|
60 | 132 | end
|
0 commit comments