Karafka-Testing 2.0 some breaking changes in the way consumer builder and message publishing is done.
Please upgrade your application to Karafka 2.0
first.
- Replace
#karafka_consumer_for
in your specs with#karafka.consumer_for
- Replace
#publish_for_karafka
in your specs with#karafka.produce
And that's all!
Below you can find same example written for Karafka 2.0
and 1.4
.
RSpec.describe CountersConsumer do
subject(:consumer) { karafka.consumer_for(:counters) }
let(:nr1_value) { rand }
let(:nr2_value) { rand }
let(:sum) { nr1_value + nr2_value }
before do
karafka.produce({ 'number' => nr1_value }.to_json)
karafka.produce({ 'number' => nr2_value }.to_json, partition: 2)
allow(Karafka.logger).to receive(:info)
end
it 'expects to log a proper message' do
expect(Karafka.logger).to receive(:info).with("Sum of 2 elements equals to: #{sum}")
consumer.consume
end
end
RSpec.describe InlineBatchConsumer do
subject(:consumer) { karafka_consumer_for(:counters) }
let(:nr1_value) { rand }
let(:nr2_value) { rand }
let(:sum) { nr1_value + nr2_value }
before do
publish_for_karafka({ 'number' => nr1_value }.to_json)
publish_for_karafka({ 'number' => nr2_value }.to_json, partition: 2)
allow(Karafka.logger).to receive(:info)
end
it 'expects to log a proper message' do
expect(Karafka.logger).to receive(:info).with("Sum of 2 elements equals to: #{sum}")
consumer.consume
end
end