Permalink
Browse files

added :width option

  • Loading branch information...
Avdi Grimm
Avdi Grimm committed Jan 10, 2010
1 parent a9bf1e6 commit d3c3be190aaeba5f866081ec72c452e043230c60
Showing with 17 additions and 1 deletion.
  1. +2 −0 lib/cowsay.rb
  2. +15 −1 spec/cowsay_spec.rb
View
@@ -9,6 +9,8 @@ def initialize(options={})
def say(message, options={})
command = "cowsay"
+ width = options[:width] || 40
+ command << " -W #{width}"
if options[:strings] && options[:strings][:eyes]
command << " -e '#{options[:strings][:eyes]}'"
end
View
@@ -25,7 +25,7 @@ def set_child_exit_status(status)
end
it "should start the cowsay process" do
- @io_class.should_receive(:popen).with("cowsay", anything)
+ @io_class.should_receive(:popen).with(/^cowsay/, anything)
@it.say("foo")
end
@@ -109,5 +109,19 @@ def set_child_exit_status(status)
@it.say(nil).should be == ""
end
end
+
+ context "with no width specified" do
+ it "should pass a width arg of 40" do
+ @io_class.should_receive(:popen).with(/-W 40/, anything)
+ @it.say("moo")
+ end
+ end
+
+ context "given an integer width" do
+ it "should pass the specified width argument" do
+ @io_class.should_receive(:popen).with(/-W 29/, anything)
+ @it.say("moo", :width => 29)
+ end
+ end
end
end

0 comments on commit d3c3be1

Please sign in to comment.