Sha256: 57c5b170ac3b3d32137ae8819e050595e77318e435128727a61a99f59df8714d

Contents?: true

Size: 1.24 KB

Versions: 2

Compression:

Stored size: 1.24 KB

Contents

# encoding: UTF-8
require 'spec_helper'
require 'stringio'
require 'simulacrum/cli/parser'

describe Simulacrum::CLI::Parser do
  def run(args)
    output = StringIO.new('')
    result = Simulacrum::CLI::Parser.new(output).parse(args.split(/\s+/m))

    parser = OpenStruct.new
    parser.output = output.string
    parser.result = result
    parser
  end

  let(:option) { '' }
  subject { run(option) }

  describe 'invalid options' do
    let(:option) { '--velociraptors' }

    it 'handles invalid options by showing help' do
      expect(subject.output).to include('Usage:')
      expect(subject.result).to eq(false)
    end
  end

  describe '--version' do
    let(:option) { '--version' }

    it { expect(subject.result).to eq(true) }
    it { expect(subject.output).to include(Simulacrum::VERSION) }
  end

  describe '--color' do
    it { expect(subject.result.color).to eq(false) }

    context 'when the option is set' do
      let(:option) { '--color' }

      it { expect(subject.result.color).to eq(true) }
    end
  end

  describe '--verbose' do
    it { expect(subject.result.verbose).to eq(false) }

    context 'when the option is set' do
      let(:option) { '--verbose' }

      it { expect(subject.result.verbose).to eq(true) }
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
simulacrum-0.3.2 spec/lib/simulacrum/cli/parser_spec.rb
simulacrum-0.3.1 spec/lib/simulacrum/cli/parser_spec.rb