Skip to content

Commit

Permalink
spec edit
Browse files Browse the repository at this point in the history
  • Loading branch information
Robgra13 committed Oct 23, 2024
1 parent ed404b5 commit 8b20c9e
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ AllCops:
Metrics/AbcSize:
Max: 19
Metrics/MethodLength:
Max: 20 # Increase the limit
Max: 20
6 changes: 6 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ GEM
rspec-mocks (3.13.2)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.13.0)
rspec-sidekiq (5.0.0)
rspec-core (~> 3.0)
rspec-expectations (~> 3.0)
rspec-mocks (~> 3.0)
sidekiq (>= 5, < 8)
rspec-support (3.13.1)
rubocop (1.66.1)
json (~> 2.3)
Expand Down Expand Up @@ -77,6 +82,7 @@ PLATFORMS
DEPENDENCIES
rake (~> 13.0)
rspec (~> 3.0)
rspec-sidekiq
rubocop (~> 1.40)
rubocop-performance
rubocop-rake
Expand Down
3 changes: 3 additions & 0 deletions lib/sidekiq-poison-pill-remedy.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# frozen_string_literal: true

require 'sidekiq_poison_pill_remedy'
File renamed without changes.
3 changes: 2 additions & 1 deletion sidekiq-poison-pill-remedy.gemspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

require_relative 'lib/remedy/version'
require_relative 'lib/version'

Gem::Specification.new do |spec|
spec.name = 'sidekiq-poison-pill-remedy'
Expand Down Expand Up @@ -34,6 +34,7 @@ Gem::Specification.new do |spec|
# Uncomment to register a new dependency of your gem
# spec.add_dependency "example-gem", "~> 1.0"
spec.add_dependency 'sidekiq'
spec.add_development_dependency 'rspec-sidekiq'

# For more information and examples about making a new gem, check out our
# guide at: https://bundler.io/guides/creating_gem.html
Expand Down
31 changes: 26 additions & 5 deletions spec/sidekiq_poison_pill_remedy_spec.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,34 @@
# frozen_string_literal: true

require_relative '../lib/sidekiq_poison_pill_remedy'
require 'sidekiq/testing'
require 'rspec-sidekiq'
require 'sidekiq'
require 'sidekiq-poison-pill-remedy'
require 'support/my_job'

RSpec.describe SidekiqPoisonPillRemedy do
it 'has a version number' do
expect(SidekiqPoisonPillRemedy::VERSION).not_to be nil
let(:job_args) { ['test_argument'] }
let(:jid) { MyJob.perform_async(*job_args) }

before do
Sidekiq::Testing.fake!
end

it 'does something useful' do
expect(true).to eq(true)
it 'moves job to poison_pill queue and logs message' do
begin
MyJob.new.perform('fail')
rescue StandardError
nil
end

job = Sidekiq::DeadSet.new.find_job(jid)

expect(job).not_to be_nil
expect(job.klass).to eq('MyJob')

SidekiqPoisonPillRemedy.remedy.call(nil, job)

poison_pill_job = Sidekiq::Queue.new('poison_pill').find_job(job.jid)
expect(poison_pill_job).not_to be_nil
end
end
13 changes: 13 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# frozen_string_literal: true

require 'bundler/setup'
require 'sidekiq/testing'
require 'rspec-sidekiq'
require 'sentry-ruby'
require 'sidekiq'
require 'sidekiq-poison-pill-remedy'

RSpec.configure do |config|
# Enable flags like --only-failures and --next-failure
config.example_status_persistence_file_path = '.rspec_status'
Expand All @@ -10,4 +17,10 @@
config.expect_with :rspec do |c|
c.syntax = :expect
end

config.before(:all) do
ENV['REDIS_URL'] ||= 'redis://localhost:6379/1'
end

Dir[File.join(__dir__, 'support', '**', '*.rb')].each { |f| require f }
end
7 changes: 7 additions & 0 deletions spec/support/my_job.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class MyJob
include Sidekiq::Worker

def perform(arg)
raise 'An error occurred!' if arg == 'fail'
end
end

0 comments on commit 8b20c9e

Please sign in to comment.