Sha256: 95189e960ad8171c29d50d508151be296d8326aa2288a40dee2335a41c60cc40

Contents?: true

Size: 1.37 KB

Versions: 18

Compression:

Stored size: 1.37 KB

Contents

require 'spec_helper'

describe Dragonfly::Shell do

  let(:shell){ Dragonfly::Shell.new }

  it "returns the result of the command" do
    shell.run("echo 10").strip.should == '10'
  end

  it "should raise an error if the command isn't found" do
    lambda{
      shell.run "non-existent-command"
    }.should raise_error(Dragonfly::Shell::CommandFailed)
  end

  it "should raise an error if the command fails" do
    lambda{
      shell.run "ls -j"
    }.should raise_error(Dragonfly::Shell::CommandFailed)
  end

  unless Dragonfly.running_on_windows?

    describe "escaping args" do
      {
        %q(hello) => %q('hello'),
        %q("hello") => %q('hello'),
        %q('hello') => %q('hello'),
        %q(he\'llo) => %q('he'\''llo'),
        %q('he'\''llo') => %q('he'\''llo'),
        %q("he'llo") => %q('he'\''llo'),
        %q(hel$(lo)) => %q('hel$(lo)'),
        %q(hel\$(lo)) => %q('hel$(lo)'),
        %q('hel\$(lo)') => %q('hel\$(lo)')
      }.each do |args, escaped_args|
        it "should escape #{args.inspect} -> #{escaped_args.inspect}" do
          shell.escape_args(args).should == escaped_args
        end
      end
    end

    it "escapes commands by default" do
      shell.run("echo `echo 1`").strip.should == "`echo 1`"
    end

    it "allows running non-escaped commands" do
      shell.run("echo `echo 1`", :escape => false).strip.should == "1"
    end

  end

end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
dragonfly-1.1.5 spec/dragonfly/shell_spec.rb
dragonfly-1.1.4 spec/dragonfly/shell_spec.rb
dragonfly-1.1.3 spec/dragonfly/shell_spec.rb
dragonfly-1.1.2 spec/dragonfly/shell_spec.rb
dragonfly-1.1.1 spec/dragonfly/shell_spec.rb
dragonfly-1.1.0 spec/dragonfly/shell_spec.rb
dragonfly-1.0.12 spec/dragonfly/shell_spec.rb
dragonfly-1.0.11 spec/dragonfly/shell_spec.rb
dragonfly-1.0.10 spec/dragonfly/shell_spec.rb
dragonfly-1.0.9 spec/dragonfly/shell_spec.rb
dragonfly-1.0.8 spec/dragonfly/shell_spec.rb
dragonfly-1.0.7 spec/dragonfly/shell_spec.rb
dragonfly-1.0.6 spec/dragonfly/shell_spec.rb
dragonfly-1.0.5 spec/dragonfly/shell_spec.rb
dragonfly-1.0.4 spec/dragonfly/shell_spec.rb
dragonfly-1.0.3 spec/dragonfly/shell_spec.rb
dragonfly-1.0.2 spec/dragonfly/shell_spec.rb
dragonfly-1.0.1 spec/dragonfly/shell_spec.rb