Skip to content

RSpec::Sidekiq::NullObject wants respond_to_missing? #274

@DmitryBarskov

Description

@DmitryBarskov

Currently RSpec::Sidekiq::NullObject is defined like so

# lib/rspec/sidekiq/batch.rb:7-13
module RSpec
  module Sidekiq
    class NullObject
      def method_missing(*args, &block)
        self
      end
    end
  end
end

but when overriding #method_missing, #respond_to_missing? should be overridden too.
Current implementation leads to a bug when using delegation.

# spec/rspec_sidekiq_null_batch_spec.rb
require "rails_helper"

class SidekiqBatchEssentially < SimpleDelegator
end

RSpec.describe "Delegation error, issue 274" do
  it "delegation works" do
    batch = SidekiqBatchEssentially.new(Sidekiq::Batch.new)

    expect do
      batch.callback_queue = "should_not_fail"
      batch.callback_queue
    end.not_to raise_error
  end
end

Suggested fix:

# lib/rspec/sidekiq/batch.rb:1-17
# frozen_string_literal: true

require "rspec/core"
require "rspec/support/fuzzy_matcher"

if defined? Sidekiq::Batch
  module RSpec
    module Sidekiq
      class NullObject
        def method_missing(*args, &block)
          self
        end

        def respond_to_missing?(*_args)
          true
        end
      end
# ...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions