Created
March 19, 2010 17:01
-
-
Save bradphelan/337835 to your computer and use it in GitHub Desktop.
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
class Object | |
def should_receive!(sym, opts={}, &block) | |
objx = Object.new | |
@__rspec_obj__ ||= Object.new | |
m = class<<self;self;end | |
sym_old = "__#{sym}__old__" | |
# Generates for sym => :foo | |
# | |
# alias :foo_old :foo | |
# | |
# def foo *args, &block | |
# foo_old *args, &block | |
# @__rspec_obj__.send :foo, *args, &block | |
# end | |
if not respond_to?("#{sym_old}".to_sym) | |
m.class_eval <<-EOS, __FILE__, __LINE__ | |
alias :#{sym_old} :#{sym} | |
def #{sym} *args, &block | |
#{sym_old} *args, &block | |
@__rspec_obj__.send :#{sym}, *args, &block | |
end | |
EOS | |
end | |
@__rspec_obj__.should_receive(sym, opts, &block) | |
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
class Fing | |
def bar | |
puts " bar really called" | |
end | |
def bing | |
puts " bing really called" | |
end | |
end | |
describe Fing do | |
it "is a monkey" do | |
b = Fing.new | |
b.should_receive!(:bar).once.ordered | |
b.should_receive!(:bing).once.ordered | |
b.should_receive!(:bar).once.ordered | |
b.bar | |
b.bing | |
b.bar | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment