views:

23

answers:

1

rails 3 rspec-rails 2

in controller

def index @users = User.paginate :page => params[:page],:per_pae => 5 end

in view

User list

<% @users.each do |user|%

<%= user.name %>

<% end %> <%= will_paginate @users %>

Now I use rspec-rails 2 to test view.

require 'spec_helper'

describe "/users/index.html.erb" do
before(:each) do assign(:users, [ stub_model(User), stub_model(User), stub_model(User, stub_model(User) ]) end

it "renders a list of contracts" do render

rendered.should contain "User list"   end

end

Now I use rspec common to test it.I got: undefined method `total_pages' for #

How to stub paginate or some other way to fix it?

A: 

You want an instance of the will_paginate collection object:

before(:each) do
  page = 1
  per_page = 1
  total_entries = 4
  users = WillPaginate::Collection.create(page, per_page, total_entries) do |pager|
    pager.replace([stub_model(User), stub_model(User), stub_model(User), stub_model(User)])
  end
  assigns(:users, users)
end

This will give you access to all the attributes needed to correctly paginate.

heavysixer