mirror of
https://github.com/inspec/inspec
synced 2024-12-24 03:53:15 +00:00
71057675de
* Allow skipping/failing resources in FilterTable `FilterTable` is commonly used in the class body of a resource and is evaluated during an `instance_eval`. This means that if you raise an exception (e.g. SkipResource) it will halt `inspec exec` and `inspec check`. This adds an `ExceptionCatcher` class that will postpone evaluation until test execution. This allows `inspec check` and `inspec exec` to perform as intended when skipping/failing a resource in `FilterTable` Huge thanks to @adamleff for providing the starting code/ideas! Signed-off-by: Jerry Aldrich <jerryaldrichiii@gmail.com> * Comment why `ExceptionCatcher` doesn't raise Signed-off-by: Jerry Aldrich <jerryaldrichiii@gmail.com> * Remove `accessor` from `ExceptionCatcher` Signed-off-by: Jerry Aldrich <jerryaldrichiii@gmail.com> * Return the existing ExceptionCatcher object rather than creating new Signed-off-by: Adam Leff <adam@leff.co>
74 lines
2 KiB
Ruby
74 lines
2 KiB
Ruby
# encoding: utf-8
|
|
|
|
# checks[0]
|
|
describe exception_resource_test('should raise ResourceSkipped', :skip_me) do
|
|
its('value') { should eq 'does not matter' }
|
|
end
|
|
|
|
# checks[1]
|
|
describe exception_resource_test('should raise ResourceFailed', :fail_me) do
|
|
its('value') { should eq 'does not matter' }
|
|
end
|
|
|
|
# checks[2]
|
|
describe exception_resource_test('should pass') do
|
|
its('value') { should eq 'should pass' }
|
|
end
|
|
|
|
# checks[3]
|
|
describe exception_resource_test('fail inside matcher') do
|
|
its('inside_matcher') { should eq 'does not matter' }
|
|
end
|
|
|
|
# checks[4]
|
|
describe exception_resource_test('skip inside matcher') do
|
|
its('inside_matcher') { should eq 'does not matter' }
|
|
end
|
|
|
|
control 'should-work-within-control' do
|
|
# checks[5][0]
|
|
describe exception_resource_test('should skip', :skip_me) do
|
|
its('value') { should eq 'does not matter' }
|
|
end
|
|
|
|
# checks[5][1]
|
|
describe exception_resource_test('should fail', :fail_me) do
|
|
its('value') { should eq 'does not matter' }
|
|
end
|
|
end
|
|
|
|
# checks[6]
|
|
describe exception_resource_test('skip_me').matters('does not matter') do
|
|
its('matters') { should eq 'does not matter' }
|
|
end
|
|
|
|
# checks[7]
|
|
describe exception_resource_test('fail_me').matters('does not matter') do
|
|
its('matters') { should eq 'does not matter' }
|
|
end
|
|
|
|
# checks[8]
|
|
describe exception_resource_test('skip_me').matters('it really does').another_filter('example') do
|
|
its('value') { should cmp 'does not matter' }
|
|
end
|
|
|
|
# checks[9]
|
|
describe exception_resource_test('fail_me').matters('it really does').another_filter('example') do
|
|
its('value') { should cmp 'does not matter' }
|
|
end
|
|
|
|
# checks[10]
|
|
describe exception_resource_test('skip_me').matters('it really does').not_real_filter('example') do
|
|
its('value') { should cmp 'does not matter' }
|
|
end
|
|
|
|
# checks[11]
|
|
describe exception_resource_test('fail_me').matters('it really does').not_real_filter('example') do
|
|
its('value') { should cmp 'does not matter' }
|
|
end
|
|
|
|
# checks[12]
|
|
describe exception_resource_test('should_pass').matters('it really does') do
|
|
its('another_filter') { should cmp 'example' }
|
|
end
|
|
|