Sha256: 10f7c9a8e103ef4f8b4fef4fa91715e190df25ad008ea4fa456a5d0f998dc81e

Contents?: true

Size: 1.9 KB

Versions: 2

Compression:

Stored size: 1.9 KB

Contents

require File.expand_path(
    File.join(File.dirname(__FILE__), %w[.. .. lib germinate]))

module Germinate
  describe ShellPublisher do
    before :each do
      @name = "frank"
      @pipeline_output = ["* line 1\n", "* line 2\n"]
      @pipeline  = stub("Pipeline", :call => @pipeline_output)
      @variables = stub("Variables")
      @librarian = stub("Librarian", 
        :make_pipeline => @pipeline,
        :variables     => @variables)
      @command   = "cat %f"
      @options   = {:command => @command}
      @it = ShellPublisher.new(@name, @librarian, @options)
    end

    it "should have identifier 'shell'" do
      ShellPublisher.identifier.should == "shell"
    end

    context "on publish" do
      before :each do
        @result  = ["line 1\n", "line 2\n"]
        @output  = StringIO.new
        @process = stub("ShellProcess", :call => @result).as_null_object
        @source  = stub("Source").as_null_object
        @librarian.stub!(:[]).and_return(@source)
        ShellProcess.stub!(:new).and_return(@process)
      end
      
      it "should create a new process" do
        ShellProcess.should_receive(:new).with(@name, @command, @variables)
        @it.publish!(@output)
      end

      it "should execute the created process" do
        @process.should_receive(:call).with(anything).and_return(@result)
        @it.publish!(@output)
      end

      it "should pass the pipeline output to the created process" do
        @process.should_receive(:call).with(@pipeline_output).and_return(@result)
        @it.publish!(@output)
      end

      it "should ask the librarian for the source file" do
        @librarian.should_receive(:[]).with("$TEXT|_transform", anything)
        @it.publish!(@output)
      end

      it "should write process output to given output stream" do
        @it.publish!(@output)
        @output.rewind
        @output.read.should == "line 1\nline 2\n"
      end

    end
  end
end

Version data entries

2 entries across 2 versions & 2 rubygems

Version Path
devver-germinate-1.2.0 spec/germinate/shell_publisher_spec.rb
germinate-1.2.0 spec/germinate/shell_publisher_spec.rb