Skip to content

Instantly share code, notes, and snippets.

@pyykkis
Created August 31, 2011 03:52
Show Gist options
  • Save pyykkis/1182778 to your computer and use it in GitHub Desktop.
Save pyykkis/1182778 to your computer and use it in GitHub Desktop.
Feeding mock objects DI style
-----------------
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