Skip to content

Commit 405e079

Browse files
author
Kevin Paulisse
committed
Add tests for new example files
1 parent 3cdfee0 commit 405e079

File tree

1 file changed

+84
-12
lines changed

1 file changed

+84
-12
lines changed

spec/octocatalog-diff/integration/examples_spec.rb

+84-12
Original file line numberDiff line numberDiff line change
@@ -29,32 +29,104 @@
2929
end
3030

3131
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
3435

3536
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
3739
end
3840

3941
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)
4444
end
4545

46-
after(:each) do
47-
$stdout = @old_stdout
46+
it 'should run without error' do
47+
expect(@exitcode.exitstatus).to eq(0)
4848
end
4949

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")
5352
expect(output).to include('Object returned from OctocatalogDiff::API::V1.catalog is: OctocatalogDiff::API::V1::Catalog')
5453
expect(output).to include('The catalog is valid.')
5554
expect(output).to include('The catalog was built using OctocatalogDiff::Catalog::Computed')
5655
expect(output).to include('- System::User - bob')
5756
expect(output).to include('The resources are equal!')
5857
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
59131
end
60132
end

0 commit comments

Comments
 (0)