[rspec-users] mocking named_scope utilization

Pat Maddox pergesu at gmail.com
Thu Nov 6 12:48:45 EST 2008

"Chris Flipse" <cflipse at gmail.com> writes:

> 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

Yeah, that's cool.  In regards to Demeter, one of my former coworkers
argued that if you don't gain much by that encapsulation, you should
default to following the ontological structure.  Makes a lot of sense to


More information about the rspec-users mailing list