Sha256: 6add2de63a99a687c4fd244a33bacdb7559d22f5dab3f13ff6c8914cfdc54efd

Contents?: true

Size: 1.54 KB

Versions: 8

Compression:

Stored size: 1.54 KB

Contents

require '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(:command, :type => :unknown)
      }.to raise_error(ArgumentError, "Type :unknown is not valid for arguments.")
    end

    it "raises an error if argument is required and has default values" do
      expect {
        argument(:command, :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(:command, :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

8 entries across 8 versions & 3 rubygems

Version Path
acquia_toolbelt-2.4.1 lib/vendor/thor/spec/parser/argument_spec.rb
acquia_toolbelt-2.4.0 lib/vendor/thor/spec/parser/argument_spec.rb
acquia_toolbelt-2.3.2 lib/vendor/thor/spec/parser/argument_spec.rb
acquia_toolbelt-2.3.1 lib/vendor/thor/spec/parser/argument_spec.rb
acquia_toolbelt-2.0.1 lib/vendor/thor/spec/parser/argument_spec.rb
acquia_toolbelt-2.0.0 lib/vendor/thor/spec/parser/argument_spec.rb
thor_dleavitt-0.18.1 spec/parser/argument_spec.rb
thor-dleavitt-0.18.1 spec/parser/argument_spec.rb