Skip to content

Instantly share code, notes, and snippets.

/mock Secret

Created January 22, 2015 09:33
Show Gist options
  • Save anonymous/d1937869a01ddc718029 to your computer and use it in GitHub Desktop.
Save anonymous/d1937869a01ddc718029 to your computer and use it in GitHub Desktop.
mocking method calls in unit tests
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