Skip to content
This repository has been archived by the owner on Nov 16, 2017. It is now read-only.

Commit

Permalink
Refactored anitmock out into a method... called antimock.
Browse files Browse the repository at this point in the history
  • Loading branch information
Burke Libbey committed Aug 27, 2010
1 parent d7dbaad commit a1a3a50
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 19 deletions.
2 changes: 1 addition & 1 deletion autolink.gemspec
@@ -1,6 +1,6 @@
Gem::Specification.new do |gem|
gem.name = 'autolink'
gem.version = "1.0.0"
gem.version = "1.0.1"

gem.author, gem.email = 'Burke Libbey', "burke@burkelibbey.org"
gem.homepage = "http://github.com/burke/autolink"
Expand Down
47 changes: 29 additions & 18 deletions lib/autolink/rspec.rb
@@ -1,3 +1,31 @@
# This is a really bad idea. There's a reason this isn't supported out of the box.
# ...but I don't want to refactor thousands of specs.
module Spec
module Mocks
class Mock
def antimock(*methods)
methods.each do |method|
__mock_proxy.instance_eval <<-CODE
def @target.#{method}
syms = __mock_proxy.instance_variable_get("@stubs").map(&:sym)
@__sub = #{self.class}.new
syms.each do |sym|
# Define this method to call the same method on @target.
that = self
(class << @__sub; self; end).send(:define_method, sym) do
that.send(sym)
end
end
@__sub.#{method}
end
CODE
end
self
end
end
end
end

module Spec
module Rails
module Matchers
Expand Down Expand Up @@ -25,24 +53,7 @@ def expected_url
module Mocks

def __post_mock_model(model_class, mock)

mock.__send__(:__mock_proxy).instance_eval <<-CODE
def @target.default_lineage
# self == @target
syms = __mock_proxy.instance_variable_get("@stubs").map(&:sym)
@__sub = #{model_class}.new
syms.each do |sym|
# Define this method to call the same method on @target.
that = self
(class << @__sub; self; end).send(:define_method, sym) do
that.send(sym)
end
end
@__sub.default_lineage
end
CODE

mock
mock.antimock(:default_lineage)
end

alias __mock_model mock_model
Expand Down

0 comments on commit a1a3a50

Please sign in to comment.