[rspec-users] mocking named_scope utilization
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|
> 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 :)
>> rspec-users mailing list
>> rspec-users at rubyforge.org
> // anything worth taking seriously is worth making fun of
> // http://blog.devcaffeine.com/
// anything worth taking seriously is worth making fun of
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the rspec-users