Skip to content

Instantly share code, notes, and snippets.

@mwotton
Created November 21, 2010 23:51
Show Gist options
  • Save mwotton/709304 to your computer and use it in GitHub Desktop.
Save mwotton/709304 to your computer and use it in GitHub Desktop.
stubbing new
require 'rspec'
class Bar
def baz
puts "baz called"
end
end
class Foo
def initialize
@bar = Bar.new
@bar.baz
end
end
describe "stubbing an init" do
it 'should stub' do
@mymock = mock("mymock")
Bar.stub(:new).and_return(@mymock)
@mymock.should_receive(:baz)
Foo.new
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment