Skip to content

Commit 886344c

Browse files
author
Kevin Paulisse
committed
Fix tests
1 parent f2c6492 commit 886344c

1 file changed

Lines changed: 10 additions & 22 deletions

File tree

spec/octocatalog-diff/tests/catalog-util/git_spec.rb

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
require OctocatalogDiff::Spec.require_path('catalog-util/git')
66
require OctocatalogDiff::Spec.require_path('errors')
7+
require OctocatalogDiff::Spec.require_path('util/scriptrunner')
78

89
require 'ostruct'
910

@@ -48,10 +49,10 @@
4849
context 'with valid directory' do
4950
context 'with successful script run' do
5051
it 'should log proper messages and not raise error' do
51-
expect(described_class).to receive(:create_git_checkout_script).and_return('/tmp/baz.sh')
52-
expect(Open3).to receive(:capture2e)
53-
.with('/tmp/baz.sh', chdir: '/tmp/bar')
54-
.and_return(['asldfkj', OpenStruct.new(exitstatus: 0)])
52+
script_runner = double
53+
expect(script_runner).to receive(:run).and_return('')
54+
expect(OctocatalogDiff::Util::ScriptRunner).to receive(:new).and_return(script_runner)
55+
5556
opts = { branch: 'foo', path: '/tmp/bar', basedir: '/tmp/bar', logger: @logger }
5657
described_class.check_out_git_archive(opts)
5758
expect(@logger_str.string).to match(%r{Success git archive /tmp/bar:foo})
@@ -60,10 +61,11 @@
6061

6162
context 'with failed script run' do
6263
it 'should raise OctocatalogDiff::Errors::GitCheckoutError' do
63-
expect(described_class).to receive(:create_git_checkout_script).and_return('/tmp/baz.sh')
64-
expect(Open3).to receive(:capture2e)
65-
.with('/tmp/baz.sh', chdir: '/tmp/bar')
66-
.and_return(['errors abound', OpenStruct.new(exitstatus: 1)])
64+
script_runner = double
65+
expect(script_runner).to receive(:run).and_raise(OctocatalogDiff::Util::ScriptRunner::ScriptException)
66+
expect(script_runner).to receive(:output).and_return('errors abound')
67+
expect(OctocatalogDiff::Util::ScriptRunner).to receive(:new).and_return(script_runner)
68+
6769
opts = { branch: 'foo', path: '/tmp/bar', basedir: '/tmp/bar', logger: @logger }
6870
expect do
6971
described_class.check_out_git_archive(opts)
@@ -73,20 +75,6 @@
7375
end
7476
end
7577

76-
describe '#create_git_checkout_script' do
77-
it 'should create the temporary script' do
78-
result = described_class.create_git_checkout_script('foo', '/tmp/baz')
79-
expect(result).to be_a_kind_of(String)
80-
expect(File.file?(result)).to eq(true)
81-
82-
text = File.read(result)
83-
expect(text).to match(/git archive --format=tar foo \|/)
84-
expect(text).to match(%r{\( cd /tmp/baz && tar -xf - \)})
85-
86-
expect(File.executable?(result)).to eq(true)
87-
end
88-
end
89-
9078
describe '#branch_sha' do
9179
context 'with invalid directory' do
9280
it 'should raise Errno::ENOENT if basedir is nil' do

0 commit comments

Comments
 (0)