Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
Showing
3 changed files
with
46 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
require 'stendhal/mocks/test_double' | ||
require 'stendhal/mocks/spyable' | ||
|
||
module Stendhal | ||
module Mocks | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |