[rspec-users] stubbing out helper method in helper spec

Ingo Weiss ingo at ingoweiss.com
Thu Sep 6 12:07:18 EDT 2007


Thanks David,

in this case stubbing out method1 helped me a lot with focusing on  
what I want to test, without being distracted by having to follow  
down the call stack

Ingo

On Sep 6, 2007, at 5:40 PM, David Chelimsky wrote:

> On 9/6/07, Ingo Weiss <ingo at ingoweiss.com> wrote:
>> Hi,
>>
>> I am stuck with a problem in my helper specs. Say I have a helper
>> with two methods, method1 and method2, where method2 is calling
>> method1 internally. How can I stub out method1 when testing method2?
>> I guess it boils down to how I can access the helper object from
>> within a helper spec.
>>
>>    it 'should behave_correctly' do
>>      ???.stub!(:method1).and_return('mock')
>>      method2.should eql('...')
>>    end
>
> 2 schools of thought:
>
> it "should behave correctly" do
>   self.should_receive(:method1).with('foo').and_return(whatever)
>   method2('foo')
> end
>
> The other is don't mock the call. Just spec the behaviour of method1
> as though it does everything.
>
> Deciding between these two approaches is where the art of mocking lies
> - when to do it, when not to. In the end, it depends on a lot of
> factors, but the overriding factor should be the answer to "what is
> the simplest way I can get stuff done?"
>
> I'm sure that's not at all helpful :)
>
> Cheers,
> David
>
>>
>> Thanks!
>> Ingo
>>
>>
>> _______________________________________________
>> rspec-users mailing list
>> rspec-users at rubyforge.org
>> http://rubyforge.org/mailman/listinfo/rspec-users
>>
> _______________________________________________
> rspec-users mailing list
> rspec-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users



More information about the rspec-users mailing list