[rspec-users] mocking named_scope utilization

Chris Flipse cflipse at gmail.com
Tue Nov 4 22:27:30 EST 2008


Right.  Example passed a block, but stub_chains didn't call it.  Pretend
there's a yield(hades) in there somewhere.

On Tue, Nov 4, 2008 at 10:26 PM, Chris Flipse <cflipse at gmail.com> wrote:

> I dunno ... creating a bunch of joining methods seems to be an awfully
> disjoint way to deal with something that is, admittedly, designed to laugh
> in the face of the Law of Demeter.
>
> I've been handling chains through some heavy use of null_object stubs ...
> but, I've been doing that sort of manually.  Could be rolled up, at least.
>
> I'm kind of spitballing something that might be somewhat less manual ...
>
> foo.stub_chains :method_1, :method_2 do |chain|
> end
>
> def stub_chains(*args)
>   hades = stub("chain", :null_object => true)
>   args.each do|chain|
>     hades.stub!(chain).and_return(hades)
>     self.stub!(chain).and_return(hades)
>   end
> end
>
> This would more or less let named_scope be used like it's intended in
> Rails, with one not-so-little exception -- I have to know what gets called
> last, so it can return a real value.  For me, in practice, that's been
> .paginate, so it's not been a huge issue, but that's a definite gotchya
>
>
> WDYT?
>
>
> On Tue, Nov 4, 2008 at 6:41 PM, Pat Maddox <pergesu at gmail.com> wrote:
>
>> Fernando Perez <lists at ruby-forum.com> writes:
>>
>> > Therefore a workaround is to define an instance method:
>> > --
>> > class Thing
>> >   def self.method1_and_method2(arg)
>> >     method1(arg).method2
>> >   end
>> > end
>>
>> I'm inclined to call this an improvement rather than a workaround :)
>>
>> Pat
>> _______________________________________________
>> rspec-users mailing list
>> rspec-users at rubyforge.org
>> http://rubyforge.org/mailman/listinfo/rspec-users
>>
>
>
>
> --
> // anything worth taking seriously is worth making fun of
> // http://blog.devcaffeine.com/
>



-- 
// anything worth taking seriously is worth making fun of
// http://blog.devcaffeine.com/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20081104/eaea0261/attachment.html>


More information about the rspec-users mailing list