Forum: RSpec Mocking find_by_sql

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
059ed46172a087063ce26250e44c8627?d=identicon&s=25 Fernando Perez (fernando)
on 2009-06-05 22:29
Hi, I cannot manage to mock a call to find_by_sql. Which class is
actually getting called? It is not the model, and I tried ActiveRecord
which didn't work either.
059ed46172a087063ce26250e44c8627?d=identicon&s=25 Fernando Perez (fernando)
on 2009-06-05 22:33
Damn I can't mock will_paginate's paginate method either!!!
5d38ab152e1e3e219512a9859fcd93af?d=identicon&s=25 David Chelimsky (Guest)
on 2009-06-05 23:07
(Received via mailing list)
On Fri, Jun 5, 2009 at 3:33 PM, Fernando Perez <lists@ruby-forum.com>
wrote:
> Damn I can't mock will_paginate's paginate method either!!!

Same deal as your other post about find_by_sql. Set the message
expectation on the method on the class:

Post.should_receive(:paginate)
5d38ab152e1e3e219512a9859fcd93af?d=identicon&s=25 David Chelimsky (Guest)
on 2009-06-05 23:18
(Received via mailing list)
On Fri, Jun 5, 2009 at 3:29 PM, Fernando Perez <lists@ruby-forum.com>
wrote:
> Hi, I cannot manage to mock a call to find_by_sql. Which class is
> actually getting called? It is not the model, and I tried ActiveRecord
> which didn't work either.

It's the model's class:

class Foo < AR::Base; end

describe Foo do
  it "...." do
    Foo.should_receive(:find_by_sql) ....

HTH,
David
059ed46172a087063ce26250e44c8627?d=identicon&s=25 Fernando Perez (fernando)
on 2009-06-06 11:16
> Same deal as your other post about find_by_sql. Set the message
> expectation on the method on the class:
>
> Post.should_receive(:paginate)

Unfortunately it doesn't work :-( I'll have to dive into the
will_paginate source code to find out how it plugs itself in AR.
9239e324751b8db551789e5e16689438?d=identicon&s=25 Hunt Jon (Guest)
on 2009-06-06 17:54
(Received via mailing list)
You might not be understanding the usage of mock very well.
This topic is locked and can not be replied to.