Testing vs. stubbing pagination of will_paginate gem
27 June 2013I used a “rspec view” as customer acceptance test. My intention was not to test the “will_paginate” gem code, but to assure the customer, that there is a “pagination bar”!
At the beginning I tried to stub the pagination method like that
which was not working and did not make sense in a view spec (vs. a model spec). Thanks to hints from David:
“First, yours stubs :will_paginate. You definitely don’t want to do that if your specifying outcomes of will_paginate.”
and Mislav:
“The way to get pagination in the view is to create a fake paginated collection that appears to have more than 1 page. You only have 3 records, and with the default per_page value this is only 1 page of data.”
I changed the spec to
which did the trick and worked perfectly.
Find here the full rspec and will_paginate threads! Next time I probably would better use rspec features for that!