Sha256: f7b59d231131019df13eefa375ffd90cc73692ba3d7d35181fd243fbe8b3523c

Contents?: true

Size: 1.34 KB

Versions: 3

Compression:

Stored size: 1.34 KB

Contents

require 'spec_helper'
require 'torkify/reader'

module Torkify
  describe Reader do
    context "with dummy command" do
      before { @reader = Reader.new 'echo' }
      subject { @reader}

      it { should respond_to :readline  }
      it { should respond_to :each_line }
      it { should respond_to :pos       }
    end

    context "with echo command" do
      before { @reader = Reader.new 'echo "Line 1\nLine 2"' }

      context "first line" do
        subject { @reader.readline.strip }
        it { should == "Line 1" }
      end

      context "second line" do
        before { @reader.readline }
        subject { @reader.readline.strip }

        it { should == "Line 2" }
      end

      context "each over line" do
        before do
          @output = []
          @reader.each_line { |line| @output << line.strip }
        end

        subject { @output }

        it { should == ["Line 1", "Line 2"] }
      end
    end

    context "with command that writes to standard error" do
      it "should raise TorkError" do
        err = 'Command error'
        expect { Reader.new "echo '#{err}' >&2" }.to raise_exception(TorkError, err)
      end
    end

    context "with a working directory" do
      before do
        @reader = Reader.new 'echo $PWD', '/usr'
      end
      subject { @reader.read.strip }

      it { should == '/usr' }
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
torkify-0.0.3 spec/reader_spec.rb
torkify-0.0.2 spec/reader_spec.rb
torkify-0.0.1 spec/reader_spec.rb