[rspec-users] mocking named_scope utilization

Chris Flipse cflipse at gmail.com
Tue Nov 4 22:26:39 EST 2008

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|

def stub_chains(*args)
  hades = stub("chain", :null_object => true)
  args.each do|chain|

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


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/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20081104/e6d00868/attachment.html>

More information about the rspec-users mailing list