-
-
Save anonymous/d1937869a01ddc718029 to your computer and use it in GitHub Desktop.
mocking method calls in unit tests
This file contains 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
class B | |
def some_call | |
return True | |
end | |
end | |
class A | |
def meth | |
return @b.some_call | |
end | |
def initialize(params={}) | |
params.each { |k,v| instance_variable_set "@#{k}",v } #setattr(self, k, v) } | |
end | |
end | |
#require "minitest" | |
#require "minitest/autorun" | |
require "test/unit" | |
class ATest < Test::Unit::TestCase | |
def setup | |
@b = B.new | |
def @b.some_call; false;end | |
@a = A.new(b: @b) | |
end | |
def test_meth | |
assert(!@a.meth()) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment