Sha256: dc25abccc8aad2dddbad2c3cf055d227ced2d88d35730aabb9f54f8a6a9692e7

Contents?: true

Size: 1.35 KB

Versions: 15

Compression:

Stored size: 1.35 KB

Contents

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

describe Thor::Argument do

  def argument(name, options={})
    @argument ||= Thor::Argument.new(name, options)
  end

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

    it "raises an error if type is unknown" do
      lambda {
        argument(:task, :type => :unknown)
      }.should 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, :type => :string, :default => "bar", :required => true)
      }.should 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, :type => :string).usage.should == "FOO"
    end

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

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

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

Version data entries

15 entries across 13 versions & 5 rubygems

Version Path
challah-rolls-0.2.0 vendor/bundle/gems/thor-0.15.4/spec/parser/argument_spec.rb
challah-rolls-0.2.0 vendor/bundle/gems/challah-0.8.0.pre/vendor/bundle/gems/thor-0.15.4/spec/parser/argument_spec.rb
librarian-puppet-0.9.4 vendor/gems/ruby/1.8/gems/thor-0.15.4/spec/parser/argument_spec.rb
challah-rolls-0.1.0 vendor/bundle/gems/thor-0.15.4/spec/parser/argument_spec.rb
challah-rolls-0.1.0 vendor/bundle/gems/challah-0.8.0.pre/vendor/bundle/gems/thor-0.15.4/spec/parser/argument_spec.rb
challah-0.8.0.pre vendor/bundle/gems/thor-0.15.4/spec/parser/argument_spec.rb
challah-0.7.1 vendor/bundle/gems/thor-0.15.4/spec/parser/argument_spec.rb
challah-0.7.0 vendor/bundle/gems/thor-0.15.4/spec/parser/argument_spec.rb
challah-0.7.0.pre2 vendor/bundle/gems/thor-0.15.4/spec/parser/argument_spec.rb
librarian-puppet-0.9.3 vendor/gems/ruby/1.8/gems/thor-0.15.4/spec/parser/argument_spec.rb
challah-0.7.0.pre vendor/bundle/gems/thor-0.15.4/spec/parser/argument_spec.rb
challah-0.6.2 vendor/bundle/gems/thor-0.15.4/spec/parser/argument_spec.rb
thor-0.15.4 spec/parser/argument_spec.rb
initforthe-cookies-0.0.1 vendor/bundle/gems/thor-0.15.3/spec/parser/argument_spec.rb
thor-0.15.3 spec/parser/argument_spec.rb