inspec/test/unit/base_cli_test.rb
Jared Quick 72af4a96f1 Update default cli options to be per command. (#2378)
Signed-off-by: Jared Quick <jquick@chef.io>
2017-12-07 13:19:36 +01:00

56 lines
1.8 KiB
Ruby

# encoding: utf-8
# copyright: 2017, Chef Software Inc.
require 'helper'
require 'thor'
describe 'BaseCLI' do
let(:cli) { Inspec::BaseCLI.new }
describe 'merge_options' do
it 'cli defaults populate correctly' do
default_options = { exec: { format: 'json', backend_cache: false }}
Inspec::BaseCLI.stubs(:default_options).returns(default_options)
opts = cli.send(:merged_opts, :exec)
expected = { 'format' => 'json', 'backend_cache' => false }
opts.must_equal expected
end
it 'json-config options override cli defaults' do
default_options = { exec: { format: 'json', backend_cache: false }}
Inspec::BaseCLI.stubs(:default_options).returns(default_options)
parsed_json = { 'backend_cache' => true }
cli.expects(:options_json).returns(parsed_json)
opts = cli.send(:merged_opts, :exec)
expected = { 'format' => 'json', 'backend_cache' => true }
opts.must_equal expected
end
it 'cli options override json-config and default' do
default_options = { exec: { format: 'json', backend_cache: false }}
Inspec::BaseCLI.stubs(:default_options).returns(default_options)
parsed_json = { 'backend_cache' => false }
cli.expects(:options_json).returns(parsed_json)
cli_options = { 'backend_cache' => true }
cli.instance_variable_set(:@options, cli_options)
opts = cli.send(:merged_opts, :exec)
expected = { 'format' => 'json', 'backend_cache' => true }
opts.must_equal expected
end
it 'make sure shell does not get exec defaults' do
default_options = { exec: { format: 'json', backend_cache: false }}
Inspec::BaseCLI.stubs(:default_options).returns(default_options)
opts = cli.send(:merged_opts)
expected = {}
opts.must_equal expected
end
end
end