Skip to content

Commit

Permalink
Update specs to use Yabeda RSpec matchers, refresh CI setup
Browse files Browse the repository at this point in the history
  • Loading branch information
Envek committed Feb 6, 2024
1 parent 8b97eb3 commit 6db6730
Show file tree
Hide file tree
Showing 8 changed files with 193 additions and 188 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ jobs:
name: RuboCop
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- uses: ruby/setup-ruby@v1
with:
ruby-version: "3.0"
ruby-version: "3.2"
bundler-cache: true
- name: Lint Ruby code with RuboCop
run: |
Expand Down
40 changes: 18 additions & 22 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,38 +10,34 @@ on:

jobs:
test:
name: 'Ruby ${{ matrix.ruby }}'
name: 'Ruby ${{ matrix.ruby }} × Sidekiq v${{ matrix.sidekiq }} × ActiveJob v${{ matrix.activejob }}'
# Skip running tests for local pull requests (use push event instead), run only for foreign ones
if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.owner.login != github.event.pull_request.base.repo.owner.login
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
include:
- ruby: '3.3'
sidekiq: '7'
activejob: '7.1'
- ruby: '3.2'
sidekiq: '7'
activejob: '7.0'
- ruby: '3.1'
sidekiq: '6'
activejob: '6.1'
- ruby: '3.0'
- ruby: '2.7'
- ruby: '2.6'
- ruby: '2.5'
container:
image: ruby:${{ matrix.ruby }}
env:
CI: true
sidekiq: '5'
activejob: '6.0'
env:
SIDEKIQ_VERSION: '${{ matrix.sidekiq }}'
ACTIVEJOB_VERSION: '${{ matrix.activejob }}'
steps:
- uses: actions/checkout@v2
- uses: actions/cache@v2
- uses: actions/checkout@v4
- uses: ruby/setup-ruby@v1
with:
path: vendor/bundle
key: bundle-${{ matrix.ruby }}-${{ hashFiles('**/*.gemspec') }}-${{ hashFiles('**/Gemfile') }}
restore-keys: |
bundle-${{ matrix.ruby }}-${{ hashFiles('**/*.gemspec') }}-${{ hashFiles('**/Gemfile') }}
bundle-${{ matrix.ruby }}-
- name: Upgrade Bundler to 2.0 (for older Rubies)
run: gem install bundler -v '~> 2.0'
- name: Bundle install
run: |
bundle config path vendor/bundle
bundle install
bundle update
ruby-version: ${{ matrix.ruby }}
bundler-cache: true
- name: Run RSpec
run: bundle exec rspec
11 changes: 10 additions & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ require:
- rubocop-rspec

AllCops:
TargetRubyVersion: 2.3
TargetRubyVersion: 2.5

Metrics/BlockLength:
Enabled: false
Expand Down Expand Up @@ -65,3 +65,12 @@ Metrics/MethodLength:

Metrics/AbcSize:
Max: 17

Style/SoleNestedConditional:
Enabled: false

Style/ExplicitBlockArgument:
Enabled: false

Gemspec/RequiredRubyVersion:
Enabled: false
28 changes: 27 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,36 @@ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
# Specify your gem's dependencies in yabeda-sidekiq.gemspec
gemspec

# rubocop:disable Bundler/DuplicatedGem
sidekiq_version = ENV.fetch("SIDEKIQ_VERSION", "~> 7.2")
case sidekiq_version
when "HEAD"
gem "sidekiq", git: "https://github.com/sidekiq/sidekiq.git"
else
sidekiq_version = "~> #{sidekiq_version}.0" if sidekiq_version.match?(/^\d+(?:\.\d+)?$/)
gem "sidekiq", sidekiq_version
end

activejob_version = ENV.fetch("ACTIVEJOB_VERSION", "~> 7.1")
case activejob_version
when "HEAD"
git "https://github.com/rails/rails.git" do
gem "activejob"
gem "activesupport"
gem "rails"
end
else
activejob_version = "~> #{activejob_version}.0" if activejob_version.match?(/^\d+\.\d+$/)
gem "activejob", activejob_version
gem "activesupport", activejob_version
end
# rubocop:enable Bundler/DuplicatedGem

group :development, :test do
gem "pry"
gem "pry-byebug", platform: :mri

gem "rubocop", "~> 0.80.0"
gem "yabeda", github: "yabeda-rb/yabeda", branch: "master" # For RSpec matchers
gem "rubocop", "~> 1.0"
gem "rubocop-rspec"
end
6 changes: 1 addition & 5 deletions lib/yabeda/sidekiq.rb
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,7 @@ def labelize(worker, job, queue)
end

def worker_class(worker, job)
if defined?(ActiveJob::QueueAdapters::SidekiqAdapter::JobWrapper)
if worker.is_a?(ActiveJob::QueueAdapters::SidekiqAdapter::JobWrapper) || worker == ActiveJob::QueueAdapters::SidekiqAdapter::JobWrapper
return job["wrapped"].to_s
end
end
worker = job["wrapped"] || worker
(worker.is_a?(String) || worker.is_a?(Class) ? worker : worker.class).to_s
end

Expand Down
17 changes: 16 additions & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
require "sidekiq/cli" # Fake that we're a worker to test worker-specific things
require "yabeda/sidekiq"

require "yabeda/rspec"
require "sidekiq/testing"
require "active_job"
require "active_job/queue_adapters/sidekiq_adapter"
Expand All @@ -29,8 +30,10 @@
Kernel.srand config.seed
config.order = :random

config.filter_run focus: true
config.run_all_when_everything_filtered = true

config.before(:all) do
Yabeda.configure!
Sidekiq::Testing.fake!
ActiveJob::QueueAdapters::SidekiqAdapter::JobWrapper.jobs.clear
end
Expand All @@ -39,6 +42,18 @@
Sidekiq::Queues.clear_all
Sidekiq::Testing.disable!
end

config.around do |ex|
next ex.run unless ex.metadata[:sidekiq]

begin
previous_mode = Sidekiq::Testing.__test_mode
Sidekiq::Testing.__set_test_mode(ex.metadata[:sidekiq])
ex.run
ensure
Sidekiq::Testing.__set_test_mode(previous_mode)
end
end
end

ActiveJob::Base.logger = Logger.new(nil)
7 changes: 5 additions & 2 deletions spec/support/sidekiq_inline_middlewares.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,22 @@
require "sidekiq/testing"

module SidekiqTestingInlineWithMiddlewares
# rubocop:disable Metrics/AbcSize
def push(job)
return super unless Sidekiq::Testing.inline?

job = Sidekiq.load_json(Sidekiq.dump_json(job))
job["jid"] ||= SecureRandom.hex(12)
job_class = Sidekiq::Testing.constantize(job["class"])
job_class = Object.const_get(job["class"])
job_instance = job_class.new
queue = (job_instance.sidekiq_options_hash || {}).fetch("queue", "default")
Sidekiq.server_middleware.invoke(job_instance, job, queue) do
server = Sidekiq.respond_to?(:default_configuration) ? Sidekiq.default_configuration : Sidekiq
server.server_middleware.invoke(job_instance, job, queue) do
job_instance.perform(*job["args"])
end
job["jid"]
end
# rubocop:enable Metrics/AbcSize
end

Sidekiq::Client.prepend(SidekiqTestingInlineWithMiddlewares)
Loading

0 comments on commit 6db6730

Please sign in to comment.