Permalink
Browse files

Basic assertion for :out

  • Loading branch information...
1 parent a9bf1e6 commit 4a26ff2871c77ecccbe4faa8a855cc31b88a8084 @avdi committed Jan 8, 2010
Showing with 12 additions and 2 deletions.
  1. +4 −2 lib/cowsay.rb
  2. +8 −0 spec/cowsay_spec.rb
View
6 lib/cowsay.rb
@@ -8,6 +8,8 @@ def initialize(options={})
end
def say(message, options={})
+ out = options[:out]
+ raise ArgumentError unless out.nil? || out.respond_to?(:<<)
command = "cowsay"
if options[:strings] && options[:strings][:eyes]
command << " -e '#{options[:strings][:eyes]}'"
@@ -31,8 +33,8 @@ def say(message, options={})
end
end
output = results.join("\n")
- if options[:out]
- options[:out] << output
+ if out
+ out << output
end
destination = case options[:out]
when nil then "return value"
View
8 spec/cowsay_spec.rb
@@ -109,5 +109,13 @@ def set_child_exit_status(status)
@it.say(nil).should be == ""
end
end
+
+ context "bad :out option" do
+ it "should raise ArgumentError" do
+ lambda do
+ @it.say("whatever", :out => Object.new)
+ end.should raise_error(ArgumentError)
+ end
+ end
end
end

0 comments on commit 4a26ff2

Please sign in to comment.