Created
October 31, 2012 02:00
-
-
Save totallymike/3984369 to your computer and use it in GitHub Desktop.
How I want these doubles to work
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 characters
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! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment