diff --git a/spec/lib/mina/runner/exec_spec.rb b/spec/lib/mina/runner/exec_spec.rb new file mode 100644 index 00000000..2b3f2a7b --- /dev/null +++ b/spec/lib/mina/runner/exec_spec.rb @@ -0,0 +1,16 @@ +require 'spec_helper' + +describe Mina::Runner::Exec do + subject(:runner) { described_class.new('echo hello') } + + describe '#run' do + before do + allow(Kernel).to receive(:exec) + expect_any_instance_of(Kernel).to receive(:exec).with('echo hello') + end + + it 'executes the script' do + runner.run + end + end +end diff --git a/spec/lib/mina/runner/printer_spec.rb b/spec/lib/mina/runner/printer_spec.rb new file mode 100644 index 00000000..bb6b1f75 --- /dev/null +++ b/spec/lib/mina/runner/printer_spec.rb @@ -0,0 +1,17 @@ +require 'spec_helper' + +describe Mina::Runner::Printer do + subject(:runner) { described_class.new('echo hello') } + + describe '#run' do + it 'prints the script to stdout' do + expect do + runner.run + end.to output("echo hello\n").to_stdout + end + + it 'returns true', :suppressed_output do + expect(runner.run).to eq(true) + end + end +end diff --git a/spec/lib/mina/runner/system_spec.rb b/spec/lib/mina/runner/system_spec.rb new file mode 100644 index 00000000..29057e27 --- /dev/null +++ b/spec/lib/mina/runner/system_spec.rb @@ -0,0 +1,16 @@ +require 'spec_helper' + +describe Mina::Runner::System do + subject(:runner) { described_class.new('echo hello') } + + describe '#run' do + before do + allow(Kernel).to receive(:system) + expect_any_instance_of(Kernel).to receive(:system).with('echo hello') + end + + it 'executes the script' do + runner.run + end + end +end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 3c3e1379..aa975657 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -31,4 +31,13 @@ config.after(:all, type: :rake) do Mina::Configuration.instance.remove :simulate end + + config.around(:each, :suppressed_output) do |example| + original_stdout, $stdout = $stdout, File.open(File::NULL, 'w') + original_stderr, $stderr = $stderr, File.open(File::NULL, 'w') + + example.run + + $stdout, $stderr = original_stdout, original_stderr + end end