'change of behaviour for empty kwargs with `public_send`
I made an update of my Gemfile and since I've a spec that failed.
Here is the code:
module V1
##
# Pusher job
class PusherJob < BaseJob
queue_as :default
##
# Call V1::PusherLine#notify_now
def perform(pusher, delivery_action, *args, params: nil, **kwargs)
klass = pusher.safe_constantize
handler = params ? klass.with(**params) : klass.new
handler.public_send(delivery_action, *args, **kwargs)
end
end
end
RSpec.describe V1::PusherJob do
subject { job.perform(double_pusher_string, delivery_action, *args, kwargs) }
let(:job) { V1::PusherJob.new }
let(:kwargs) { {} }
describe '#perform' do
let(:double_pusher_string) { double(:pusher_string, safe_constantize: double_pusher_klass) }
let(:double_pusher_klass) { double(:pusher_klass, public_send: true) }
let(:double_instance) { double(:double_instance) }
let(:delivery_action) { Faker::Lorem.word }
let(:args) { Faker::Lorem.words(number: 4) }
context 'without params' do
it 'forms correctly the method' do
expect(double_pusher_string).to receive(:safe_constantize).once
expect(double_pusher_klass).to receive(:new).and_return(double_instance)
expect(double_instance).to receive(:public_send).with(delivery_action, *args, **kwargs)
subject
end
end
end
end
Error I got it
1) V1::PusherJob#perform without params forms correctly the method
Failure/Error: end
#<Double :double_instance> received :public_send with unexpected arguments
expected: ("dolorem", "rerum", "et", "et", "quia", {})
got: ("dolorem", "rerum", "et", "et", "quia")
Diff:
@@ -1 +1 @@
-["dolorem", "rerum", "et", "et", "quia", {}]
+["dolorem", "rerum", "et", "et", "quia"]
When I display arguments passed to public_send, kwargs is correct with the value {}. There is here a behaviour that I cannot catch.
BUT if I change value of my kwargs to a non-empty hash, it works.
I cannot find where this changes come from. Any idea?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
