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.
Fernando P. (Guest)
on 2009-06-06 00: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.
Fernando P. (Guest)
on 2009-06-06 00:33
Damn I can't mock will_paginate's paginate method either!!!
David C. (Guest)
on 2009-06-06 01:07
(Received via mailing list)
On Fri, Jun 5, 2009 at 3:33 PM, Fernando P. 
<removed_email_address@domain.invalid>
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)
David C. (Guest)
on 2009-06-06 01:18
(Received via mailing list)
On Fri, Jun 5, 2009 at 3:29 PM, Fernando P. 
<removed_email_address@domain.invalid>
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
Fernando P. (Guest)
on 2009-06-06 13: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.
Hunt J. (Guest)
on 2009-06-06 19: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.