lib/rimless/rspec/matchers.rb in rimless-1.2.0 vs lib/rimless/rspec/matchers.rb in rimless-1.3.0

- old
+ new

@@ -14,10 +14,11 @@ # Instantiate a new expectation object. # # @param schema [String, Symbol, nil] the expected message schema # @return [HaveSentKafkaMessage] the expectation instance def initialize(schema) + super @schema = schema @args = {} @data = {} @messages = [] set_expected_number(:exactly, 1) @@ -182,11 +183,11 @@ return true unless @schema begin Rimless.avro.decode(message[:encoded_data], schema_name: @schema.to_s) - return true + true rescue Avro::IO::SchemaMatchException false end end @@ -211,12 +212,11 @@ message[:data].merge(@data.deep_stringify_keys) == message[:data] end # Setup the +WaterDrop+ spies and record each sent message. - # - # rubocop:disable Metrics/AbcSize because of the message decoding + # because of the message decoding # rubocop:disable Metrics/MethodLength dito def listen_to_messages decode = proc do |encoded| { encoded_data: encoded, data: Rimless.avro.decode(encoded) } end @@ -229,10 +229,9 @@ allow(WaterDrop::AsyncProducer).to receive(:call) do |data, **args| @messages << { args: args, type: :async }.merge(decode[data]) nil end end - # rubocop:enable Metrics/AbcSize # rubocop:enable Metrics/MethodLength # Serve the RSpec API and return the positive failure message. # # @return [String] the message to display