Sha256: 364521c86ada2a1fd4d0ba4b4e136f9dc84c34557de9504138602c7486cd8af1

Contents?: true

Size: 2 KB

Versions: 1

Compression:

Stored size: 2 KB

Contents

describe CLIForge, ".start" do

  let(:mock_runner) {
    double("CLIForge::Runner").tap do |runner|
      runner.stub(:start)
    end
  }

  before(:each) do
    CLIForge::Runner.stub(:new) { |config|
      @config = config
      mock_runner
    }
  end

  # Stub out our environment
  around(:each) do |spec|
    old_path, old_argv = ENV["PATH"], ARGV

    begin
      spec.run
    ensure
      ENV["PATH"] = old_path
      Object.send(:remove_const, :ARGV)
      ::ARGV = old_argv
    end
  end


  it "should not require any arguments" do
    mock_runner.should_receive(:start)
    described_class.should_receive(:guess_bin_name)

    described_class.start
  end

  it "should pass the configuration to the given block" do
    mock_runner.should_receive(:start)
    described_class.should_not_receive(:guess_bin_name)

    described_class.start do |config|
      config.bin_name = "foo-bar"
    end

    expect(@config.bin_name).to eq("foo-bar")
  end

  describe "special-cased configuration properties" do

    it "should consume the passed name if given" do
      mock_runner.should_receive(:start)
      described_class.should_not_receive(:guess_bin_name)

      described_class.start("awesomesauce")

      expect(@config.bin_name).to eq("awesomesauce")
    end

    it "should extract the caller path" do
      ENV["PATH"] = ""

      described_class.start

      expect(@config.search_paths).to eq([
        File.dirname(__FILE__)
      ])
    end

    it "should pull search paths in order from PATH" do
      ENV["PATH"] = "/usr/bin:/usr/local/bin:/foo/bar:/usr/bin"
      described_class.stub(:caller_path) { nil }

      described_class.start

      expect(@config.search_paths).to eq([
        "/usr/bin",
        "/usr/local/bin",
        "/foo/bar"
      ])
    end

    it "should extract ARGV" do
      Object.send(:remove_const, :ARGV)
      ::ARGV = ["my-bin", "sub-command", "--stuff"]

      mock_runner.should_receive(:start).with(["my-bin", "sub-command", "--stuff"])

      described_class.start
    end

  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
cli-forge-0.1.0 spec/unit/cli_forge/class_methods/start_spec.rb