Skip to content

Instantly share code, notes, and snippets.

@mattpolito
Created January 30, 2013 15:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattpolito/4674184 to your computer and use it in GitHub Desktop.
Save mattpolito/4674184 to your computer and use it in GitHub Desktop.
Testing system calls
require 'stringio'
class DefaultFormatter
attr_reader :output
def initialize(output = StringIO.new)
@output = output
end
def display(message)
output.puts
output.puts "=" * 80
output.puts ">> #{message}"
output.puts "=" * 80
output.puts
end
end
require './default_formatter'
class Whoopsie
attr_reader :formatter
def initialize(thing, options = {})
@formatter = options[:formatter] || DefaultFormatter.new
end
def do_special_work
notify_screen("Amazing stuff happening here")
# actual amazing work
end
private
def notify_screen(message)
formatter.display(message)
end
end
require 'rspec'
require './whoopsie'
describe Whoopsie do
describe "#do_special_work" do
let(:whoopsie) do
described_class.new('thing', formatter: formatter)
end
let(:formatter) { double(:formatter) }
it "displays message" do
formatter.should_receive(:display).with('Amazing stuff happening here')
whoopsie.do_special_work
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment