wspurgin / rspec-sidekiq

RSpec for Sidekiq
https://github.com/wspurgin/rspec-sidekiq
Other
662 stars 133 forks source link

Avoid methods from ActiveSupport, which is not required at runtime #120

Closed aprescott closed 7 years ago

aprescott commented 7 years ago

Version 3.0.0 included #109 which added the private unwrapped_job_options method:

def unwrapped_job_options(jobs)
  jobs = jobs.values if jobs.is_a?(Hash)
  jobs.flatten.map do |job|
    job.slice('at')
  end
end

The method relies on Hash#slice, which is in ActiveSupport but not Ruby. This broke one of my gem's test suites because the activesupport gem isn't declared as a runtime dependency, only a development dependency, causing a NoMethodError:

Failure/Error: expect(FooJob).to have_enqueued_job(1)

NoMethodError:
  undefined method `slice' for #<Hash:0x000000027b2df0>
# ./gemfiles/vendor/bundle/ruby/2.0.0/gems/rspec-sidekiq-3.0.0/lib/rspec/sidekiq/matchers/have_enqueued_job.rb:140:in `block in unwrapped_job_options'

I would actually like to avoid any runtime gem dependencies on ActiveSupport or other Rails libraries, since Sidekiq itself does not require Rails.

In addition to the use of slice, present? was also introduced in #81, which is only in ActiveSupport.

This PR corrects both problems.

It would be nice to have this be caught by the test suite, but I don't see a simple way of avoiding it because of the global nature of require. The reason it doesn't fail in this gem's own suite is because activejob is a development dependency, presumably to allow test coverage of ActiveJob support.

aprescott commented 7 years ago

I branched this off develop, on the assumption that it shouldn't be in master, which is behind develop right now and doesn't include the v3.0.0 commit. Let me know if master gets updated and I should use master as the base instead.

coveralls commented 7 years ago

Coverage Status

Coverage remained the same at 97.207% when pulling 782e41ec114d83246316726356592693d2ab5f9c on aprescott:no-runtime-activesupport into fd6ffa7564931aba67db76f52f5fb06327af0395 on philostler:develop.

packrat386 commented 7 years ago

Thanks for sending this. I'll release 3.0.1 with this fix soon.

aprescott commented 7 years ago

Thanks!

packrat386 commented 7 years ago

That's released now. https://github.com/philostler/rspec-sidekiq/releases/tag/v3.0.1

aprescott commented 7 years ago

Perfect, thanks!