Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Started working on message expectations
  • Loading branch information
Josep M. Bach committed Nov 9, 2010
1 parent 9009c33 commit f5d887a
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/stendhal/mocks.rb
@@ -1,4 +1,5 @@
require 'stendhal/mocks/test_double'
require 'stendhal/mocks/spyable'

module Stendhal
module Mocks
Expand Down
25 changes: 25 additions & 0 deletions lib/stendhal/mocks/spyable.rb
@@ -0,0 +1,25 @@
module Stendhal
module Mocks
module Spyable
# def included(base)
# base.send(:include, InstanceMethods)
# end

# module InstanceMethods
def spy(method)
metaclass = (class << self;self;end)
metaclass.send(:alias_method, :"__original_#{method}", method.to_sym)
metaclass.send(:undef_method, method.to_sym)
metaclass.class_eval <<EOT
def #{method}(*args, &block)
puts "spy says... called #{method}!"
@__verifier.add_call(:#{method},*args,&block) if nil
__original_#{method}(*args,&block)
end
EOT
end
# end

end
end
end
20 changes: 20 additions & 0 deletions spec/stendhal/spyable_spec.rb
@@ -0,0 +1,20 @@
require 'spec_helper'

class MyClass < Array
include Stendhal::Mocks::Spyable
end

module Stendhal
module Mocks
describe "a Spyable class" do

subject { MyClass.new([1,2,3]) }

it 'acts as a proxy for the target' do
subject.spy(:length)
subject.length
end

end
end
end

0 comments on commit f5d887a

Please sign in to comment.