Sha256: a5fdd36a74f1f8abd5f04009bacc9e8dd04422773f8e3d52d52351aebf3d8e3c

Contents?: true

Size: 1.52 KB

Versions: 5

Compression:

Stored size: 1.52 KB

Contents

require_relative '../test_helper'

describe HammerCLI::Options::OptionFamily do
  let(:family) do
    HammerCLI::Options::OptionFamily.new(
      deprecated: { '--test-one' => 'Use --test-two instead' }
    )
  end
  let(:first_option) { HammerCLI::Apipie::OptionDefinition.new("--test-one", '', '') }
  let(:second_option) { HammerCLI::Apipie::OptionDefinition.new("--test-two", '', '') }
  let(:third_option) { HammerCLI::Apipie::OptionDefinition.new("--test-three", '', '') }
  let(:full_family) do
    family.parent('--test-one', '', 'Test').family.child('--test-two', '', '').family
  end

  describe 'switch' do
    it 'returns nil if family is empty' do
      _(family.switch).must_be_nil
    end

    it 'returns parent switch if family has no children' do
      family.parent('--test-one', '', '')
      _(family.switch).must_equal '--test-one'
    end

    it 'returns switch based on members' do
      _(full_family.switch).must_equal '--test[-two|-one]'
    end
  end

  describe 'description' do
    it 'returns parent description if nothing passed to initializer' do
      _(full_family.description).must_equal full_family.head.help[1]
    end

    it 'returns description with deprecation message' do
      _(full_family.description).must_equal 'Test (--test-one is deprecated: Use --test-two instead)'
    end
  end

  describe 'adopt' do
    it 'appends an option to children' do
      full_family.adopt(third_option)
      _(full_family.children.size).must_equal 2
      _(third_option.family).must_equal full_family
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
hammer_cli-3.13.0 test/unit/options/option_family_test.rb
hammer_cli-3.12.0 test/unit/options/option_family_test.rb
hammer_cli-3.10.0 test/unit/options/option_family_test.rb
hammer_cli-3.9.0 test/unit/options/option_family_test.rb
hammer_cli-3.8.0 test/unit/options/option_family_test.rb