File: shell_out_spec.rb

package info (click to toggle)
ruby-buff-shell-out 0.2.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid, stretch
  • size: 164 kB
  • ctags: 18
  • sloc: ruby: 136; makefile: 3
file content (45 lines) | stat: -rw-r--r-- 1,225 bytes parent folder | download
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
require 'spec_helper'

describe Buff::ShellOut do
  describe "#shell_out" do
    let(:command) { "ls" }

    subject(:result) { described_class.shell_out(command) }

    it "returns a ShellOut::Response" do
      expect(result).to be_a(described_class::Response)
    end

    its(:stdout) { should be_a(String) }
    its(:stderr) { should be_a(String) }
    its(:exitstatus) { should be_a(Fixnum) }
    its(:success?) { should be_truthy }
    its(:error?) { should be_falsey }

    context "when on MRI" do
      before { described_class.stub(jruby?: false) }

      it "delegates to #mri_out" do
        expect(described_class).to receive(:mri_out).with(command, {})
        result
      end

      context "when Process.waitpid2 returns an Integer instead of a Process::Status" do
        before { Process.stub(:waitpid2).and_return([12345, 0]) }

        it "sets the exitstatus to the returned integer" do
          expect(result.exitstatus).to eql(0)
        end
      end
    end

    context "when on JRuby" do
      before { described_class.stub(jruby?: true) }

      it "delegates to #jruby_out" do
        expect(described_class).to receive(:jruby_out).with(command, {})
        result
      end
    end
  end
end