[rspec-users] Problems stubbing @controller.stub!(:send)

David Schmidt davids at tower-mt.com
Tue Nov 4 19:27:08 EST 2008

On Nov 4, 2008, at 1:53 PM, Pat Maddox wrote:

> David Schmidt <davids at tower-mt.com> writes:
>> In one of my controller tests I'm testing a method which uses
>> self.send(<private method name>) to do some pre-processing if that
>> private method name is defined:
>>            # If this task requires some additional preperation then
>> create a
>>            # private method below with the same name as the
>> task_type and
>>            # it will be executed here.
>>            if private_methods.include?(task_type)
>>              self.send(task_type)
>>            end
>> I will be testing these private_methods separately so I want to just
>> stub out the "self.send" line so that I can verify that it's called  
>> if
>> there's a match.
>> [...]

>> Is there any way that I can stub out *just* the :send with "private
>> method" and leave the other one alone to execute?
> I'm not sure, but you should be able to stub out :private_method and  
> it
> ought to work fine, even when you send it.
> Pat

That did the trick and worked great.  Thanks Pat!

David Schmidt
davids at tower-mt.com

More information about the rspec-users mailing list