Sha256: a78affc5f4afccd68a662932999f382a4f795da5ac55ed0e0ddbf13cf506a0dc

Contents?: true

Size: 1.64 KB

Versions: 19

Compression:

Stored size: 1.64 KB

Contents

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

describe Shelly::CLI::Runner do
  before do
    @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 failse 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

19 entries across 19 versions & 1 rubygems

Version Path
shelly-0.0.37 spec/shelly/cli/runner_spec.rb
shelly-0.0.36 spec/shelly/cli/runner_spec.rb
shelly-0.0.34 spec/shelly/cli/runner_spec.rb
shelly-0.0.33 spec/shelly/cli/runner_spec.rb
shelly-0.0.32 spec/shelly/cli/runner_spec.rb
shelly-0.0.31 spec/shelly/cli/runner_spec.rb
shelly-0.0.30 spec/shelly/cli/runner_spec.rb
shelly-0.0.29 spec/shelly/cli/runner_spec.rb
shelly-0.0.28 spec/shelly/cli/runner_spec.rb
shelly-0.0.27 spec/shelly/cli/runner_spec.rb
shelly-0.0.26 spec/shelly/cli/runner_spec.rb
shelly-0.0.21.pre5 spec/shelly/cli/runner_spec.rb
shelly-0.0.25 spec/shelly/cli/runner_spec.rb
shelly-0.0.24 spec/shelly/cli/runner_spec.rb
shelly-0.0.23 spec/shelly/cli/runner_spec.rb
shelly-0.0.22 spec/shelly/cli/runner_spec.rb
shelly-0.0.21.pre3 spec/shelly/cli/runner_spec.rb
shelly-0.0.21.pre2 spec/shelly/cli/runner_spec.rb
shelly-0.0.21 spec/shelly/cli/runner_spec.rb