2022-07-13 21:52:31 +00:00
|
|
|
require "../spec_helper"
|
|
|
|
|
2022-07-15 01:59:14 +00:00
|
|
|
Spectator.describe "GitHub Issue #44" do
|
2022-07-13 21:52:31 +00:00
|
|
|
inject_mock Process do
|
|
|
|
# Instance variable that can be nil, provide a default.
|
|
|
|
@process_info = Crystal::System::Process.new(0)
|
|
|
|
end
|
|
|
|
|
|
|
|
let(command) { "ls -l" }
|
|
|
|
let(exception) { File::NotFoundError.new("File not found", file: "test.file") }
|
|
|
|
|
2022-10-09 18:33:31 +00:00
|
|
|
context "with positional arguments" do
|
|
|
|
before_each do
|
|
|
|
pipe = Process::Redirect::Pipe
|
|
|
|
expect(Process).to receive(:run).with(command, nil, nil, false, true, pipe, pipe, pipe, nil).and_raise(exception)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "must stub Process.run" do
|
|
|
|
expect do
|
|
|
|
Process.run(command, shell: true, output: :pipe) do |_process|
|
|
|
|
end
|
|
|
|
end.to raise_error(File::NotFoundError, "File not found")
|
|
|
|
end
|
2022-07-13 21:52:31 +00:00
|
|
|
end
|
|
|
|
|
2022-10-09 18:33:31 +00:00
|
|
|
# Original issue uses keyword arguments in place of positional arguments.
|
|
|
|
context "keyword arguments in place of positional arguments" do
|
|
|
|
before_each do
|
2022-11-30 05:31:22 +00:00
|
|
|
pipe = Process::Redirect::Pipe
|
|
|
|
expect(Process).to receive(:run).with(command, shell: true, output: pipe).and_raise(exception)
|
2022-10-09 18:33:31 +00:00
|
|
|
end
|
|
|
|
|
2022-11-30 05:31:22 +00:00
|
|
|
it "must stub Process.run" do
|
|
|
|
expect do
|
|
|
|
Process.run(command, shell: true, output: :pipe) do |_process|
|
|
|
|
end
|
|
|
|
end.to raise_error(File::NotFoundError, "File not found")
|
2022-07-13 21:52:31 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|