Sha256: 871d166d5da382280ea2e3659454465ac85c30360dd2fc79ab82c64cdf7d6cc5

Contents?: true

Size: 1.55 KB

Versions: 44

Compression:

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

    it "raises an error if type is unknown" do
      expect do
        argument(:command, :type => :unknown)
      end.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 do
        argument(:command, :type => :string, :default => "bar", :required => true)
      end.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 do
        argument(:command, :type => :string, :enum => "bar")
      end.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

44 entries across 41 versions & 19 rubygems

Version Path
abaci-0.3.0 vendor/bundle/gems/thor-0.19.1/spec/parser/argument_spec.rb
gameboard-3.1.0 vendor/bundle/ruby/2.3.0/gems/thor-0.19.1/spec/parser/argument_spec.rb
gameboard-3.0.0 vendor/bundle/ruby/2.3.0/gems/thor-0.19.1/spec/parser/argument_spec.rb
cvss-suite-1.0.8 vendor/cache/ruby/2.2.0/gems/thor-0.19.1/spec/parser/argument_spec.rb
tdiary-5.0.2 vendor/bundle/gems/thor-0.19.1/spec/parser/argument_spec.rb
tdiary-5.0.1 vendor/bundle/gems/thor-0.19.1/spec/parser/argument_spec.rb
cvss-suite-1.0.7 vendor/cache/ruby/2.2.0/gems/thor-0.19.1/spec/parser/argument_spec.rb
ish_lib_manager-0.0.1 test/dummy/vendor/bundle/ruby/2.3.0/gems/thor-0.19.1/spec/parser/argument_spec.rb
cvss-suite-1.0.6 vendor/cache/ruby/2.2.0/gems/thor-0.19.1/spec/parser/argument_spec.rb
cvss-suite-1.0.5 vendor/cache/ruby/2.2.0/gems/thor-0.19.1/spec/parser/argument_spec.rb
cvss-suite-1.0.4 vendor/cache/ruby/2.2.0/gems/thor-0.19.1/spec/parser/argument_spec.rb
cvss-suite-1.0.3 vendor/cache/ruby/2.2.0/gems/thor-0.19.1/spec/parser/argument_spec.rb
cvss-suite-1.0.2 vendor/cache/ruby/2.2.0/gems/thor-0.19.1/spec/parser/argument_spec.rb
cvss-suite-1.0.1 vendor/cache/ruby/2.2.0/gems/thor-0.19.1/spec/parser/argument_spec.rb
cvss-suite-1.0.0 vendor/cache/ruby/2.2.0/gems/thor-0.19.1/spec/parser/argument_spec.rb
honeybadger-2.4.0 vendor/gems/ruby/1.9.1/gems/thor-0.19.1/spec/parser/argument_spec.rb
honeybadger-2.4.0 vendor/gems/ruby/2.2.0/gems/thor-0.19.1/spec/parser/argument_spec.rb
honeybadger-2.4.0 vendor/gems/ruby/2.1.0/gems/thor-0.19.1/spec/parser/argument_spec.rb
angular-rails4-templates-0.4.1 vendor/ruby/2.1.0/gems/thor-0.19.1/spec/parser/argument_spec.rb
vagrant-unbundled-1.8.1.1 vendor/bundle/ruby/2.3.0/gems/thor-0.19.1/spec/parser/argument_spec.rb