Skip to content

Commit

Permalink
Merge branch 'feat/DEX-2306/fix--producer-mock' into 'master'
Browse files Browse the repository at this point in the history
[DEX-2306] feat: remove mock and new fake class

Closes DEX-2306

See merge request nstmrt/rubygems/sbmt-kafka_producer!34
  • Loading branch information
Arlantir committed Jun 20, 2024
2 parents bed1f9b + 293df92 commit 7c0cef2
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 11 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

### Fixed

## [2.2.3] - 2024-06-20

### Fixed

- Remove mock for producer client
- A singleton class of the producer client has been added for testing

## [2.2.2] - 2024-06-15

### Fixed
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ The gem collects base producing metrics using [Yabeda](https://github.com/yabeda

## Testing

To stub a producer request to real Kafka broker, you can use a mock. To do this, please add `require "sbmt/kafka_producer/testing"` to the `spec/rails_helper.rb`.
To stub a producer request to real Kafka broker, you can use a fake class. To do this, please add `require "sbmt/kafka_producer/testing"` to the `spec/rails_helper.rb`.

## Development

Expand Down
28 changes: 19 additions & 9 deletions lib/sbmt/kafka_producer/testing/configure_producer_client.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,23 @@
# frozen_string_literal: true

RSpec.configure do |config|
config.before(:each) do
allow(Sbmt::KafkaProducer::KafkaClientFactory)
.to receive(:default_client)
.and_return(instance_double(WaterDrop::Producer, {produce_sync: true, produce_async: true}))

allow(Sbmt::KafkaProducer::KafkaClientFactory)
.to receive(:build)
.and_return(instance_double(WaterDrop::Producer, {produce_sync: true, produce_async: true}))
class FakeWaterDropClient
def produce_sync(*)
# no op
end

def produce_async(*)
# no op
end
end

Sbmt::KafkaProducer::KafkaClientFactory.singleton_class.prepend(
Module.new do
def default_client
@default_client ||= FakeWaterDropClient.new
end

def build(*)
@default_client ||= FakeWaterDropClient.new
end
end
)
2 changes: 1 addition & 1 deletion lib/sbmt/kafka_producer/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

module Sbmt
module KafkaProducer
VERSION = "2.2.2"
VERSION = "2.2.3"
end
end

0 comments on commit 7c0cef2

Please sign in to comment.