hammer_cli 0.6.1 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/config/cli_config.template.yml +4 -1
- data/doc/development_tips.md +2 -2
- data/doc/release_notes.md +13 -1
- data/lib/hammer_cli/apipie/option_definition.rb +3 -0
- data/lib/hammer_cli/defaults.rb +35 -16
- data/lib/hammer_cli/defaults_commands.rb +2 -2
- data/lib/hammer_cli/logger.rb +1 -1
- data/lib/hammer_cli/options/normalizers.rb +22 -10
- data/lib/hammer_cli/output/adapter/abstract.rb +5 -0
- data/lib/hammer_cli/output/adapter/csv.rb +5 -0
- data/lib/hammer_cli/output/adapter/table.rb +5 -0
- data/lib/hammer_cli/output/adapter/tree_structure.rb +5 -0
- data/lib/hammer_cli/output/output.rb +1 -1
- data/lib/hammer_cli/output/record_collection.rb +8 -4
- data/lib/hammer_cli/settings.rb +2 -0
- data/lib/hammer_cli/validator.rb +49 -1
- data/lib/hammer_cli/version.rb +1 -1
- data/locale/ca/LC_MESSAGES/hammer-cli.mo +0 -0
- data/locale/ca/hammer-cli.edit.po +411 -0
- data/locale/ca/hammer-cli.po +338 -0
- data/locale/ca/hammer-cli.po.time_stamp +0 -0
- data/locale/de/LC_MESSAGES/hammer-cli.mo +0 -0
- data/locale/de/hammer-cli.edit.po +16 -16
- data/locale/de/hammer-cli.po +25 -5
- data/locale/en/LC_MESSAGES/hammer-cli.mo +0 -0
- data/locale/en/hammer-cli.edit.po +46 -26
- data/locale/en/hammer-cli.po +20 -3
- data/locale/en_GB/LC_MESSAGES/hammer-cli.mo +0 -0
- data/locale/en_GB/hammer-cli.edit.po +25 -25
- data/locale/en_GB/hammer-cli.po +25 -5
- data/locale/es/LC_MESSAGES/hammer-cli.mo +0 -0
- data/locale/es/hammer-cli.po +24 -6
- data/locale/fr/LC_MESSAGES/hammer-cli.mo +0 -0
- data/locale/fr/hammer-cli.edit.po +26 -26
- data/locale/fr/hammer-cli.po +24 -6
- data/locale/hammer-cli.pot +50 -28
- data/locale/it/LC_MESSAGES/hammer-cli.mo +0 -0
- data/locale/it/hammer-cli.edit.po +9 -9
- data/locale/it/hammer-cli.po +25 -5
- data/locale/ja/LC_MESSAGES/hammer-cli.mo +0 -0
- data/locale/ja/hammer-cli.edit.po +9 -9
- data/locale/ja/hammer-cli.po +25 -5
- data/locale/ko/LC_MESSAGES/hammer-cli.mo +0 -0
- data/locale/ko/hammer-cli.edit.po +9 -9
- data/locale/ko/hammer-cli.po +25 -5
- data/locale/pt_BR/LC_MESSAGES/hammer-cli.mo +0 -0
- data/locale/pt_BR/hammer-cli.edit.po +6 -6
- data/locale/pt_BR/hammer-cli.po +25 -5
- data/locale/ru/LC_MESSAGES/hammer-cli.mo +0 -0
- data/locale/ru/hammer-cli.edit.po +31 -30
- data/locale/ru/hammer-cli.po +25 -5
- data/locale/zh_CN/LC_MESSAGES/hammer-cli.mo +0 -0
- data/locale/zh_CN/hammer-cli.edit.po +9 -9
- data/locale/zh_CN/hammer-cli.po +26 -6
- data/locale/zh_TW/LC_MESSAGES/hammer-cli.mo +0 -0
- data/locale/zh_TW/hammer-cli.edit.po +9 -9
- data/locale/zh_TW/hammer-cli.po +25 -5
- data/test/functional/defaults_test.rb +12 -0
- data/test/reports/TEST-Fields-ContainerField-display-.xml +1 -1
- data/test/reports/TEST-Fields-ContainerField-display-blank-is-allowed.xml +5 -5
- data/test/reports/TEST-Fields-ContainerField-display-blank-is-not-allowed.xml +5 -5
- data/test/reports/TEST-Fields-ContainerField.xml +1 -1
- data/test/reports/TEST-Fields-Field-display-.xml +1 -1
- data/test/reports/TEST-Fields-Field-display-blank-is-allowed.xml +3 -3
- data/test/reports/TEST-Fields-Field-display-blank-is-not-allowed.xml +3 -3
- data/test/reports/TEST-Fields-Field-hide-blank-.xml +3 -3
- data/test/reports/TEST-Fields-Field-parameters.xml +2 -2
- data/test/reports/TEST-Fields-Field.xml +4 -4
- data/test/reports/TEST-HammerCLI-AbstractCommand-build-options.xml +5 -5
- data/test/reports/TEST-HammerCLI-AbstractCommand-exception-handler.xml +4 -4
- data/test/reports/TEST-HammerCLI-AbstractCommand-logging.xml +8 -10
- data/test/reports/TEST-HammerCLI-AbstractCommand-option-builder.xml +3 -3
- data/test/reports/TEST-HammerCLI-AbstractCommand-options.xml +3 -3
- data/test/reports/TEST-HammerCLI-AbstractCommand-output.xml +7 -7
- data/test/reports/TEST-HammerCLI-AbstractCommand-subcommand-behavior-remove-subcommand.xml +3 -3
- data/test/reports/TEST-HammerCLI-AbstractCommand-subcommand-behavior-subcommand-.xml +4 -4
- data/test/reports/TEST-HammerCLI-AbstractCommand-subcommand-behavior-subcommand.xml +3 -3
- data/test/reports/TEST-HammerCLI-AbstractCommand-subcommand-behavior.xml +1 -1
- data/test/reports/TEST-HammerCLI-AbstractCommand.xml +3 -3
- data/test/reports/TEST-HammerCLI-Apipie-Command-options.xml +3 -3
- data/test/reports/TEST-HammerCLI-Apipie-Command-resource-defined.xml +2 -2
- data/test/reports/TEST-HammerCLI-Apipie-Command-setting-resources.xml +7 -7
- data/test/reports/TEST-HammerCLI-Apipie-Command.xml +2 -2
- data/test/reports/TEST-HammerCLI-Apipie-OptionBuilder-aliasing-resources.xml +4 -4
- data/test/reports/TEST-HammerCLI-Apipie-OptionBuilder-filtering-options.xml +5 -5
- data/test/reports/TEST-HammerCLI-Apipie-OptionBuilder-required-options.xml +3 -3
- data/test/reports/TEST-HammerCLI-Apipie-OptionBuilder-setting-correct-normalizers.xml +2 -8
- data/test/reports/TEST-HammerCLI-Apipie-OptionBuilder-with-hash-params.xml +3 -3
- data/test/reports/TEST-HammerCLI-Apipie-OptionBuilder-with-one-simple-param.xml +5 -5
- data/test/reports/TEST-HammerCLI-Apipie-OptionBuilder.xml +1 -1
- data/test/reports/TEST-HammerCLI-Completer-command-completion.xml +12 -12
- data/test/reports/TEST-HammerCLI-Completer-option-value-completion.xml +6 -6
- data/test/reports/TEST-HammerCLI-Completer-subcommand-completion.xml +7 -7
- data/test/reports/TEST-HammerCLI-Completer.xml +1 -1
- data/test/reports/TEST-HammerCLI-CompleterLine-line-complete.xml +10 -10
- data/test/reports/TEST-HammerCLI-CompleterLine-splitting-words.xml +12 -12
- data/test/reports/TEST-HammerCLI-CompleterLine.xml +1 -1
- data/test/reports/TEST-HammerCLI-CompleterWord-complete-.xml +9 -9
- data/test/reports/TEST-HammerCLI-CompleterWord-quote.xml +5 -5
- data/test/reports/TEST-HammerCLI-CompleterWord-quoted-.xml +4 -4
- data/test/reports/TEST-HammerCLI-CompleterWord.xml +1 -1
- data/test/reports/TEST-HammerCLI-Connection.xml +8 -8
- data/test/reports/TEST-HammerCLI-ExceptionHandler.xml +8 -8
- data/test/reports/TEST-HammerCLI-I18n.xml +3 -3
- data/test/reports/TEST-HammerCLI-MainCommand-loading-context-password.xml +3 -3
- data/test/reports/TEST-HammerCLI-MainCommand-loading-context-username.xml +3 -3
- data/test/reports/TEST-HammerCLI-MainCommand-loading-context-verbose.xml +2 -2
- data/test/reports/TEST-HammerCLI-MainCommand-loading-context.xml +1 -1
- data/test/reports/TEST-HammerCLI-MainCommand.xml +1 -1
- data/test/reports/TEST-HammerCLI-Modules-find-by-name.xml +4 -4
- data/test/reports/TEST-HammerCLI-Modules-load-a-module-module-not-found.xml +4 -4
- data/test/reports/TEST-HammerCLI-Modules-load-a-module-module-runtime-exception.xml +4 -4
- data/test/reports/TEST-HammerCLI-Modules-load-a-module-success.xml +5 -5
- data/test/reports/TEST-HammerCLI-Modules-load-a-module.xml +1 -1
- data/test/reports/TEST-HammerCLI-Modules-load-all-modules.xml +2 -4
- data/test/reports/TEST-HammerCLI-Modules-names.xml +4 -4
- data/test/reports/TEST-HammerCLI-Modules.xml +1 -1
- data/test/reports/TEST-HammerCLI-OptionBuilderContainer.0.xml +1 -5
- data/test/reports/TEST-HammerCLI-OptionBuilderContainer.xml +5 -1
- data/test/reports/TEST-HammerCLI-Options-Normalizers-abstract.xml +2 -2
- data/test/reports/TEST-HammerCLI-Options-Normalizers-bool.xml +13 -13
- data/test/reports/TEST-HammerCLI-Options-Normalizers-datetime.xml +6 -6
- data/test/reports/TEST-HammerCLI-Options-Normalizers-enum.xml +5 -5
- data/test/reports/TEST-HammerCLI-Options-Normalizers-enumlist.xml +8 -8
- data/test/reports/TEST-HammerCLI-Options-Normalizers-json-input.xml +5 -5
- data/test/reports/TEST-HammerCLI-Options-Normalizers-key-value-list.xml +6 -26
- data/test/reports/TEST-HammerCLI-Options-Normalizers-list.xml +5 -5
- data/test/reports/TEST-HammerCLI-Options-Normalizers.xml +1 -1
- data/test/reports/TEST-HammerCLI-Options-OptionDefinition-context.xml +2 -2
- data/test/reports/TEST-HammerCLI-Options-OptionDefinition-formatters.xml +3 -3
- data/test/reports/TEST-HammerCLI-Options-OptionDefinition.xml +1 -1
- data/test/reports/TEST-HammerCLI-Output-Adapter-Abstract-error-messages.xml +5 -5
- data/test/reports/TEST-HammerCLI-Output-Adapter-Abstract-messages.xml +3 -3
- data/test/reports/TEST-HammerCLI-Output-Adapter-Abstract-test-data-for-field.xml +5 -5
- data/test/reports/TEST-HammerCLI-Output-Adapter-Abstract.xml +6 -6
- data/test/reports/TEST-HammerCLI-Output-Adapter-Base-print-collection-show-ids.xml +2 -2
- data/test/reports/TEST-HammerCLI-Output-Adapter-Base-print-collection.xml +11 -11
- data/test/reports/TEST-HammerCLI-Output-Adapter-Base.xml +1 -1
- data/test/reports/TEST-HammerCLI-Output-Adapter-CSValues-print-collection-formatters.xml +3 -3
- data/test/reports/TEST-HammerCLI-Output-Adapter-CSValues-print-collection-handle-fields-with-collections.xml +4 -4
- data/test/reports/TEST-HammerCLI-Output-Adapter-CSValues-print-collection-handle-fields-with-containers.xml +3 -3
- data/test/reports/TEST-HammerCLI-Output-Adapter-CSValues-print-collection-handle-ids.xml +3 -3
- data/test/reports/TEST-HammerCLI-Output-Adapter-CSValues-print-collection.xml +3 -3
- data/test/reports/TEST-HammerCLI-Output-Adapter-CSValues-print-message.xml +3 -3
- data/test/reports/TEST-HammerCLI-Output-Adapter-CSValues.xml +1 -1
- data/test/reports/TEST-HammerCLI-Output-Adapter-Table-print-collection-column-width.xml +5 -11
- data/test/reports/TEST-HammerCLI-Output-Adapter-Table-print-collection-formatters.xml +3 -3
- data/test/reports/TEST-HammerCLI-Output-Adapter-Table-print-collection-handle-ids.xml +3 -7
- data/test/reports/TEST-HammerCLI-Output-Adapter-Table-print-collection-sort-columns.xml +2 -2
- data/test/reports/TEST-HammerCLI-Output-Adapter-Table-print-collection.xml +3 -3
- data/test/reports/TEST-HammerCLI-Output-Adapter-Table.xml +1 -1
- data/test/reports/TEST-HammerCLI-Output-Definition-empty-.xml +3 -3
- data/test/reports/TEST-HammerCLI-Output-Definition.xml +3 -3
- data/test/reports/TEST-HammerCLI-Output-Dsl-collection.xml +4 -4
- data/test/reports/TEST-HammerCLI-Output-Dsl-custom-fields.xml +3 -3
- data/test/reports/TEST-HammerCLI-Output-Dsl-fields.xml +5 -5
- data/test/reports/TEST-HammerCLI-Output-Dsl-label.xml +4 -4
- data/test/reports/TEST-HammerCLI-Output-Dsl-path-definition.xml +4 -4
- data/test/reports/TEST-HammerCLI-Output-Dsl.xml +2 -2
- data/test/reports/TEST-HammerCLI-Output-FieldFilter.xml +4 -4
- data/test/reports/TEST-HammerCLI-Output-Formatters-BooleanFormatter.xml +3 -3
- data/test/reports/TEST-HammerCLI-Output-Formatters-ColorFormatter.xml +2 -2
- data/test/reports/TEST-HammerCLI-Output-Formatters-DateFormatter.xml +3 -3
- data/test/reports/TEST-HammerCLI-Output-Formatters-FieldFormatter.xml +4 -4
- data/test/reports/TEST-HammerCLI-Output-Formatters-FormatterContainer.xml +4 -4
- data/test/reports/TEST-HammerCLI-Output-Formatters-FormatterLibrary.xml +3 -3
- data/test/reports/TEST-HammerCLI-Output-Formatters-KeyValueFormatter.xml +4 -4
- data/test/reports/TEST-HammerCLI-Output-Formatters-ListFormatter.xml +4 -4
- data/test/reports/TEST-HammerCLI-Output-Formatters-LongTextFormatter.xml +4 -4
- data/test/reports/TEST-HammerCLI-Output-Output-adapters.xml +6 -6
- data/test/reports/TEST-HammerCLI-Output-Output-data.xml +5 -5
- data/test/reports/TEST-HammerCLI-Output-Output-formatters.xml +2 -2
- data/test/reports/TEST-HammerCLI-Output-Output-messages.xml +7 -7
- data/test/reports/TEST-HammerCLI-Output-Output.xml +1 -1
- data/test/reports/TEST-HammerCLI-Output-RecordCollection.xml +4 -4
- data/test/reports/TEST-HammerCLI-Settings-load-from-paths.xml +5 -5
- data/test/reports/TEST-HammerCLI-Settings.xml +10 -10
- data/test/reports/TEST-HammerCLI-ShellHistory-loading-old-history.xml +3 -3
- data/test/reports/TEST-HammerCLI-ShellHistory-saving-history.xml +5 -5
- data/test/reports/TEST-HammerCLI-ShellHistory.xml +1 -1
- data/test/reports/TEST-MiniTest-Spec.xml +1 -1
- data/test/reports/TEST-String-camelize.xml +3 -3
- data/test/reports/TEST-String-formatting.xml +6 -6
- data/test/reports/TEST-String-indent.xml +3 -3
- data/test/reports/{TEST-HammerCLI-interactive-.xml → TEST-String-interactive-.xml} +4 -4
- data/test/reports/TEST-String.xml +1 -1
- data/test/reports/TEST-constraints-HammerCLI-Validator-AllConstraint-exist-.xml +4 -4
- data/test/reports/TEST-constraints-HammerCLI-Validator-AllConstraint.xml +1 -1
- data/test/reports/TEST-constraints-HammerCLI-Validator-AnyConstraint-exist-.xml +4 -4
- data/test/reports/TEST-constraints-HammerCLI-Validator-AnyConstraint.xml +1 -1
- data/test/reports/TEST-constraints-HammerCLI-Validator-BaseConstraint-exist-.xml +2 -2
- data/test/reports/TEST-constraints-HammerCLI-Validator-BaseConstraint-rejected.xml +4 -4
- data/test/reports/TEST-constraints-HammerCLI-Validator-BaseConstraint-required.xml +4 -4
- data/test/reports/TEST-constraints-HammerCLI-Validator-BaseConstraint.xml +1 -1
- data/test/reports/TEST-constraints.xml +1 -1
- data/test/unit/apipie/option_definition_test.rb +9 -0
- data/test/unit/defaults_test.rb +84 -22
- data/test/unit/fixtures/defaults/defaults_dashed.yml +6 -0
- data/test/unit/options/normalizers_test.rb +46 -34
- data/test/unit/output/adapter/abstract_test.rb +4 -0
- data/test/unit/output/adapter/base_test.rb +4 -0
- data/test/unit/output/adapter/csv_test.rb +4 -0
- data/test/unit/output/adapter/json_test.rb +4 -0
- data/test/unit/output/adapter/table_test.rb +19 -3
- data/test/unit/output/adapter/yaml_test.rb +4 -0
- data/test/unit/output/record_collection_test.rb +26 -0
- data/test/unit/settings_test.rb +11 -1
- data/test/unit/validator_test.rb +111 -6
- metadata +192 -247
- data/test/reports/TEST-Fields-Label-display-.xml +0 -7
- data/test/reports/TEST-Fields-Label-display-blank-is-allowed.xml +0 -15
- data/test/reports/TEST-Fields-Label-display-blank-is-not-allowed.xml +0 -15
- data/test/reports/TEST-Fields-Label.xml +0 -7
- data/test/reports/TEST-HammerCLI-Apipie-Command-reload-apipie-cache.xml +0 -11
- data/test/reports/TEST-HammerCLI-Apipie-OptionBuilder-setting-referenced-resources.xml +0 -9
- data/test/reports/TEST-HammerCLI-Apipie-OptionDefinition-referenced-resource.xml +0 -13
- data/test/reports/TEST-HammerCLI-Apipie-OptionDefinition.xml +0 -7
- data/test/reports/TEST-HammerCLI-Defaults.xml +0 -19
- data/test/reports/TEST-HammerCLI-Options-Matcher.xml +0 -17
- data/test/reports/TEST-HammerCLI-Options-Normalizers-number.xml +0 -11
- data/test/reports/TEST-HammerCLI-Options-OptionDefinition-deprecated-options.xml +0 -11
- data/test/reports/TEST-HammerCLI-Output-Adapter-Json-print-collection-show-ids.xml +0 -9
- data/test/reports/TEST-HammerCLI-Output-Adapter-Json-print-collection.xml +0 -27
- data/test/reports/TEST-HammerCLI-Output-Adapter-Json-print-message.xml +0 -11
- data/test/reports/TEST-HammerCLI-Output-Adapter-Json.xml +0 -7
- data/test/reports/TEST-HammerCLI-Output-Adapter-Yaml-print-collection-show-ids.xml +0 -9
- data/test/reports/TEST-HammerCLI-Output-Adapter-Yaml-print-collection.xml +0 -27
- data/test/reports/TEST-HammerCLI-Output-Adapter-Yaml-print-message.xml +0 -11
- data/test/reports/TEST-HammerCLI-Output-Adapter-Yaml.xml +0 -7
- data/test/reports/TEST-HammerCLI-constant-path.xml +0 -15
- data/test/reports/TEST-HammerCLI.xml +0 -7
- data/test/reports/TEST-Logging-LogEvent-filtering.xml +0 -9
- data/test/reports/TEST-Logging-LogEvent.xml +0 -7
- data/test/reports/TEST-String-constantize.xml +0 -15
- data/test/reports/TEST-String-underscore.xml +0 -13
- data/test/reports/TEST-commands-defaults-add.xml +0 -21
- data/test/reports/TEST-commands-defaults-delete.xml +0 -11
- data/test/reports/TEST-commands-defaults-list.xml +0 -11
- data/test/reports/TEST-commands-defaults-providers.xml +0 -11
- data/test/reports/TEST-commands.xml +0 -7
data/test/unit/defaults_test.rb
CHANGED
|
@@ -1,44 +1,106 @@
|
|
|
1
1
|
require File.join(File.dirname(__FILE__), 'test_helper')
|
|
2
2
|
describe HammerCLI::Defaults do
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
let(:filepath) { File.join(File.dirname(__FILE__), '/fixtures/defaults/defaults.yml') }
|
|
5
5
|
|
|
6
6
|
before(:all) do
|
|
7
|
-
settings = YAML::load(File.open(
|
|
7
|
+
settings = YAML::load(File.open(filepath))
|
|
8
8
|
|
|
9
|
-
@defaults = HammerCLI::Defaults.new(settings[:defaults],
|
|
9
|
+
@defaults = HammerCLI::Defaults.new(settings[:defaults], filepath)
|
|
10
10
|
@defaults.stubs(:write_to_file).returns true
|
|
11
11
|
end
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
13
|
+
describe '#add_defaults_to_conf' do
|
|
14
|
+
it "Should add a default param to defaults file, without a provider" do
|
|
15
|
+
defaults_result = @defaults.add_defaults_to_conf({"organization_id"=> 3}, nil)
|
|
16
|
+
assert_equal 3, defaults_result[:defaults][:organization_id][:value]
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
it "Should update dashed default when underscored default is set" do
|
|
20
|
+
defaults_result = @defaults.add_defaults_to_conf({"location-id"=> 3}, nil)
|
|
21
|
+
assert_equal 3, defaults_result[:defaults][:'location-id'][:value]
|
|
22
|
+
assert_equal nil, defaults_result[:defaults][:location_id]
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
context "dashed" do
|
|
26
|
+
let(:filepath) { File.join(File.dirname(__FILE__), '/fixtures/defaults/defaults_dashed.yml') }
|
|
27
|
+
it "Should update underscored default when dashed default is set" do
|
|
28
|
+
defaults_result = @defaults.add_defaults_to_conf({"location_id"=> 3}, nil)
|
|
29
|
+
assert_equal 3, defaults_result[:defaults][:location_id][:value]
|
|
30
|
+
assert_equal nil, defaults_result[:defaults][:'location-id']
|
|
31
|
+
end
|
|
32
|
+
end
|
|
17
33
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
34
|
+
it "Should add a default param to defaults file, with provider" do
|
|
35
|
+
defaults_result = @defaults.add_defaults_to_conf({"location_id"=>nil}, :foreman)
|
|
36
|
+
assert_equal :foreman, defaults_result[:defaults][:location_id][:provider]
|
|
37
|
+
end
|
|
21
38
|
end
|
|
22
39
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
40
|
+
describe '#delete_default_from_conf' do
|
|
41
|
+
it "Should remove default param from defaults file" do
|
|
42
|
+
defaults_result = @defaults.delete_default_from_conf(:organization_id)
|
|
43
|
+
assert_nil defaults_result[:defaults][:organization_id]
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
it "Should remove dashed default param from defaults file" do
|
|
47
|
+
defaults_result = @defaults.delete_default_from_conf(:"organization-id")
|
|
48
|
+
assert_nil defaults_result[:defaults][:organization_id]
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
context "dashed" do
|
|
52
|
+
let(:filepath) { File.join(File.dirname(__FILE__), '/fixtures/defaults/defaults_dashed.yml') }
|
|
53
|
+
it "Should remove default param from defaults file" do
|
|
54
|
+
defaults_result = @defaults.delete_default_from_conf(:organization_id)
|
|
55
|
+
assert_nil defaults_result[:defaults][:'organization-id']
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
it "Should remove dashed default param from defaults file" do
|
|
59
|
+
defaults_result = @defaults.delete_default_from_conf(:"organization-id")
|
|
60
|
+
assert_nil defaults_result[:defaults][:'organization-id']
|
|
61
|
+
end
|
|
62
|
+
end
|
|
26
63
|
end
|
|
27
64
|
|
|
28
|
-
|
|
29
|
-
|
|
65
|
+
describe '#defaults_set' do
|
|
66
|
+
it "should check if the defaults is set" do
|
|
67
|
+
assert_equal true, @defaults.defaults_set?("location_id")
|
|
68
|
+
end
|
|
30
69
|
end
|
|
31
70
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
71
|
+
|
|
72
|
+
describe '#get_defaults' do
|
|
73
|
+
it "should get the default param, without provider" do
|
|
74
|
+
assert_equal 2, @defaults.get_defaults("location_id")
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
it "should get the default param, with provider" do
|
|
78
|
+
fake_provider = mock()
|
|
79
|
+
fake_provider.stubs(:provider_name).returns(:foreman)
|
|
80
|
+
fake_provider.expects(:get_defaults).with(:organization_id).returns(3)
|
|
81
|
+
@defaults.register_provider(fake_provider)
|
|
82
|
+
assert_equal 3, @defaults.get_defaults("organization_id")
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
context 'dashed params' do
|
|
86
|
+
let(:filepath) { File.join(File.dirname(__FILE__), '/fixtures/defaults/defaults_dashed.yml') }
|
|
87
|
+
|
|
88
|
+
it "should get the default param, without provider" do
|
|
89
|
+
assert_equal 2, @defaults.get_defaults("location_id")
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
it "should get the default param, with provider" do
|
|
93
|
+
fake_provider = mock()
|
|
94
|
+
fake_provider.stubs(:provider_name).returns(:foreman)
|
|
95
|
+
fake_provider.expects(:get_defaults).with(:organization_id).returns(3)
|
|
96
|
+
@defaults.register_provider(fake_provider)
|
|
97
|
+
assert_equal 3, @defaults.get_defaults("organization_id")
|
|
98
|
+
end
|
|
99
|
+
end
|
|
38
100
|
end
|
|
39
101
|
|
|
40
102
|
it "should return empty defaults when the settings file is not present" do
|
|
41
|
-
defaults = HammerCLI::Defaults.new(nil,
|
|
103
|
+
defaults = HammerCLI::Defaults.new(nil, filepath)
|
|
42
104
|
assert_equal({}, defaults.defaults_settings)
|
|
43
105
|
end
|
|
44
106
|
|
|
@@ -52,52 +52,64 @@ describe HammerCLI::Options::Normalizers do
|
|
|
52
52
|
proc { formatter.format("a") }.must_raise ArgumentError
|
|
53
53
|
end
|
|
54
54
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
55
|
+
describe 'key=value format' do
|
|
56
|
+
it "should parse a comma separated string" do
|
|
57
|
+
formatter.format("a=1,b=2,c=3").must_equal({'a' => '1', 'b' => '2', 'c' => '3'})
|
|
58
|
+
end
|
|
58
59
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
60
|
+
it "should parse a comma separated string with spaces" do
|
|
61
|
+
formatter.format("a= 1 , b = 2 ,c =3").must_equal({'a' => '1', 'b' => '2', 'c' => '3'})
|
|
62
|
+
end
|
|
62
63
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
64
|
+
it "should parse a comma separated string with spaces using single quotes" do
|
|
65
|
+
formatter.format("a= ' 1 ' , b =' 2',c ='3'").must_equal({'a' => ' 1 ', 'b' => ' 2', 'c' => '3'})
|
|
66
|
+
end
|
|
66
67
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
68
|
+
it "should parse a comma separated string with spaces using double quotes" do
|
|
69
|
+
formatter.format("a= \" 1 \" , b =\" 2\",c =\"3\"").must_equal({'a' => ' 1 ', 'b' => ' 2', 'c' => '3'})
|
|
70
|
+
end
|
|
70
71
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
72
|
+
it "should deal with equal sign in value" do
|
|
73
|
+
formatter.format("a=1,b='2=2',c=3").must_equal({'a' => '1', 'b' => '2=2', 'c' => '3'})
|
|
74
|
+
end
|
|
74
75
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
76
|
+
it "should parse arrays" do
|
|
77
|
+
formatter.format("a=1,b=[1,2,3],c=3").must_equal({'a' => '1', 'b' => ['1', '2', '3'], 'c' => '3'})
|
|
78
|
+
end
|
|
78
79
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
80
|
+
it "should parse arrays with spaces" do
|
|
81
|
+
formatter.format("a=1,b=[1, 2, 3],c=3").must_equal({'a' => '1', 'b' => ['1', '2', '3'], 'c' => '3'})
|
|
82
|
+
end
|
|
82
83
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
84
|
+
it "should parse arrays with spaces using by single quotes" do
|
|
85
|
+
formatter.format("a=1,b=['1 1', ' 2 ', ' 3 3'],c=3").must_equal({'a' => '1', 'b' => ['1 1', ' 2 ', ' 3 3'], 'c' => '3'})
|
|
86
|
+
end
|
|
86
87
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
88
|
+
it "should parse arrays with spaces using by double quotes" do
|
|
89
|
+
formatter.format("a=1,b=[\"1 1\", \" 2 \", \" 3 3\"],c=3").must_equal({'a' => '1', 'b' => ['1 1', ' 2 ', ' 3 3'], 'c' => '3'})
|
|
90
|
+
end
|
|
90
91
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
92
|
+
it "should parse array with one item" do
|
|
93
|
+
formatter.format("a=1,b=[abc],c=3").must_equal({'a' => '1', 'b' => ['abc'], 'c' => '3'})
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
it "should parse empty array" do
|
|
97
|
+
formatter.format("a=1,b=[],c=3").must_equal({'a' => '1', 'b' => [], 'c' => '3'})
|
|
98
|
+
end
|
|
94
99
|
|
|
95
|
-
|
|
96
|
-
|
|
100
|
+
it "should parse a comma separated string 2" do
|
|
101
|
+
proc { formatter.format("a=1,b,c=3") }.must_raise ArgumentError
|
|
102
|
+
end
|
|
97
103
|
end
|
|
98
104
|
|
|
99
|
-
|
|
100
|
-
|
|
105
|
+
describe 'json format' do
|
|
106
|
+
it 'parses arrays' do
|
|
107
|
+
formatter.format('["a", "b", 1]').must_equal(['a', 'b', 1])
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
it 'parses objects' do
|
|
111
|
+
formatter.format('{"a": ["b", 1]}').must_equal({'a' => ['b', 1]})
|
|
112
|
+
end
|
|
101
113
|
end
|
|
102
114
|
end
|
|
103
115
|
|
|
@@ -20,6 +20,10 @@ describe HammerCLI::Output::Adapter::Abstract do
|
|
|
20
20
|
end
|
|
21
21
|
end
|
|
22
22
|
|
|
23
|
+
it "allows default pagination" do
|
|
24
|
+
adapter.paginate_by_default?.must_equal true
|
|
25
|
+
end
|
|
26
|
+
|
|
23
27
|
it "should filter formatters with incompatible tags" do
|
|
24
28
|
|
|
25
29
|
HammerCLI::Output::Formatters::FormatterLibrary.expects(:new).with({ :type => [] })
|
|
@@ -5,6 +5,10 @@ describe HammerCLI::Output::Adapter::Base do
|
|
|
5
5
|
let(:context) {{}}
|
|
6
6
|
let(:adapter) { HammerCLI::Output::Adapter::Base.new(context, HammerCLI::Output::Output.formatters) }
|
|
7
7
|
|
|
8
|
+
it "allows default pagination" do
|
|
9
|
+
adapter.paginate_by_default?.must_equal true
|
|
10
|
+
end
|
|
11
|
+
|
|
8
12
|
context "print_collection" do
|
|
9
13
|
|
|
10
14
|
let(:id) { Fields::Id.new(:path => [:id], :label => "Id") }
|
|
@@ -4,6 +4,10 @@ describe HammerCLI::Output::Adapter::CSValues do
|
|
|
4
4
|
|
|
5
5
|
let(:adapter) { HammerCLI::Output::Adapter::CSValues.new }
|
|
6
6
|
|
|
7
|
+
it "forbids default pagination" do
|
|
8
|
+
adapter.paginate_by_default?.must_equal false
|
|
9
|
+
end
|
|
10
|
+
|
|
7
11
|
context "print_collection" do
|
|
8
12
|
|
|
9
13
|
let(:field_name) { Fields::Field.new(:path => [:name], :label => "Name") }
|
|
@@ -5,6 +5,10 @@ describe HammerCLI::Output::Adapter::Json do
|
|
|
5
5
|
let(:context) {{}}
|
|
6
6
|
let(:adapter) { HammerCLI::Output::Adapter::Json.new(context, HammerCLI::Output::Output.formatters) }
|
|
7
7
|
|
|
8
|
+
it "forbids default pagination" do
|
|
9
|
+
adapter.paginate_by_default?.must_equal false
|
|
10
|
+
end
|
|
11
|
+
|
|
8
12
|
context "print_message" do
|
|
9
13
|
it "prints the message" do
|
|
10
14
|
params = { :a => 'Test', :b => 83 }
|
|
@@ -4,6 +4,10 @@ describe HammerCLI::Output::Adapter::Table do
|
|
|
4
4
|
|
|
5
5
|
let(:adapter) { HammerCLI::Output::Adapter::Table.new }
|
|
6
6
|
|
|
7
|
+
it "allows default pagination" do
|
|
8
|
+
adapter.paginate_by_default?.must_equal true
|
|
9
|
+
end
|
|
10
|
+
|
|
7
11
|
context "print_collection" do
|
|
8
12
|
|
|
9
13
|
let(:field_name) { Fields::Field.new(:path => [:fullname], :label => "Name") }
|
|
@@ -15,14 +19,14 @@ describe HammerCLI::Output::Adapter::Table do
|
|
|
15
19
|
[field_name]
|
|
16
20
|
}
|
|
17
21
|
|
|
18
|
-
let(:
|
|
22
|
+
let(:record) { {
|
|
19
23
|
:id => 1,
|
|
20
24
|
:firstname => "John",
|
|
21
25
|
:lastname => "Doe",
|
|
22
26
|
:fullname => "John Doe",
|
|
23
27
|
:long => "SomeVeryLongString"
|
|
24
|
-
}
|
|
25
|
-
|
|
28
|
+
} }
|
|
29
|
+
let(:data) { HammerCLI::Output::RecordCollection.new [record] }
|
|
26
30
|
let(:empty_data) { HammerCLI::Output::RecordCollection.new [] }
|
|
27
31
|
|
|
28
32
|
it "should print column name " do
|
|
@@ -33,6 +37,18 @@ describe HammerCLI::Output::Adapter::Table do
|
|
|
33
37
|
proc { adapter.print_collection(fields, data) }.must_output(/.*John Doe.*/, "")
|
|
34
38
|
end
|
|
35
39
|
|
|
40
|
+
context "pagination" do
|
|
41
|
+
it "should print pagination info if data are not complete" do
|
|
42
|
+
data = HammerCLI::Output::RecordCollection.new([record], { :total => 2, :page => 1, :per_page => 1, :subtotal => 2 })
|
|
43
|
+
proc { adapter.print_collection(fields, data) }.must_output(/.*Page 1 of 2 (use --page and --per-page for navigation)*/, "")
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
it "should print pagination info if data are complete" do
|
|
47
|
+
data = HammerCLI::Output::RecordCollection.new([record], { :total => 1, :page => 1, :per_page => 1, :subtotal => 1 })
|
|
48
|
+
proc { adapter.print_collection(fields, data) }.must_output("--------\nNAME \n--------\nJohn Doe\n--------\n", "")
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
|
|
36
52
|
context "handle ids" do
|
|
37
53
|
let(:field_id) { Fields::Id.new(:path => [:some_id], :label => "Id") }
|
|
38
54
|
let(:fields) {
|
|
@@ -5,6 +5,10 @@ describe HammerCLI::Output::Adapter::Yaml do
|
|
|
5
5
|
let(:context) {{}}
|
|
6
6
|
let(:adapter) { HammerCLI::Output::Adapter::Yaml.new(context, HammerCLI::Output::Output.formatters) }
|
|
7
7
|
|
|
8
|
+
it "forbids default pagination" do
|
|
9
|
+
adapter.paginate_by_default?.must_equal false
|
|
10
|
+
end
|
|
11
|
+
|
|
8
12
|
context "print_message" do
|
|
9
13
|
it "prints the message" do
|
|
10
14
|
params = { :a => 'Test', :b => 83 }
|
|
@@ -30,5 +30,31 @@ describe HammerCLI::Output::RecordCollection do
|
|
|
30
30
|
set.meta.must_equal metadata
|
|
31
31
|
set.meta.total.must_equal 6
|
|
32
32
|
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
describe HammerCLI::Output::MetaData do
|
|
36
|
+
|
|
37
|
+
let(:meta) { HammerCLI::Output::MetaData.new(:total => "6", :page => "2", :per_page => "3", :subtotal => "5") }
|
|
38
|
+
|
|
39
|
+
it "converts numeric metadata to numbers" do
|
|
40
|
+
meta.total.must_equal 6
|
|
41
|
+
meta.page.must_equal 2
|
|
42
|
+
meta.per_page.must_equal 3
|
|
43
|
+
meta.subtotal.must_equal 5
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
describe "pagination_set?" do
|
|
47
|
+
let(:pagination_data) { { :total => 6, :page => 2, :per_page => 3, :subtotal => 5 } }
|
|
33
48
|
|
|
49
|
+
it "can tell if pagination data are set" do
|
|
50
|
+
meta.pagination_set?.must_equal true
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
it "can tell if pagination data are not set" do
|
|
54
|
+
pagination_data.keys.each do |key|
|
|
55
|
+
meta = HammerCLI::Output::MetaData.new(pagination_data.clone.reject { |k| k == key })
|
|
56
|
+
meta.pagination_set?.must_equal false
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
end
|
|
34
60
|
end
|
data/test/unit/settings_test.rb
CHANGED
|
@@ -49,7 +49,7 @@ describe HammerCLI::Settings do
|
|
|
49
49
|
settings.dump.must_equal data
|
|
50
50
|
end
|
|
51
51
|
|
|
52
|
-
it "merges settings on second load" do
|
|
52
|
+
it "merges hash settings on second load" do
|
|
53
53
|
settings.load({:a => 1, :b => 2, :d => {:e => 4, :f => 5}})
|
|
54
54
|
settings.load({:b => 'B', :c => 'C', :d => {:e => 'E'}})
|
|
55
55
|
settings.get(:a).must_equal 1
|
|
@@ -59,6 +59,16 @@ describe HammerCLI::Settings do
|
|
|
59
59
|
settings.get(:d, :f).must_equal 5
|
|
60
60
|
end
|
|
61
61
|
|
|
62
|
+
it "merges array settings on second load" do
|
|
63
|
+
settings.load({:x => [:a, :b]})
|
|
64
|
+
settings.load({:x => [:c, :d]})
|
|
65
|
+
settings.get(:x)[0].must_equal :a
|
|
66
|
+
settings.get(:x)[1].must_equal :b
|
|
67
|
+
settings.get(:x)[2].must_equal :c
|
|
68
|
+
settings.get(:x)[3].must_equal :d
|
|
69
|
+
settings.get(:x).size.must_equal 4
|
|
70
|
+
end
|
|
71
|
+
|
|
62
72
|
it "clear wipes all settings" do
|
|
63
73
|
settings.load({:a => 1, :b => 2})
|
|
64
74
|
settings.clear
|
data/test/unit/validator_test.rb
CHANGED
|
@@ -14,8 +14,8 @@ describe "constraints" do
|
|
|
14
14
|
@option_a = 1
|
|
15
15
|
@option_b = 1
|
|
16
16
|
@option_c = 1
|
|
17
|
-
@
|
|
18
|
-
@
|
|
17
|
+
@option_unset_d = nil
|
|
18
|
+
@option_unset_e = nil
|
|
19
19
|
end
|
|
20
20
|
end
|
|
21
21
|
|
|
@@ -23,7 +23,7 @@ describe "constraints" do
|
|
|
23
23
|
FakeCmd.new
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
let(:option_names) { ["a", "b", "c", "d", "e"] }
|
|
26
|
+
let(:option_names) { ["a", "b", "c", "unset-d", "unset-e"] }
|
|
27
27
|
let(:options_def) {
|
|
28
28
|
option_names.collect{ |n| Clamp::Option::Definition.new(["-"+n, "--option-"+n], n.upcase, "Option "+n.upcase) }
|
|
29
29
|
}
|
|
@@ -107,13 +107,66 @@ describe "constraints" do
|
|
|
107
107
|
end
|
|
108
108
|
|
|
109
109
|
it "should return false when one of the options is missing" do
|
|
110
|
-
constraint = cls.new(options, [:option_a, :option_b, :option_c, :
|
|
110
|
+
constraint = cls.new(options, [:option_a, :option_b, :option_c, :option_unset_d])
|
|
111
111
|
constraint.exist?.must_equal false
|
|
112
112
|
end
|
|
113
113
|
end
|
|
114
114
|
|
|
115
115
|
end
|
|
116
116
|
|
|
117
|
+
describe HammerCLI::Validator::OneOptionConstraint do
|
|
118
|
+
let(:cls) { HammerCLI::Validator::OneOptionConstraint }
|
|
119
|
+
|
|
120
|
+
describe "exist?" do
|
|
121
|
+
it "should return true when the option exist" do
|
|
122
|
+
constraint = cls.new(options, :option_a)
|
|
123
|
+
constraint.exist?.must_equal true
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
it "should return false when the option is missing" do
|
|
127
|
+
constraint = cls.new(options, :option_unset_d)
|
|
128
|
+
constraint.exist?.must_equal false
|
|
129
|
+
end
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
describe "#rejected" do
|
|
133
|
+
it "returns nil when the option is missing" do
|
|
134
|
+
constraint = cls.new(options, :option_unset_d)
|
|
135
|
+
constraint.rejected.must_equal nil
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
it "raises exception when the option is present" do
|
|
139
|
+
constraint = cls.new(options, :option_a)
|
|
140
|
+
e = proc{ constraint.rejected }.must_raise HammerCLI::Validator::ValidationError
|
|
141
|
+
e.message.must_equal "You can't set option --option-a"
|
|
142
|
+
end
|
|
143
|
+
end
|
|
144
|
+
|
|
145
|
+
describe "#required" do
|
|
146
|
+
it "returns nil when the option exist" do
|
|
147
|
+
constraint = cls.new(options, :option_a)
|
|
148
|
+
constraint.required.must_equal nil
|
|
149
|
+
end
|
|
150
|
+
|
|
151
|
+
it "raises exception when the option is present" do
|
|
152
|
+
constraint = cls.new(options, :option_unset_d)
|
|
153
|
+
e = proc{ constraint.required }.must_raise HammerCLI::Validator::ValidationError
|
|
154
|
+
e.message.must_equal 'Option --option-unset-d is required'
|
|
155
|
+
end
|
|
156
|
+
end
|
|
157
|
+
|
|
158
|
+
describe "#value" do
|
|
159
|
+
it "returns value of the option" do
|
|
160
|
+
constraint = cls.new(options, :option_a)
|
|
161
|
+
constraint.value.must_equal 1
|
|
162
|
+
end
|
|
163
|
+
it "returns nil when the option is missing" do
|
|
164
|
+
constraint = cls.new(options, :option_unset_d)
|
|
165
|
+
constraint.value.must_equal nil
|
|
166
|
+
end
|
|
167
|
+
end
|
|
168
|
+
end
|
|
169
|
+
|
|
117
170
|
describe HammerCLI::Validator::AnyConstraint do
|
|
118
171
|
|
|
119
172
|
let(:cls) { HammerCLI::Validator::AnyConstraint }
|
|
@@ -126,17 +179,69 @@ describe "constraints" do
|
|
|
126
179
|
end
|
|
127
180
|
|
|
128
181
|
it "should return true when one of the options exist" do
|
|
129
|
-
constraint = cls.new(options, [:option_a, :
|
|
182
|
+
constraint = cls.new(options, [:option_a, :option_unset_d, :option_unset_e])
|
|
130
183
|
constraint.exist?.must_equal true
|
|
131
184
|
end
|
|
132
185
|
|
|
133
186
|
it "should return false when all the options are missing" do
|
|
134
|
-
constraint = cls.new(options, [:
|
|
187
|
+
constraint = cls.new(options, [:option_unset_d, :option_unset_e])
|
|
135
188
|
constraint.exist?.must_equal false
|
|
136
189
|
end
|
|
137
190
|
end
|
|
138
191
|
|
|
139
192
|
end
|
|
140
193
|
|
|
194
|
+
describe HammerCLI::Validator::OneOfConstraint do
|
|
141
195
|
|
|
196
|
+
let(:cls) { HammerCLI::Validator::OneOfConstraint }
|
|
197
|
+
|
|
198
|
+
it "raises exception when nothing to check is set" do
|
|
199
|
+
e = proc{ cls.new(options, []) }.must_raise RuntimeError
|
|
200
|
+
e.message.must_equal 'Set at least one expected option'
|
|
201
|
+
end
|
|
202
|
+
|
|
203
|
+
describe "#exist?" do
|
|
204
|
+
it "should return true when one of the options exist" do
|
|
205
|
+
constraint = cls.new(options, [:option_a, :option_unset_d, :option_unset_e])
|
|
206
|
+
constraint.exist?.must_equal true
|
|
207
|
+
end
|
|
208
|
+
|
|
209
|
+
it "should return false when the option isn't present" do
|
|
210
|
+
constraint = cls.new(options, [:option_unset_d, :option_unset_e])
|
|
211
|
+
constraint.exist?.must_equal false
|
|
212
|
+
end
|
|
213
|
+
|
|
214
|
+
it "should return false when more than one of the options is present" do
|
|
215
|
+
constraint = cls.new(options, [:option_a, :option_b])
|
|
216
|
+
constraint.exist?.must_equal false
|
|
217
|
+
end
|
|
218
|
+
end
|
|
219
|
+
|
|
220
|
+
describe "#rejected" do
|
|
221
|
+
it "raises not implemented exception" do
|
|
222
|
+
constraint = cls.new(options, [:option_a, :option_unset_d])
|
|
223
|
+
e = proc{ constraint.rejected }.must_raise NotImplementedError
|
|
224
|
+
e.message.must_equal '#rejected is unsupported for OneOfConstraint'
|
|
225
|
+
end
|
|
226
|
+
end
|
|
227
|
+
|
|
228
|
+
describe "#required" do
|
|
229
|
+
it "returns nil when one of the options exist" do
|
|
230
|
+
constraint = cls.new(options, [:option_a, :option_unset_d, :option_unset_e])
|
|
231
|
+
constraint.required.must_equal nil
|
|
232
|
+
end
|
|
233
|
+
|
|
234
|
+
it "raises exception when none of the options is present" do
|
|
235
|
+
constraint = cls.new(options, [:option_unset_d, :option_unset_e])
|
|
236
|
+
e = proc{ constraint.required }.must_raise HammerCLI::Validator::ValidationError
|
|
237
|
+
e.message.must_equal 'One of options --option-unset-d, --option-unset-e is required'
|
|
238
|
+
end
|
|
239
|
+
|
|
240
|
+
it "raises exception when more than one of the options is present" do
|
|
241
|
+
constraint = cls.new(options, [:option_a, :option_b])
|
|
242
|
+
e = proc{ constraint.required }.must_raise HammerCLI::Validator::ValidationError
|
|
243
|
+
e.message.must_equal 'Only one of options --option-a, --option-b can be set'
|
|
244
|
+
end
|
|
245
|
+
end
|
|
246
|
+
end
|
|
142
247
|
end
|