Created
August 31, 2011 03:52
-
-
Save pyykkis/1182778 to your computer and use it in GitHub Desktop.
Feeding mock objects DI style
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
----------------- | |
my_world.rb | |
class MyWorld | |
def initialize | |
@king = King.new | |
end | |
def king_of_the_world | |
@king.name | |
end | |
end | |
---------------- | |
my_world_spec.rb | |
describe MyWorld | |
class TestKing | |
def name | |
"foobar" | |
end | |
end | |
before(:each) do | |
@test_king = TestKing.new | |
King.stub!(:new).and_return(@test_king) | |
@world = MyWorld.new | |
end | |
it "knows the king of the world" | |
@world.king_of_the_world.should == "foobar" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment