File: shell_capture_spec.rb

package info (click to toggle)
ruby-cliver 0.3.2-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 208 kB
  • sloc: ruby: 760; makefile: 3
file content (42 lines) | stat: -rw-r--r-- 1,335 bytes parent folder | download | duplicates (3)
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
# encoding: utf-8
require 'cliver'

describe Cliver::ShellCapture do
  let(:test_command) { 'test command' }
  subject { Cliver::ShellCapture.new(test_command) }

  context 'a command that exists' do
    let(:intended_stdout) { StringIO.new('1.1.1').tap(&:rewind) }
    let(:intended_stderr) { StringIO.new('foo baar 1').tap(&:rewind) }
    let(:intended_stdin)  { StringIO.new('').tap(&:rewind) }

    ['test command', %w(test command)].each do |input|
      context "with #{input.class.name} input" do
        let(:test_command) { input }

        before(:each) do
          Open3.should_receive(:popen3) do |*args|
            args.size.should eq 1
            args.first.should == 'test command'
          end.and_yield(intended_stdin, intended_stdout, intended_stderr)
        end

        its(:stdout) { should eq '1.1.1' }
        its(:stderr) { should eq 'foo baar 1' }
        its(:command_found) { should be_true }
      end
    end
  end

  context 'looking for a command that does not exist' do
    before(:each) do
      Open3.should_receive(:popen3) do |command|
        command.should eq test_command
        raise Errno::ENOENT.new("No such file or directory - #{test_command}")
      end
    end
    its(:stdout) { should eq '' }
    its(:stderr) { should eq '' }
    its(:command_found) { should be_false }
  end
end