Rails + Kaminari with RSpec

The default rspec view specs don’t work so well for index pages if you have added Kaminari pagination.

The reason is the assigned variable in the controller is not an array, but is instead expected to respond to additional methods: current_page, num_pages, and limit_value.

Modifying the view spec like below appears to address the issue.

@books = [
  Factory.build(:book),
  Factory.build(:book)
]
@books.stub!(:current_page).and_return(1)
@books.stub!(:num_pages).and_return(1)
@books.stub!(:limit_value).and_return(1)
Advertisements
This entry was posted in rails and tagged , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s