Skip to content

Instantly share code, notes, and snippets.

@totallymike
Created October 31, 2012 02:00

Revisions

  1. totallymike created this gist Oct 31, 2012.
    37 changes: 37 additions & 0 deletions buttheydont.rb
    Original 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!