I have added the TestHelpers module which includes methods to stub out the current_page, total_count and other methods used in the pagination partials, to allow spec-ing the controllers with render_views. The code is fairly simple and I have tested with all 4 mocking frameworks supported by RSpec. Also I have asked (and they have already implemented it) extra functionality from rspec-core so that it is possible for my TestHelpers to automatically detect the mocking framework being used and generate the correct stub calls. TestHelpers have been tested with both rspec-core-2.5.1 (without the extra functionality) and with the git version of it (with the extra functionality).
I don't know if this better sits together with kaminari in the same gem, or I should create a kaminari-rspec gem (tentative name) of my own. As the owner of kaminari, I let the choice to you, and I am fine with both solutions.
Added TestHelpers for RSpec render_views
Fixed typos in README.rdoc
Added limit for current_page
Yes, this is really good. Please add this in ;)
There seems to be something missing here -- the documentation references stub_pagination_methods to make use of the automatic mocking framework discovery, but no such method is actually defined in the commits. Maybe you meant stub_pagination there, but that method never calls discover_mock_framework so the discovery doesn't work. Otherwise though this works well for me with the manual method of stub_pagination(thing, :mock => :rspec) -- thanks!!
stub_pagination(thing, :mock => :rspec)
Side note -- I'm not sure if you meant to add .idea to the .gitignore uncommented, but if so you may have misread the whole spiel right above it and it's downright comical :-) I love that public service announcement in the .gitignore @amatsuda, I might link people to it in the future when they violate that pet peeve which I share with you :-) Please take no offense @nessche, just made me laugh!
@ches: you are right on all counts, the right method to call is stub_pagination and since at the time of the last commit the gem version of RSpec did not include the functionality for the framework discovery, I did remove the call to discover_mock_framework, thinking that I would change it back when the updated RSpec gem was available. Obviously I forgot.
About the .gitignore, no offense taken. I meant to add it commented. But it must have been one late night commit, and having .idea added to the global gitignore I didn't notice the difference
This did not make it into master, right? Why not?
Don't know the reason why it was not pulled in a year ago when I made it, now I suspect it would need some updating to match the current version of the library.
@amatsuda: do you think this functionality is to be merged to the library or should I just create a kaminari-test-helpers gem which would live a separate life? I would prefer the first option.
This could use a rebase, if anyone is interested
@nessche I would also still consider this useful.
Given the interest of people, and the lack of interest from @amatsuda , I guess it should go to a separate gem. I am currently on holiday, and I had to promise my family that I would stay clear of "those things that should not take more than couple of hours and instead take a few days" 😄 . But I'll be back in couple of weeks and will try to extract this functionality into a separate gem.
@nessche Sounds good, please release your code as a gem. And be sure to add a link to this ticket incase anyone wants to try it!
the code is now in a gem of its called kaminari-rspec. Current version is 0.14.1.b0. The version will follow the one from this gem, possibly with beta and rc releases (depending on the impact of the changes).
There is also an example Rails app which shows how to use the gem with the different mocking framework it supports.
It is still a beta release, so it can still be a bit shaky. I hope to be able to put in a bit more effort this week into testing (especially on different rubies) and documentation.
Contributors and comments are highly appreciated!