Skip to content

Instantly share code, notes, and snippets.

@tbuehlmann
Last active September 7, 2018 11:21
Show Gist options
  • Save tbuehlmann/ced1e747098a5346595962f75579f187 to your computer and use it in GitHub Desktop.
Save tbuehlmann/ced1e747098a5346595962f75579f187 to your computer and use it in GitHub Desktop.
class A
def self.foo
end
end
class B < A
end
mock_a = MiniTest::Mock.new
mock_b = MiniTest::Mock.new
A.stub(:foo, mock_a) do
B.stub(:foo, mock_b) { }
end
A.method(:foo).source # => " def self.foo\n end\n"
B.method(:foo).source # => " metaclass.send :define_method, name do |*args, &blk|\n if val_or_callable.respond_to? :call then\n val_or_callable.call(*args, &blk)\n else\n blk.call(*block_args) if blk\n val_or_callable\n end\n end\n"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment