Sha256: a07d1403a34114964d08770b44a65bfafaa0066a615e1b44f9e1da5384c3a5c1

Contents?: true

Size: 1.7 KB

Versions: 11

Compression:

Stored size: 1.7 KB

Contents

require 'test_helper'

# All raised errors tested here

describe Slop::MissingArgument do
  it "raises when an argument is missing" do
    opts = Slop::Options.new
    opts.string "-n", "--name"
    assert_raises(Slop::MissingArgument) { opts.parse %w(--name) }

    #Assert returns the argument question
    begin
      opts.parse %w(--name)
    rescue Slop::MissingArgument => e
      assert_equal(e.flags, ["-n", "--name"])
    end
  end

  it "does not raise when errors are suppressed" do
    opts = Slop::Options.new(suppress_errors: true)
    opts.string "-n", "--name"
    opts.parse %w(--name)
  end

  it "does not raise if '--' appears as the first argument" do
    opts = Slop::Options.new
    opts.string "-n", "--name"
    opts.parse %w(-- --name)
  end
end

describe Slop::UnknownOption do
  it "raises when an option is unknown" do
    opts = Slop::Options.new
    opts.string "-n", "--name"
    assert_raises(Slop::UnknownOption) { opts.parse %w(--foo) }

    #Assert returns the unknown option in question
    begin
      opts.parse %w(--foo)
    rescue Slop::UnknownOption => e
      assert_equal(e.flag, "--foo")
    end
  end

  it "does not raise when errors are suppressed" do
    opts = Slop::Options.new(suppress_errors: true)
    opts.string "-n", "--name"
    opts.parse %w(--foo)
  end
end

describe Slop::MissingRequiredOption do
  it "raises when a required option is missing" do
    opts = Slop::Options.new
    opts.string "-n", "--name", required: true
    assert_raises(Slop::MissingRequiredOption) { opts.parse [] }
  end

  it "does not raise when errors are suppressed" do
    opts = Slop::Options.new(suppress_errors: true)
    opts.string "-n", "--name", required: true
    opts.parse []
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
slop-4.9.3 test/error_test.rb
slop-4.9.2 test/error_test.rb
slop-4.9.1 test/error_test.rb
slop-4.9.0 test/error_test.rb
slop-4.8.2 test/error_test.rb
slop-4.8.1 test/error_test.rb
slop-4.8.0 test/error_test.rb
slop-4.7.0 test/error_test.rb
slop-4.6.2 test/error_test.rb
slop-4.6.1 test/error_test.rb
slop-4.6.0 test/error_test.rb