Allow add_test to accept negation (#3586)

* Allow add_test to accept negation
This will allow for negated tests to be generated with add_tests.
* Fix rubocop violation
* Add optional options hash

Signed-off-by: Rachel Rice <rrice@chef.io>
This commit is contained in:
Rachel Rice 2018-11-08 17:48:12 +00:00 committed by Jared Quick
parent 45926ef63a
commit de5b332feb
2 changed files with 22 additions and 2 deletions

View file

@ -57,8 +57,8 @@ module Inspec
@variables = []
end
def add_test(its, matcher, expectation)
test = Inspec::Describe::Test.new(its, matcher, expectation, false)
def add_test(its, matcher, expectation, opts = {})
test = Inspec::Describe::Test.new(its, matcher, expectation, opts[:negated])
tests.push(test)
test
end

View file

@ -127,6 +127,26 @@ end
describe resource do
its(["explorer", "exe"]) { should cmp 1 }
end
'.strip
end
it 'is negated' do
obj.qualifier = [['resource']]
obj.add_test(['explorer', 'exe'], 'cmp', 1, :negated => true)
obj.to_ruby.must_equal '
describe resource do
its(["explorer", "exe"]) { should_not cmp 1 }
end
'.strip
end
it 'is not negated' do
obj.qualifier = [['resource']]
obj.add_test(['explorer', 'exe'], 'cmp', 1, :negated => false)
obj.to_ruby.must_equal '
describe resource do
its(["explorer", "exe"]) { should cmp 1 }
end
'.strip
end
end