Created
January 30, 2013 15:52
-
-
Save mattpolito/4674184 to your computer and use it in GitHub Desktop.
Testing system calls
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
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 |
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
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 |
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
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