Sha256: 4b1260f218af1c8b8b35feb4f32911699b8766f678f9a97585fec5d22dca9b5c

Contents?: true

Size: 1.87 KB

Versions: 6

Compression:

Stored size: 1.87 KB

Contents

require "spec_helper"
require "shelly/cli/runner"

describe Shelly::CLI::Runner do
  before do
    ENV['SHELLY_DEBUG'] = "false"
    @runner = Shelly::CLI::Runner.new(%w(version --debug))
  end

  describe "#initialize" do
    it "should initialize parent class" do
      @runner.should be_kind_of(Thor::Shell::Basic)
      @runner.should respond_to(:say) # if responds to parent class method
    end

    it "should assign args" do
      @runner.args.should == %w(version --debug)
    end
  end

  describe "#debug?" do
    it "should be true if args include --debug option" do
      @runner.should be_debug
    end
    
    it "should be true if SHELLY_DEBUG is set to true" do
      runner = Shelly::CLI::Runner.new
      runner.should_not be_debug
      ENV['SHELLY_DEBUG'] = "true"
      runner.should be_debug
    end

    it "should be false if args doesn't include --debug option" do
      runner = Shelly::CLI::Runner.new(%w(version))
      runner.should_not be_debug
    end
  end

  describe "#start" do
    it "should start main CLI with given args" do
      Shelly::CLI::Main.should_receive(:start).with(%w(version --debug))
      @runner.start
    end

    context "with --debug option (debug mode)" do
      it "should re-raise caught exception to the console" do
        Shelly::CLI::Main.stub(:start).and_raise(RuntimeError.new)
        lambda {
          @runner.start
        }.should raise_error(RuntimeError)
      end
    end

    context "without --debug option (normal mode)" do
      it "should rescue exception and display generic error message" do
        Shelly::CLI::Main.stub(:start).and_raise(RuntimeError.new)
        runner = Shelly::CLI::Runner.new(%w(version))
        $stdout.should_receive(:puts).with("Unknown error, to see debug information run command with --debug")
        lambda {
          runner.start
        }.should raise_error(SystemExit)
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
shelly-0.0.43 spec/shelly/cli/runner_spec.rb
shelly-0.0.41 spec/shelly/cli/runner_spec.rb
shelly-0.0.41.pre spec/shelly/cli/runner_spec.rb
shelly-0.0.40 spec/shelly/cli/runner_spec.rb
shelly-0.0.39 spec/shelly/cli/runner_spec.rb
shelly-0.0.38 spec/shelly/cli/runner_spec.rb