Sha256: 83c253175514c678bd0b40dfbca04bcf128abe858581b66e7741f53314e06bc5

Contents?: true

Size: 1.56 KB

Versions: 11

Compression:

Stored size: 1.56 KB

Contents

require 'spec_helper'

describe Anvil::Cli do
  # before {FakeFS.deactivate!}
  describe '#run' do
    let(:dummy_task) { DummyTask }
    let(:argv)       { %w[dummy arg1 arg2 --argument value] }

    context 'with a task name' do
      before do
        dummy_task.should_receive(:new)
          .with('arg1', 'arg2', argument: 'value').and_call_original
        subject.should_not_receive(:print_help)
      end

      it('runs the task in the first parameter') { subject.run argv }
    end

    describe '#build_task' do
      it 'builds the task and parses the arguments' do
        subject.build_task(argv).options.should == { argument: 'value' }
      end

      context 'if the task is not found' do
        let(:argv) { %w[ihopethiswillnotexistever arg2] }

        it 'prints task list and exits' do
          expect(subject).to receive(:task_not_found)
            .with('ihopethiswillnotexistever')
          expect do
            subject.build_task(argv)
          end.to raise_error(SystemExit)
        end
      end

      context 'if the arguments are not the correct' do
        let(:argv) { %w[foo:dummy arg1 arg2 arg3 arg4 arg5 arg6 arg7] }

        it 'prints task list and exits' do
          expect(subject).to receive(:help).with('foo:dummy')
          expect do
            subject.build_task(argv)
          end.to raise_error(SystemExit)
        end
      end
    end

    context 'without a task name' do
      let(:argv)            { [] }
      before                { subject.should_receive(:print_help) }
      it('prints the help') { subject.run argv }
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
anvil-core-0.4.2 spec/lib/anvil/cli_spec.rb
anvil-core-0.4.1 spec/lib/anvil/cli_spec.rb
anvil-core-0.4.0 spec/lib/anvil/cli_spec.rb
anvil-core-0.3.2 spec/lib/anvil/cli_spec.rb
anvil-core-0.3.1 spec/lib/anvil/cli_spec.rb
anvil-core-0.3.0 spec/lib/anvil/cli_spec.rb
anvil-core-0.2.0 spec/lib/anvil/cli_spec.rb
anvil-core-0.1.0 spec/lib/anvil/cli_spec.rb
anvil-core-0.0.1.pre.alpha.3 spec/lib/anvil/cli_spec.rb
anvil-core-0.0.1.pre.alpha.2 spec/lib/anvil/cli_spec.rb
anvil-core-0.0.1.alpha.1 spec/lib/cli_spec.rb