Class: Object
- Inherits:
- BasicObject
- Defined in:
- lib/proxymock.rb
Defined Under Namespace
Classes: ProxyObject
Instance Method Summary collapse
-
#should_receive!(sym, opts = {}, &block) ⇒ Object
Just like should_receive in the standard rspec but also calls the real method.
Instance Method Details
#should_receive!(sym, opts = {}, &block) ⇒ Object
Just like should_receive in the standard rspec but also calls the real method
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/proxymock.rb', line 17 def should_receive!(sym, opts={}, &block) @__rspec_obj__ ||= ProxyObject.new @__rspec_obj__.fake_class = self.class 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 |