Sha256: ab2af7809a5d733ff02a25a4260d2cea2066f7d92565ab28001ff332a0e05e1c

Contents?: true

Size: 1.13 KB

Versions: 9

Compression:

Stored size: 1.13 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
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

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
slop-4.5.0 test/error_test.rb
slop-4.4.3 test/error_test.rb
slop-4.4.2 test/error_test.rb
slop-4.4.1 test/error_test.rb
slop-4.4.0 test/error_test.rb
slop-4.3.0 test/error_test.rb
slop-4.2.1 test/error_test.rb
slop-4.2.0 test/error_test.rb
slop-4.1.0 test/error_test.rb