Wrap regex in parenthesis no matter of the matcher used, ex: match, cmp

Signed-off-by: Alex Pop <apop@chef.io>
This commit is contained in:
Alex Pop 2017-01-30 11:51:06 +00:00
parent 5a087bd256
commit 80ad877e02
2 changed files with 3 additions and 3 deletions

View file

@ -67,7 +67,7 @@ module Inspec
itsy = xtra.nil? ? 'it' : 'its(' + xtra.to_s.inspect + ')'
naughty = @negated ? '_not' : ''
xpect = defined?(@expectation) ? expectation.inspect : ''
if matcher == 'match'
if @expectation.class == Regexp
# without this, xpect values like / \/zones\// will not be parsed properly
xpect = "(#{xpect})"
elsif xpect != ''

View file

@ -25,7 +25,7 @@ end
obj.expectation = Regexp.new('^Desc.+$')
obj.to_ruby.must_equal '
describe resource.to_s do
it { should cmp /^Desc.+$/ }
it { should cmp(/^Desc.+$/) }
end
'.strip
end
@ -127,7 +127,7 @@ end
loop_obj.to_ruby.must_equal '
port(25).addresses.each do |entry|
describe entry do
it { should_not match("0.0.0.0") }
it { should_not match "0.0.0.0" }
end
end
'.strip