Created
September 22, 2010 23:15
-
-
Save marioaquino/592762 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 'stub' | |
class Foo | |
def bar(hey, now) | |
end | |
def hoy() | |
end | |
end | |
class Bar < Foo | |
def blap(howdy) | |
end | |
end | |
class TestStub < Test::Unit::TestCase | |
def test_declared_methods | |
stub = Stub.new(Foo) | |
stub.bar_return = 'heynow' | |
result = stub.bar('baba', 'ganush') | |
assert stub.bar_called? | |
assert_equal false, stub.hoy_called? | |
assert_equal 'baba', stub.bar_params[0] | |
assert_equal 'ganush', stub.bar_params[1] | |
assert_equal 'heynow', result | |
end | |
def test_equals_method | |
one = Stub.new(Foo) | |
two = Stub.new(Foo) | |
assert_equal one, two | |
one.bar_return = 'yeah' | |
two.bar_return = 'yeah' | |
assert_equal one, two | |
two.bar_return = 'foo' | |
assert_not_equal one, two | |
assert_not_equal one, Stub.new(Fixnum) | |
end | |
def test_stub_throws_supplied_error | |
stub = Stub.new(Foo) | |
stub.bar_error = StandardError.new | |
assert_raise(StandardError) { stub.bar('hey', 'now') } | |
end | |
def test_stub_inherited_methods | |
stub = Stub.new(Bar, true) | |
stub.blap_return = 'one' | |
stub.hoy_return = 'two' | |
blap_result = stub.blap | |
hoy_result = stub.hoy | |
assert stub.blap_called? | |
assert stub.hoy_called? | |
assert_equal 'one', blap_result | |
assert_equal 'two', hoy_result | |
end | |
def test_stub_no_inherited_methods_by_default | |
assert_raise(NoMethodError) { Stub.new(Bar).hoy } | |
end | |
def test_params_method_created_when_needed | |
stub = Stub.new(Foo) | |
assert_nothing_raised do | |
stub.bar('a', 'b') | |
stub.bar_params[0] | |
end | |
stub.hoy | |
assert_raise(NoMethodError) { stub.hoy_params[0] } | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment