Sha256: 88e8cf89c538b10a8e99b8082fc2a1c6876d3ee92d28ae5a72c91f1261370cc1

Contents?: true

Size: 1.33 KB

Versions: 29

Compression:

Stored size: 1.33 KB

Contents

require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
require 'thor/parser'

describe Thor::Argument do

  def argument(name, type=:string, default=nil, required=nil)
    @argument ||= Thor::Argument.new(name, nil, required || default.nil?, type, default)
  end

  describe "errors" do
    it "raises an error if name is not supplied" do
      lambda {
        argument(nil)
      }.must raise_error(ArgumentError, "Argument name can't be nil.")
    end

    it "raises an error if type is unknown" do
      lambda {
        argument(:task, :unknown)
      }.must raise_error(ArgumentError, "Type :unknown is not valid for arguments.")
    end

    it "raises an error if argument is required and have default values" do
      lambda {
        argument(:task, :string, "bar", true)
      }.must raise_error(ArgumentError, "An argument cannot be required and have default value.")
    end
  end

  describe "#usage" do
    it "returns usage for string types" do
      argument(:foo, :string).usage.must == "FOO"
    end

    it "returns usage for numeric types" do
      argument(:foo, :numeric).usage.must == "N"
    end

    it "returns usage for array types" do
      argument(:foo, :array).usage.must == "one two three"
    end

    it "returns usage for hash types" do
      argument(:foo, :hash).usage.must == "key:value"
    end
  end
end

Version data entries

29 entries across 29 versions & 5 rubygems

Version Path
wycats-thor-0.11.5 spec/parser/argument_spec.rb
puppet-module-0.3.4 vendor/thor-852190ae/spec/parser/argument_spec.rb
puppet-module-0.3.3 vendor/thor-852190ae/spec/parser/argument_spec.rb
puppet-module-0.3.2 vendor/thor-852190ae/spec/parser/argument_spec.rb
thor-0.14.4 spec/parser/argument_spec.rb
thor-0.14.3 spec/parser/argument_spec.rb
thor-0.14.2 spec/parser/argument_spec.rb
thor-0.14.1 spec/parser/argument_spec.rb
angry_mob-0.1.0 vendor/thor/spec/parser/argument_spec.rb
thor-0.14.0 spec/parser/argument_spec.rb
thor-0.13.8 spec/parser/argument_spec.rb
thor-0.13.7 spec/parser/argument_spec.rb
puppet-module-0.3.0 vendor/thor-852190ae/spec/parser/argument_spec.rb
thor-0.13.6 spec/parser/argument_spec.rb
thor-0.13.5 spec/parser/argument_spec.rb
thor-0.13.4 spec/parser/argument_spec.rb
thor-0.13.3 spec/parser/argument_spec.rb
thor-0.13.2 spec/parser/argument_spec.rb
thor-0.13.1 spec/parser/argument_spec.rb
thor-0.13.0 spec/parser/argument_spec.rb