mirror of
https://github.com/inspec/inspec
synced 2024-12-23 03:23:27 +00:00
f1f2900866
* WIP require chaining * add a tiny comment * reapply fix doh * add a deprecation warning Signed-off-by: Dominik Richter <dominik.richter@gmail.com> * lint Signed-off-by: Dominik Richter <dominik.richter@gmail.com> * remove deprecation warning for require in control files as discussed with Adam Leff Signed-off-by: Dominik Richter <dominik.richter@gmail.com> * add tests for regular ruby gem require in libs Signed-off-by: Dominik Richter <dominik.richter@gmail.com>
44 lines
1.1 KiB
Ruby
44 lines
1.1 KiB
Ruby
# encoding: utf-8
|
|
# author: Steven Danna
|
|
|
|
require 'helper'
|
|
require 'inspec/resource'
|
|
require 'inspec/library_eval_context'
|
|
|
|
describe Inspec::LibraryEvalContext do
|
|
let(:resource_content) { <<EOF
|
|
class MyTestResource < Inspec.resource(1)
|
|
name 'my_test_resource'
|
|
|
|
desc 'A test description'
|
|
example 'Forgot to write docs, sorry'
|
|
|
|
def version
|
|
'2.0'
|
|
end
|
|
end
|
|
EOF
|
|
}
|
|
|
|
let(:registry) { Inspec::Resource.new_registry }
|
|
let(:eval_context) { Inspec::LibraryEvalContext.create(registry, nil) }
|
|
|
|
it 'accepts a registry' do
|
|
Inspec::LibraryEvalContext.create(registry, nil)
|
|
end
|
|
|
|
it 'adds the resource to our registry' do
|
|
eval_context.instance_eval(resource_content)
|
|
registry.keys.include?("my_test_resource").must_equal true
|
|
end
|
|
|
|
it 'adds nothing to the default registry' do
|
|
old_default_registry = Inspec::Resource.default_registry.dup
|
|
eval_context.instance_eval(resource_content)
|
|
old_default_registry.must_equal Inspec::Resource.default_registry
|
|
end
|
|
|
|
it 'provides an inspec context for requiring local files' do
|
|
eval_context.__inspec_binding.must_be_kind_of Binding
|
|
end
|
|
end
|