inspec/test/unit/dsl/other_keywords_test.rb
Jared Quick 9930e40a76 Add new "reporter" system (replacement for "formatters"), support multiple reporters per run (#2464)
* Formatter and reporter refactor.

Signed-off-by: Jared Quick <jquick@chef.io>

* Add exception and backtrace to json-min report.

Signed-off-by: Jared Quick <jquick@chef.io>

* Add sha to json-min and include generator version for json profile.

Signed-off-by: Jared Quick <jquick@chef.io>

* Fix deprecated typo and add fallback for cli resource title.

Signed-off-by: Jared Quick <jquick@chef.io>

* Update to build json report and clean up cli logic.

Signed-off-by: Jared Quick <jquick@chef.io>

* Add tests for json reporter.

Signed-off-by: Jared Quick <jquick@chef.io>

* Add cli suppress_log_output? and a fallback for invalid reporter type.

Signed-off-by: Jared Quick <jquick@chef.io>

* Update suppress_log_output? to check if we are outputting to stdout.

Signed-off-by: Jared Quick <jquick@chef.io>

* Update reporter cli optoins to work with json_config.

Signed-off-by: Jared Quick <jquick@chef.io>

* Refactor some safe-navigation and variable names.

Signed-off-by: Jared Quick <jquick@chef.io>

* Add thor banner to show reporter file output syntax.

Signed-off-by: Jared Quick <jquick@chef.io>
2018-02-08 10:06:58 +01:00

63 lines
1.8 KiB
Ruby

# encoding: utf-8
# author: Dominik Richter
# author: Christoph Hartmann
require 'helper'
require 'inspec/runner_mock'
describe 'inspec keyword' do
def load(content)
runner = Inspec::Runner.new({backend: 'mock', test_collector: Inspec::RunnerMock.new})
runner.eval_with_virtual_profile(content)
end
def load_in_profile(cmd)
MockLoader.load_profile('complete-profile').runner_context.load(cmd)
end
it 'is a vailable as a global keyword' do
load('inspec') # wont raise anything
end
it 'is a vailable inside of control blocks' do
load('control 1 do inspec end') # wont raise anything
end
it 'provides version information' do
load('inspec.version').must_equal Inspec::VERSION
end
it 'is associated with resources' do
i = load('os.inspec')
i.wont_be_nil
i.backend.must_be_kind_of Train::Transports::Mock::Connection
end
it 'prints a nice to_s' do
load('inspec').to_s.must_equal 'Inspec::Backend::Class'
end
it 'prints a nice inspect line' do
load('inspec').inspect.must_equal 'Inspec::Backend::Class @transport=Train::Transports::Mock::Connection'
end
describe 'inspec.profile.files' do
it 'lists an empty array when calling #files without any files loaded' do
load('inspec.profile.files').must_equal([])
end
it 'lists all profile files when calling #files' do
load_in_profile('inspec.profile.files').must_equal %w{a_sub_dir/sub_items.conf items.conf}
end
end
describe 'inspec.profile.file' do
it 'raises an error if a file was not found' do
proc { load('inspec.profile.file("test")') }.must_raise RuntimeError
end
it 'provides file contents when calling file(...)' do
load_in_profile('inspec.profile.file("items.conf")').must_equal "one\ntwo\nthree\n"
end
end
end