Skip to content

Cannot test paginated AR collection in view spec - RSpec 6 #537

Closed Answered by ddnexus
cesc1989 asked this question in Q&A
Discussion options

You must be logged in to vote

OK, so there are quite a few things that don't make sense here.

The pagy* controller methods accept a collection (which in your case should be an AR scope, not an array) and return an array of 2 items: the pagy object and the paginated collection items, so you are using it improperly. That way the expenditures in your test is an array of those 2 items: no wonder it gives errors.

However, you are testing a view, and since you are mocking it rather than running your actual code like in an integration test, you don't need to paginate anything at all with pagy. Pagy is extensively tested with 100% of coverage, so DRY.

In order to test your view you have just to assign the local variables, so …

Replies: 3 comments 5 replies

Comment options

You must be logged in to vote
3 replies
@cesc1989
Comment options

@benkoshy
Comment options

@cesc1989
Comment options

Comment options

You must be logged in to vote
2 replies
@cesc1989
Comment options

@cesc1989
Comment options

Answer selected by cesc1989
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants