[rspec-users] stubbing mongoid::criteria in view code

Justin Ko jko170 at gmail.com
Thu Mar 24 15:26:12 EDT 2011


On Thu, Mar 24, 2011 at 10:22 AM, amkirwan <amkirwan at gmail.com> wrote:

> I'm try to stub the following in my view code but keep running into
> problems with unexpected messages. I've tried stubbing and mocking in
> many combinations but can't find away past this. Here is the code
> below I am trying to spec
>
> ...
>      - if page.parent_id.nil?
>        %td
>      - else
>        %td= Page.criteria.id(page.parent_id).first.title
> ...
>
> I receive this error Mock "MongoidCriteria_1004" received unexpected
> message :title with (no args) when I do the following
>
> Page.stub_chain(:criteria, :id).and_return(mock_model("MongoidCriteria",
> :first
> => mock_model("Page", :title => "foobar")))
>
> I've tried every combination I can think of but can't figure out how
> to stub this.
> _______________________________________________
> rspec-users mailing list
> rspec-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users


Try this:

Page.stub_chain('criteria.id.first.title').and_return('the title')
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20110324/0fca77fe/attachment.html>


More information about the rspec-users mailing list