inspec/test/unit/base_cli_test.rb

48 lines
1.5 KiB
Ruby
Raw Normal View History

# 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 = { format: 'json', backend_cache: false }
Inspec::BaseCLI.stubs(:default_options).returns(default_options)
opts = cli.send(:merged_opts)
expected = { 'format' => 'json', 'backend_cache' => false }
opts.must_equal expected
end
it 'json-config options override cli defaults' do
default_options = { 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)
expected = { 'format' => 'json', 'backend_cache' => true }
opts.must_equal expected
end
it 'cli options override json-config and default' do
default_options = { 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)
expected = { 'format' => 'json', 'backend_cache' => true }
opts.must_equal expected
end
end
end