Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

return output path, demonstrating try()

  • Loading branch information...
commit d064cc0223af4e18079cc3e91af1293dbfb564bd 1 parent 683f80c
@avdi authored
Showing with 17 additions and 7 deletions.
  1. +2 −1  lib/cowsay.rb
  2. +15 −6 spec/cowsay_spec.rb
View
3  lib/cowsay.rb
@@ -1,3 +1,4 @@
+require 'active_support'
module Cowsay
class Cow
def initialize(options={})
@@ -16,7 +17,7 @@ def say(message, options={})
if options[:out]
options[:out] << result
end
- result
+ options[:out].try(:path) || result
end
end
end
View
21 spec/cowsay_spec.rb
@@ -40,15 +40,24 @@ module Cowsay
@it.say("foo")
end
- it "should write to given output stream, if provided" do
- out = StringIO.new
- @it.say("moo", :out => out)
- out.string.should be == "OUTPUT"
- end
-
it "should pass the -e flag if 'eyes' string set" do
@io_class.should_receive(:popen).with(/\-e 'oO\'/, anything)
@it.say("moo", :strings => { :eyes => 'oO' })
end
+
+ context "given an output stream" do
+ it "should write to given output stream" do
+ out = StringIO.new
+ @it.say("moo", :out => out)
+ out.string.should be == "OUTPUT"
+ end
+
+ it "should return the filename of output file" do
+ out = StringIO.new
+ out.stub!(:path).and_return("/OUTPUT_PATH")
+ @it.say("moo", :out => out).should be == "/OUTPUT_PATH"
+ end
+
+ end
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.