Created
January 25, 2011 14:12
-
-
Save benpickles/794959 to your computer and use it in GitHub Desktop.
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 'test/unit' | |
require 'rubygems' | |
require 'mocha' | |
class Foo | |
def self.say_hello_to(name) | |
Bar.hello(name) | |
end | |
end | |
class Bar | |
end | |
class TestFooWithStubbingInSetup < Test::Unit::TestCase | |
def setup | |
@hello = mock("said hello") | |
Bar.stubs(:hello).returns(@hello) | |
end | |
def test_something | |
Bar.expects(:hello).with("zab") | |
Foo.say_hello_to("baz") | |
end | |
def test_something_else | |
assert_equal @hello, Foo.say_hello_to("bob") | |
end | |
# Lots of other tests so it's convenient to stub Bar.hello in the setup... | |
end | |
class TestFooWithoutStubbingInSetup < Test::Unit::TestCase | |
def setup | |
@hello = mock("said hello") | |
end | |
def test_something | |
Bar.expects(:hello).with("zab") | |
Foo.say_hello_to("baz") | |
end | |
def test_something_else | |
Bar.stubs(:hello).returns(@hello) | |
assert_equal @hello, Foo.say_hello_to("bob") | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment