Sha256: e965f0000cb8b92b99ef291652cdbd0b91d57f4e3f4c6f2d09ecfb09fe2b04aa

Contents?: true

Size: 1.58 KB

Versions: 25

Compression:

Stored size: 1.58 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
      expect {
        argument(nil)
      }.to raise_error(ArgumentError, "Argument name can't be nil.")
    end

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

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

    it "raises an error if enum isn't an array" do
      expect {
        argument(:task, :type => :string, :enum => "bar")
      }.to raise_error(ArgumentError, "An argument cannot have an enum other than an array.")
    end
  end

  describe "#usage" do
    it "returns usage for string types" do
      expect(argument(:foo, :type => :string).usage).to eq("FOO")
    end

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

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

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

Version data entries

25 entries across 21 versions & 8 rubygems

Version Path
active_mailer-0.0.10 test/fixtures/dummyapp_rails_3.2/vendor/bundle/ruby/1.9.1/gems/thor-0.17.0/spec/parser/argument_spec.rb
judge-2.0.5 vendor/bundle/ruby/2.1.0/gems/thor-0.17.0/spec/parser/argument_spec.rb
torquebox-console-0.3.0 vendor/bundle/jruby/1.9/gems/thor-0.17.0/spec/parser/argument_spec.rb
active_mailer-0.0.9 test/fixtures/dummyapp_rails_3.2/vendor/bundle/ruby/1.9.1/gems/thor-0.17.0/spec/parser/argument_spec.rb
active_mailer-0.0.8 test/fixtures/dummyapp_rails_3.2/vendor/bundle/ruby/1.9.1/gems/thor-0.17.0/spec/parser/argument_spec.rb
active_mailer-0.0.7 test/fixtures/dummyapp_rails_3.2/vendor/bundle/ruby/1.9.1/gems/thor-0.17.0/spec/parser/argument_spec.rb
active_mailer-0.0.6 test/fixtures/dummyapp_rails_3.2/vendor/bundle/ruby/1.9.1/gems/thor-0.17.0/spec/parser/argument_spec.rb
font-awesome-rails-3.1.1.2 vendor/ruby/2.0.0/gems/thor-0.17.0/spec/parser/argument_spec.rb
font-awesome-rails-3.1.1.2 vendor/ruby/1.9.1/gems/thor-0.17.0/spec/parser/argument_spec.rb
font-awesome-rails-3.1.1.1 vendor/ruby/1.9.1/gems/thor-0.17.0/spec/parser/argument_spec.rb
font-awesome-rails-3.1.1.1 vendor/ruby/2.0.0/gems/thor-0.17.0/spec/parser/argument_spec.rb
librarian-puppet-0.9.9 vendor/gems/ruby/1.9.1/gems/thor-0.17.0/spec/parser/argument_spec.rb
torquebox-console-0.2.5 vendor/bundle/ruby/1.8/gems/thor-0.17.0/spec/parser/argument_spec.rb
torquebox-console-0.2.5 vendor/bundle/jruby/1.9/gems/thor-0.17.0/spec/parser/argument_spec.rb
torquebox-console-0.2.4 vendor/bundle/jruby/1.9/gems/thor-0.17.0/spec/parser/argument_spec.rb
torquebox-console-0.2.4 vendor/bundle/ruby/1.8/gems/thor-0.17.0/spec/parser/argument_spec.rb
torquebox-console-0.2.3 vendor/bundle/jruby/1.9/gems/thor-0.17.0/spec/parser/argument_spec.rb
active_mailer-0.0.5 test/fixtures/dummyapp_rails_3.2/vendor/bundle/ruby/1.9.1/gems/thor-0.17.0/spec/parser/argument_spec.rb
active_mailer-0.0.4 test/fixtures/dummyapp_rails_3.2/vendor/bundle/ruby/1.9.1/gems/thor-0.17.0/spec/parser/argument_spec.rb
active_mailer-0.0.3 test/fixtures/dummyapp_rails_3.2/vendor/bundle/ruby/1.9.1/gems/thor-0.17.0/spec/parser/argument_spec.rb