spec/command-line.rb in mattock-0.3.0 vs spec/command-line.rb in mattock-0.3.1

- old
+ new

@@ -44,10 +44,63 @@ result.stdout.should == "Some text" end end end +describe Mattock::CommandLine, "setting environment variables" do + let :commandline do + Mattock::CommandLine.new("env") do |cmd| + cmd.env["TEST_ENV"] = "indubitably" + end + end + + let :result do + commandline.run + end + + it "should succeed" do + result.succeeded?.should be_true + end + + it "should alter the command's environment variables" do + result.stdout.should =~ /TEST_ENV.*indubitably/ + end + +end + +describe Mattock::PipelineChain do + let :commandline do + Mattock::PipelineChain.new do |chain| + chain.add Mattock::CommandLine.new("env") + chain.add Mattock::CommandLine.new("cat") do |cmd| + cmd.env["TEST_ENV"] = "indubitably" + end + end + end + + let :result do + commandline.run + end + + it "should produce the right command" do + commandline.command.should == 'env | cat' + end + + it "should produce a runnable command with format_string" do + commandline.string_format.should == 'TEST_ENV=indubitably env | cat' + end + + it "should succeed" do + result.succeeded?.should be_true + end + + it "should alter the command's environment variables" do + result.stdout.should =~ /TEST_ENV.*indubitably/ + end +end + + describe Mattock::CommandLineDSL do include described_class describe "using the - operator" do let :command do @@ -75,10 +128,10 @@ command.commands[1].should be_an_instance_of(Mattock::CommandLine) command.command.should == "cat /etc/passwd | grep root" end end - describe "using the && operator" do + describe "using the & operator" do let :command do cmd("cd", "/tmp/trash") & %w{rm -rf *} end it "should define commands" do