Skip to content

Commit

Permalink
Raise error if using Sidekiq 7+ and be_delayed
Browse files Browse the repository at this point in the history
  • Loading branch information
wspurgin committed Jul 23, 2023
1 parent 4aac21e commit ac70060
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
11 changes: 10 additions & 1 deletion lib/rspec/sidekiq/configuration.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
require "rubygems"

module RSpec
module Sidekiq
class Configuration
attr_accessor :clear_all_enqueued_jobs, :enable_terminal_colours, :warn_when_jobs_not_processed_by_sidekiq
attr_accessor :clear_all_enqueued_jobs,
:enable_terminal_colours,
:warn_when_jobs_not_processed_by_sidekiq

def initialize
@clear_all_enqueued_jobs = true
@enable_terminal_colours = true

@warn_when_jobs_not_processed_by_sidekiq = true
end

def sidekiq_gte_7?
Gem::Version.new(::Sidekiq::VERSION) >= "7"
end
end
end
end
4 changes: 4 additions & 0 deletions lib/rspec/sidekiq/matchers/be_delayed.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ def be_delayed(*expected_arguments)

class BeDelayed
def initialize(*expected_arguments)
raise <<~MSG if RSpec::Sidekiq.configuration.sidekiq_gte_7?
Use of the be_delayed matcher with Sidekiq 7+ is not possible. Try refactoring to a Sidekiq Job with `perform_at` or `perform_in` and the `have_enqueued_sidekiq_job` matcher
MSG

@expected_arguments = expected_arguments
end

Expand Down
6 changes: 4 additions & 2 deletions spec/rspec/sidekiq/matchers/be_delayed_spec.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
require 'spec_helper'
require "spec_helper"

RSpec.describe RSpec::Sidekiq::Matchers::BeDelayed do
if RSpec.configuration.sidekiq_gte_7
skip("Be Delayed is only valid for Sidekiq <7")
it "should raise an error" do
expect { described_class.new }.to raise_error(/Use of the be_delayed matcher with Sidekiq 7\+ is not possible/)
end
else
let(:delay_subject) { RSpec::Sidekiq::Matchers::BeDelayed.new }
let(:delay_with_arguments_subject) { RSpec::Sidekiq::Matchers::BeDelayed.new Object }
Expand Down

0 comments on commit ac70060

Please sign in to comment.