1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
|
shared_examples_for "a subprocess runner" do |fixture_root|
describe "running 'echo test'" do
subject { described_class.new(%w[echo test]) }
it "sets the exit code to 0" do
result = subject.run
expect(result.exit_code).to eq 0
end
it "returns the contents of stdout" do
result = subject.run
expect(result.stdout).to eq 'test'
end
it "indicates the command succeeded" do
result = subject.run
expect(result).to be_success
expect(result).to_not be_failed
end
end
describe "running a command with a large amount of output" do
subject do
described_class.new(['ruby', '-e', 'blob = "buffalo!" * (2 << 16); puts blob'])
end
it "does not hang" do
Timeout.timeout(5) do
subject.run
end
end
end
describe "running 'ls' or 'dir' with a different working directory" do
subject do
if R10K::Util::Platform.windows?
described_class.new(%w[cmd /c dir]).tap do |o|
o.cwd = fixture_root
end
else
described_class.new(%w[ls]).tap do |o|
o.cwd = fixture_root
end
end
end
it "returns the contents of the given working directory" do
result = subject.run
expect(result.stdout).to match('no-execute.sh')
end
end
describe "running 'false'" do
subject { described_class.new(%w[false]) }
it "sets the exit code to 1", unless: R10K::Util::Platform.windows? do
result = subject.run
expect(result.exit_code).to eq 1
end
it "indicates the command failed" do
result = subject.run
expect(result).to_not be_success
expect(result).to be_failed
end
end
describe "running '/this/command/will/not/exist'" do
subject { described_class.new(%w[/this/command/will/not/exist]) }
it "indicates the command failed" do
result = subject.run
expect(result).to_not be_success
expect(result).to be_failed
end
end
describe "running a non-executable file", :unless => R10K::Util::Platform.windows? do
let(:fixture_file) { File.join(fixture_root, 'no-execute.sh') }
subject { described_class.new([fixture_file]) }
it "indicates the command failed" do
result = subject.run
expect(result).to_not be_success
expect(result).to be_failed
end
end
end
|