diff --git a/spec/unit/parser/functions/shellquote_spec.rb b/spec/unit/parser/functions/shellquote_spec.rb index bfa2969ea..a06840b9e 100755 --- a/spec/unit/parser/functions/shellquote_spec.rb +++ b/spec/unit/parser/functions/shellquote_spec.rb @@ -1,83 +1,69 @@ #!/usr/bin/env rspec require 'spec_helper' describe "the shellquote function" do before :all do Puppet::Parser::Functions.autoloader.loadall end - before :each do - @scope = Puppet::Parser::Scope.new - end + let :scope do Puppet::Parser::Scope.new end it "should exist" do Puppet::Parser::Functions.function("shellquote").should == "function_shellquote" end - it "should handle no arguments" do - result = @scope.function_shellquote([]) - result.should(eql("")) + scope.function_shellquote([]).should == "" end it "should handle several simple arguments" do - result = @scope.function_shellquote( ['foo', 'bar@example.com', 'localhost:/dev/null', 'xyzzy+-4711,23']) - result.should(eql( 'foo bar@example.com localhost:/dev/null xyzzy+-4711,23')) + scope.function_shellquote( + ['foo', 'bar@example.com', 'localhost:/dev/null', 'xyzzy+-4711,23'] + ).should == 'foo bar@example.com localhost:/dev/null xyzzy+-4711,23' end it "should handle array arguments" do - - result = @scope.function_shellquote( - + scope.function_shellquote( ['foo', ['bar@example.com', 'localhost:/dev/null'], - - 'xyzzy+-4711,23']) - result.should(eql( - 'foo bar@example.com localhost:/dev/null xyzzy+-4711,23')) + 'xyzzy+-4711,23'] + ).should == 'foo bar@example.com localhost:/dev/null xyzzy+-4711,23' end it "should quote unsafe characters" do - result = @scope.function_shellquote( ['/etc/passwd ', '(ls)', '*', '[?]', "'&'"]) - result.should(eql( '"/etc/passwd " "(ls)" "*" "[?]" "\'&\'"')) + scope.function_shellquote(['/etc/passwd ', '(ls)', '*', '[?]', "'&'"]). + should == '"/etc/passwd " "(ls)" "*" "[?]" "\'&\'"' end it "should deal with double quotes" do - result = @scope.function_shellquote( - ['"foo"bar"']) - result.should(eql( - '\'"foo"bar"\'')) + scope.function_shellquote(['"foo"bar"']).should == '\'"foo"bar"\'' end it "should cope with dollar signs" do - result = @scope.function_shellquote( ['$PATH', 'foo$bar', '"x$"']) - result.should(eql( "'$PATH' 'foo$bar' '\"x$\"'")) + scope.function_shellquote(['$PATH', 'foo$bar', '"x$"']). + should == "'$PATH' 'foo$bar' '\"x$\"'" end - it "should deal with apostrophes (single quotes)", :'fails_on_ruby_1.9.2' => true do - result = @scope.function_shellquote( - ["'foo'bar'", "`$'EDITOR'`"]) - result.should(eql( - '"\'foo\'bar\'" "\\`\\$\'EDITOR\'\\`"')) + it "should deal with apostrophes (single quotes)" do + scope.function_shellquote(["'foo'bar'", "`$'EDITOR'`"]). + should == '"\'foo\'bar\'" "\\`\\$\'EDITOR\'\\`"' end it "should cope with grave accents (backquotes)" do - result = @scope.function_shellquote( ['`echo *`', '`ls "$MAILPATH"`']) - result.should(eql( "'`echo *`' '`ls \"$MAILPATH\"`'")) + scope.function_shellquote(['`echo *`', '`ls "$MAILPATH"`']). + should == "'`echo *`' '`ls \"$MAILPATH\"`'" end - it "should deal with both single and double quotes", :'fails_on_ruby_1.9.2' => true do - result = @scope.function_shellquote( ['\'foo"bar"xyzzy\'', '"foo\'bar\'xyzzy"']) - result.should(eql( '"\'foo\\"bar\\"xyzzy\'" "\\"foo\'bar\'xyzzy\\""')) + it "should deal with both single and double quotes" do + scope.function_shellquote(['\'foo"bar"xyzzy\'', '"foo\'bar\'xyzzy"']). + should == '"\'foo\\"bar\\"xyzzy\'" "\\"foo\'bar\'xyzzy\\""' end - it "should handle multiple quotes *and* dollars and backquotes", :'fails_on_ruby_1.9.2' => true do - result = @scope.function_shellquote( ['\'foo"$x`bar`"xyzzy\'']) - result.should(eql( '"\'foo\\"\\$x\\`bar\\`\\"xyzzy\'"')) + it "should handle multiple quotes *and* dollars and backquotes" do + scope.function_shellquote(['\'foo"$x`bar`"xyzzy\'']). + should == '"\'foo\\"\\$x\\`bar\\`\\"xyzzy\'"' end it "should handle linefeeds" do - result = @scope.function_shellquote( ["foo \n bar"]) - result.should(eql( "\"foo \n bar\"")) + scope.function_shellquote(["foo \n bar"]).should == "\"foo \n bar\"" end - end