Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
jbodah committed May 2, 2015
1 parent 85061b0 commit 67e77e4
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
19 changes: 15 additions & 4 deletions lib/spy/instance.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,14 @@ def attach_to(target)
# instance methods defined on a Class
def call(context, *args)
before_call(*args)
# TODO: DRY up
if original.is_a?(UnboundMethod)
original.bind(context).call(*args)
context = context
else
original.call(*args)
# TODO: not 100% sure here
context = original.receiver
end
around_call(context, *args) { _call(*args) }
end
end

Expand All @@ -81,8 +84,16 @@ def before_call(*args)
@call_count += 1 if @before_filters.all? {|f| f.before_call(*args)}
end

def around_call(*args)
@around_filters.each {|f| f.around_call(*args)}
def around_call(context, *args)
@around_filters.each {|f| f.around_call(context, *args)}
end

def _call(*args)
if original.is_a?(UnboundMethod)
original.bind(context).call(*args)
else
original.call(*args)
end
end

def add_before_filter(filter)
Expand Down
8 changes: 6 additions & 2 deletions lib/spy/instance/filters/wrap.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@ module Spy
class Instance
module Filters
class Wrap
def initialize(block)
@block = block
def initialize(wrapper)
@wrapper = wrapper
end

def around_call(context, *args, &original)
@wrapper.call(context, *args) &original
end
end
end
Expand Down

0 comments on commit 67e77e4

Please sign in to comment.