Sha256: 7ea55f05f2c24dece7e5a00bea0444b0806037825b539544067ef4412ab0c61c

Contents?: true

Size: 1.74 KB

Versions: 33

Compression:

Stored size: 1.74 KB

Contents

require 'test_helper'

class TC_testFlag < Clean::Test::TestCase
  include TestHelper

  def test_basics_simple
    Given flag_with_names(:f)
    Then attributes_should_be_set
    And name_should_be(:f)
    And aliases_should_be(nil)
  end

  def test_basics_kinda_complex
    Given flag_with_names([:f])
    Then attributes_should_be_set
    And name_should_be(:f)
    And aliases_should_be(nil)
  end

  def test_basics_complex
    Given flag_with_names([:f,:file,:filename])
    Then attributes_should_be_set
    And name_should_be(:f)
    And aliases_should_be([:file,:filename])
    And {
      assert_equal ["-f VAL","--file VAL","--filename VAL",/foobar/,Float],@flag.arguments_for_option_parser
    }
  end

  def test_flag_can_mask_its_value
    Given flag_with_names(:password, :mask => true)
    Then attributes_should_be_set(:safe_default_value => "********")
  end

  def flag_with_names(names,options = {})
    lambda do
      @options = {
        :desc => 'Filename',
        :long_desc => 'The Filename',
        :arg_name => 'file',
        :default_value => '~/.blah.rc',
        :safe_default_value => '~/.blah.rc',
        :must_match => /foobar/,
        :type => Float,
      }.merge(options)
      @flag = GLI::Flag.new(names,@options)
      @cli_option = @flag
    end
  end

  def attributes_should_be_set(override={})
    lambda {
      expected = @options.merge(override)
      assert_equal(expected[:desc],@flag.description)
      assert_equal(expected[:long_desc],@flag.long_description)
      assert_equal(expected[:default_value],@flag.default_value)
      assert_equal(expected[:safe_default_value],@flag.safe_default_value)
      assert_equal(expected[:must_match],@flag.must_match)
      assert_equal(expected[:type],@flag.type)
    }
  end
end

Version data entries

33 entries across 33 versions & 2 rubygems

Version Path
gli-2.19.2 test/tc_flag.rb
gli-2.19.1 test/tc_flag.rb
gli-2.19.0 test/tc_flag.rb
gli-2.18.2 test/tc_flag.rb
gli-2.18.1 test/tc_flag.rb
gli-2.18.0 test/tc_flag.rb
gli-2.17.2 test/tc_flag.rb
gli-2.17.1 test/tc_flag.rb
gli-2.17.0 test/tc_flag.rb
gli-2.16.1 test/tc_flag.rb
gli-2.16.0 test/tc_flag.rb
gli-2.15.0 test/tc_flag.rb
gli-2.14.0 test/tc_flag.rb
gli-2.13.4 test/tc_flag.rb
gli-2.13.3 test/tc_flag.rb
gli-2.13.2 test/tc_flag.rb
gli-2.13.1 test/tc_flag.rb
gli-2.13.0 test/tc_flag.rb
gli-2.12.3 test/tc_flag.rb
gli-2.12.2 test/tc_flag.rb