Sha256: 5902898110b6e05cc1376f3e19832b101bb536a992334d0e14ef194567706912

Contents?: true

Size: 1.29 KB

Versions: 3

Compression:

Stored size: 1.29 KB

Contents

require 'spec_helper'
require 'command_kit/program_name'

describe ProgramName do
  module TestProgramName
    class TestCmd
      include CommandKit::ProgramName
    end
  end

  let(:command_class) { TestProgramName::TestCmd }
  let(:program_name) { 'foo' }

  before do
    @original_program_name = $PROGRAM_NAME
    $PROGRAM_NAME = program_name
  end

  describe ".program_name" do
    subject { command_class }

    it "must return $PROGRAM_NAME" do
      expect(subject.program_name).to eq(program_name)
    end

    context "when $PROGRAM_NAME is '-e'" do
      let(:program_name) { '-e' }

      it "must return nil" do
        expect(subject.program_name).to be(nil)
      end
    end

    context "when $PROGRAM_NAME is 'irb'" do
      let(:program_name) { 'irb' }

      it "must return nil" do
        expect(subject.program_name).to be(nil)
      end
    end

    context "when $PROGRAM_NAME is 'rspec'" do
      let(:program_name) { 'rspec' }

      it "must return nil" do
        expect(subject.program_name).to be(nil)
      end
    end
  end

  describe "#program_name" do
    subject { command_class.new }

    it "should be the same as .program_name" do
      expect(subject.program_name).to eq(command_class.program_name)
    end
  end

  after do
    $PROGRAM_NAME = @original_program_name
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
command_kit-0.1.0.rc1 spec/program_name_spec.rb
command_kit-0.1.0.pre2 spec/program_name_spec.rb
command_kit-0.1.0.pre1 spec/program_name_spec.rb