require 'spec_helper' module DistribBuilder module Versioner describe ArgumentProcessor do it "does take '-s all' argument", broken: true do processor = described_class.new(["-s all"]) expect( processor.show ).to be_nil processor.parse expect( processor.show ).to eq(:all) end it "does take '--show all' argument", broken: true do processor = described_class.new(["--show all"]) expect( processor.show ).to be_nil processor.parse expect( processor.show ).to eq(:all) end it "does take '-s version' argument", broken: true do processor = described_class.new(["-s version"]) expect( processor.show ).to be_nil processor.parse expect( processor.show ).to eq(:version) end it "does take '--show version' argument", broken: true do processor = described_class.new(["--show version"]) expect( processor.show ).to be_nil processor.parse expect( processor.show ).to eq(:version) end it "does take '-s build' argument", broken: true do processor = described_class.new(["-s build"]) expect( processor.show ).to be_nil processor.parse expect( processor.show ).to eq(:build) end it "does take '--show build' argument", broken: true do processor = described_class.new(["--show build"]) expect( processor.show ).to be_nil processor.parse expect( processor.show ).to eq(:build) end it "does take '-i' argument" do processor = described_class.new(["-i"]) expect( processor.increment_build ).to be(false) processor.parse expect( processor.increment_build ).to be(true) end it "does take '--icrement-build' argument" do processor = described_class.new(["--increment-build"]) expect( processor.increment_build ).to be(false) processor.parse expect( processor.increment_build ).to be(true) end it "does take '-d' argument" do processor = described_class.new(["-d"]) expect( processor.decrement_build ).to be(false) processor.parse expect( processor.decrement_build ).to be(true) end it "does take '--decrement-build' argument" do processor = described_class.new(["--decrement-build"]) expect( processor.decrement_build ).to be(false) processor.parse expect( processor.decrement_build ).to be(true) end it "does take '--setup-version 1.2.3' argument", broken: true do processor = described_class.new(["--setup-version 1.2.3"]) expect( processor.setup_version ).to be_nil processor.parse expect( processor.setup_version ).to eq("1.2.3") end it "does take '--setup-build 1' argument", broken: true do processor = described_class.new(["--setup-build 1"]) expect( processor.setup_build ).to be_nil processor.parse expect( processor.setup_build ).to eq("1") end context "#validate_options" do let(:processor) { described_class.new([], Logger.new) } it "does raise an error if --setup-build argument present but nil" do allow( processor ).to receive(:option_keys).and_return("setup-build") expect( processor.logger ).to receive(:incorrect_setup_build).with(nil) processor.validate_options end it "does raise an error if --setup-build present but non a digit" do allow( processor ).to receive(:option_keys).and_return("setup-build") allow( processor ).to receive(:setup_build).and_return("t") expect( processor.logger ).to receive(:incorrect_setup_build).with("t") processor.validate_options end it "does be OK if --setup-build present and a digit" do allow( processor ).to receive(:option_keys).and_return("setup-build") allow( processor ).to receive(:setup_build).and_return("123") processor.validate_options end it "does raise an error if --setup-version argument present but nil" do allow( processor ).to receive(:option_keys).and_return("setup-version") expect( processor.logger ).to receive(:incorrect_setup_version).with(nil) processor.validate_options end it "does raise an error if --setup-version present but non a valid string" do allow( processor ).to receive(:option_keys).and_return("setup-version") allow( processor ).to receive(:setup_version).and_return("t") expect( processor.logger ).to receive(:incorrect_setup_version).with("t") processor.validate_options end it "does be OK if --setup-version present and a digit" do allow( processor ).to receive(:option_keys).and_return("setup-version") allow( processor ).to receive(:setup_version).and_return("1.2.3") processor.validate_options end end end end end