Permalink
Browse files

More specs.

  • Loading branch information...
1 parent 67c40ce commit 298111ac14e20bd4751564c76f0ee6f451ee5d65 @notahat notahat committed Nov 8, 2010
Showing with 21 additions and 2 deletions.
  1. +1 −0 .gitignore
  2. +20 −2 spec/safe_shell_spec.rb
  3. 0 tmp/.gitkeep
View
1 .gitignore
@@ -19,3 +19,4 @@ rdoc
pkg
## PROJECT::SPECIFIC
+tmp/*
View
22 spec/safe_shell_spec.rb
@@ -6,6 +6,10 @@
SafeShell.execute("echo", "Hello, world!").should == "Hello, world!\n"
end
+ it "should safely handle dangerous characters in command arguments" do
+ SafeShell.execute("echo", ";date").should == ";date\n"
+ end
+
it "should set $? to the exit status of the command" do
SafeShell.execute("test", "a", "=", "a")
$?.exitstatus.should == 0
@@ -14,8 +18,22 @@
$?.exitstatus.should == 1
end
- it "should safely handle dangerous characters in command arguments" do
- SafeShell.execute("echo", ";date").should == ";date\n"
+ context "output redirection" do
+ before do
+ File.delete("tmp/output.txt") if File.exists?("tmp/output.txt")
+ end
+
+ it "should let you redirect stdout to a file" do
+ SafeShell.execute("echo", "Hello, world!", :stdout => "tmp/output.txt")
+ File.exists?("tmp/output.txt").should be_true
+ File.read("tmp/output.txt").should == "Hello, world!\n"
+ end
+
+ it "should let you redirect stderr to a file" do
+ SafeShell.execute("cat", "tmp/nonexistent-file", :stderr => "tmp/output.txt")
+ File.exists?("tmp/output.txt").should be_true
+ File.read("tmp/output.txt").should == "cat: tmp/nonexistent-file: No such file or directory\n"
+ end
end
end
View
0 tmp/.gitkeep
No changes.

0 comments on commit 298111a

Please sign in to comment.