Skip to content

Allow running test suite without PAGINATOR set #55

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed

Conversation

terceiro
Copy link

@terceiro terceiro commented Feb 4, 2016

kaminari is the default, so let's assume that. Otherwise, if PAGINATOR
is not set while running the test suite, you will always get a failure
like this:

  1) ApiPagination Using kaminari should accept paginate_array_options option
     Failure/Error: ApiPagination.config.paginator = ENV['PAGINATOR'].to_sym
     NoMethodError:
       undefined method `to_sym' for nil:NilClass
     # ./spec/api-pagination_spec.rb:13:in `block (3 levels) in <top (required)>'

With this patch applied, you get:

$ rspec 
No PAGINATOR set. Defaulting to kaminari. To test against will_paginate, run `PAGINATOR=will_paginate bundle exec rspec`

Randomized with seed 32658
........................................................

Finished in 0.16081 seconds (files took 1.09 seconds to load)
56 examples, 0 failures

Randomized with seed 32658

$ PAGINATOR=will_paginate rspec 

Randomized with seed 22358
.........................................................

Finished in 0.16365 seconds (files took 1.25 seconds to load)
57 examples, 0 failures

Randomized with seed 22358

$ PAGINATOR=kaminari rspec 

Randomized with seed 60733
........................................................

Finished in 0.16405 seconds (files took 1.08 seconds to load)
56 examples, 0 failures

Randomized with seed 60733

kaminari is the default, so let's assume that. Otherwise, if PAGINATOR
is not set while running the test suite, you will always get a failure
like this:

  1) ApiPagination Using kaminari should accept paginate_array_options option
     Failure/Error: ApiPagination.config.paginator = ENV['PAGINATOR'].to_sym
     NoMethodError:
       undefined method `to_sym' for nil:NilClass
     # ./spec/api-pagination_spec.rb:13:in `block (3 levels) in <top (required)>'
@davidcelis
Copy link
Owner

Hey @terceiro, thanks for the PR! This solution looks pretty good, though I think I'd rather just go and refactor the bit in spec_helper that sets the Paginator:

if ENV['PAGINATOR']
  require ENV['PAGINATOR']
  ApiPagination.config.paginator = ENV['PAGINATOR'].to_sym
else
  warn 'No PAGINATOR set. Defaulting to kaminari. To test against will_paginate, run `PAGINATOR=will_paginate bundle exec rspec`'
  require 'kaminari'
  ApiPagination.config.paginator = :kaminari
end

Maybe something a bit more like "if ENV['PAGINATOR'] hasn't been set, print the warning and set it to 'kaminari'. THEN require it and set the config value." What do you think?

@terceiro
Copy link
Author

terceiro commented Feb 4, 2016

yeah, works as well. You could just stick ENV['PAGINATOR'] ||= 'kaminari' at the top of spec_helper.rb and get rid of the whole else branch.

@terceiro
Copy link
Author

terceiro commented Feb 4, 2016

or maybe just set ENV['PAGINATOR'] in the else branch, which will keep the warning etc.

1 similar comment
@terceiro
Copy link
Author

terceiro commented Feb 4, 2016

or maybe just set ENV['PAGINATOR'] in the else branch, which will keep the warning etc.

@terceiro
Copy link
Author

terceiro commented Feb 4, 2016

@davidcelis actually ignore what I said, what you said makes a lot of more sense!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants