Read more

How to change will_paginate's "per_page" in Cucumber features

Arne Hartherz
July 30, 2012Software engineer at makandra GmbH

The will_paginate gem Show archive.org snapshot will show a default of 30 records per page.
If you want to test pagination in a Cucumber feature, you don't want to create 31 records just for that.

Illustration online protection

Rails professionals since 2007

Our laser focus on a single technology has made us a leader in this space. Need help?

  • We build a solid first version of your product
  • We train your development team
  • We rescue your project in trouble
Read more Show archive.org snapshot

Instead, you probably want to modify the number of items shown, by saying something like this:

Given we paginate after 2 users

Using the following step definition, you now can! :)

require 'cucumber/rspec/doubles'

Given /^paginate after (\d+) (.*)$/ do |per_page, model_name|
  model = model_name.singularize.gsub(/[^A-Z]+/, '_').camelize.constantize
  allow(model).to receive(:per_page).and_return(per_page)
end

It will change the pagination settings per model, so you can apply different pagination rules:

Given we paginate after 2 users
  And we paginate after 5 blog posts
Posted by Arne Hartherz to makandra dev (2012-07-30 15:45)