Created
October 31, 2012 02:00
Revisions
-
totallymike created this gist
Oct 31, 2012 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,37 @@ class Foo attr_reader :stuff def initialize(stuff) @stuff = stuff end def bar sock = TCPSocket.new('127.0.0.1', 1337) stuff.each do |thing| sock.puts thing sock.close end end end describe Foo do it "will send out a line for each thing" do sock = double() sock.should_receive(:puts).at_least(:once) do |msg| msg.should eq "woo" end TCPSocket.stub(:new).and_return sock foo = Foo.new(['woo']) foo.bar end it "doesn't open and close sockets all willy-nilly" do sock = double() sock.should_receive(:close).once foo = Foo.new(['woo', 'yeah', 'party']) foo.bar end end => Oh no failzor!