Permalink
Browse files

switched assert example to check cowfile

  • Loading branch information...
1 parent db149a9 commit 84ddeefd860872621cd61cf8b30d708f946f4cf9 Avdi Grimm committed Jan 10, 2010
Showing with 19 additions and 8 deletions.
  1. +6 −4 lib/cowsay.rb
  2. +13 −4 spec/cowsay_spec.rb
View
@@ -8,12 +8,14 @@ def initialize(options={})
end
def say(message, options={})
- out = options[:out]
- assert(out.nil? || out.respond_to?(:<<))
+ assert(options[:cowfile].nil? || File.exist?(options[:cowfile]))
command = "cowsay"
if options[:strings] && options[:strings][:eyes]
command << " -e '#{options[:strings][:eyes]}'"
end
+ if options[:cowfile]
+ command << " -f #{options[:cowfile]}"
+ end
messages = case message
when Array then message
@@ -33,8 +35,8 @@ def say(message, options={})
end
end
output = results.join("\n")
- if out
- out << output
+ if options[:out]
+ options[:out] << output
end
destination = case options[:out]
when nil then "return value"
View
@@ -110,11 +110,20 @@ def set_child_exit_status(status)
end
end
- context "bad :out option" do
- it "should raise ArgumentError" do
+ context "given a cowfile" do
+ it "should supply a -f argument on the command line" do
+ File.stub!(:exist?).and_return(true)
+ @io_class.should_receive(:popen).with(/-f COWFILE/, anything)
+ @it.say("moo", :cowfile => "COWFILE")
+ end
+ end
+
+ context "given an invalid cowfile" do
+ it "should raise an error" do
+ File.stub!(:exist?).and_return(false)
lambda do
- @it.say("whatever", :out => Object.new)
- end.should raise_error
+ @it.say("moo", :cowfile => "COWFILE")
+ end.should raise_error(Exception)
end
end
end

0 comments on commit 84ddeef

Please sign in to comment.