# Problems with view spec and mocking will\_paginate

**URL:** <https://www.ruby-forum.com/t/problems-with-view-spec-and-mocking-will-paginate/139798>\
**Category:** RSpec\
**Created:** [June 7, 2008, 5:17am UTC](https://www.ruby-forum.com/t/problems-with-view-spec-and-mocking-will-paginate/139798 "2008-06-07T05:17:02Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gaston\_R](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/6de8d8/32.png) [@Gaston\_R](https://www.ruby-forum.com/u/Gaston_R)\
**Post date:** [June 7, 2008, 5:17am UTC](https://www.ruby-forum.com/t/problems-with-view-spec-and-mocking-will-paginate/139798/1 "2008-06-07T05:17:02Z")

</div>

Hi all, I have some failures that not I don’t understand

this the pastie with index.erb.html  
[http://pastie.org/private/zgohh6dcts04wpfagfgz5q](http://pastie.org/private/zgohh6dcts04wpfagfgz5q)

and this is the pastie for view’s spec:  
[http://pastie.org/210485](http://pastie.org/210485)

and the failure:

1. 

ActionView::TemplateError in ‘/posts/index.html.erb should render list  
of posts’  
undefined method `count’ for [#\<Comment:0x…fdb6535be  
@name=“Comment\_1001”\>]:Array

I tried this: Array.stub!(:count).and\_return(1)  
but didn’t work.

Can somebody help me?

Regards.

–  
“Es imposible afinar un lápiz con una cuchilla desafilada. Es igualmente  
inútil tratar de hacerlo con diez.”  
(Edsger Dijkstra)

±------------------------------------+  
Gastón Ramos

> **[Gastón Ramos](https://gastonramos.wordpress.com/)**
>
> "La mayoría de las gaviotas no se molesta en aprender sino las normas de vuelo más elementales: como ir y volver entre playa y comida. Para la mayoría de las gaviotas, no es volar lo que impor…

GNU/Linux Counter user #450312

---

<div class="post-metadata">

**Author:** ![Gaston\_R](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/6de8d8/32.png) [@Gaston\_R](https://www.ruby-forum.com/u/Gaston_R)\
**Post date:** [June 7, 2008, 9:34am UTC](https://www.ruby-forum.com/t/problems-with-view-spec-and-mocking-will-paginate/139798/2 "2008-06-07T09:34:45Z")

</div>

You have to stub that count method for the Array object and not for  
class Array:

comments = [comment]  
comments.stub!(:count).and\_return(1)  
post\_98.stub!(:comments).and\_return(comments)  
post\_99.stub!(:comments).and\_return(comments)

Matthias

Am 06.06.2008 um 23:48 schrieb Gaston R.:

---

<div class="post-metadata">

**Author:** ![Gaston\_R](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/6de8d8/32.png) [@Gaston\_R](https://www.ruby-forum.com/u/Gaston_R)\
**Post date:** [June 9, 2008, 2:09pm UTC](https://www.ruby-forum.com/t/problems-with-view-spec-and-mocking-will-paginate/139798/3 "2008-06-09T14:09:41Z")

</div>

Thanks!

El sáb, 07 de jun de 2008, a las 09:28:23 +0200, Matthias Hennemeyer dijo:

> Am 06.06.2008 um 23:48 schrieb Gaston R.:
> 
> > [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> > [http://rubyforge.org/mailman/listinfo/rspec-users](http://rubyforge.org/mailman/listinfo/rspec-users)
> 
> * * *
> 
> rspec-users mailing list  
> [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> [http://rubyforge.org/mailman/listinfo/rspec-users](http://rubyforge.org/mailman/listinfo/rspec-users)

–  
“Premature optimization is the root of all evil (or at least most of it)  
in  
programming.”

(Donald Knuth)

±------------------------------------+  
Gastón Ramos

> **[Gastón Ramos](https://gastonramos.wordpress.com/)**
>
> "La mayoría de las gaviotas no se molesta en aprender sino las normas de vuelo más elementales: como ir y volver entre playa y comida. Para la mayoría de las gaviotas, no es volar lo que impor…

GNU/Linux Counter user #450312
