Sha256: 005c8d5b0154f193aa490a2f19919a17efa46647eae67a4d3ccc68a67907179b

Contents?: true

Size: 1.83 KB

Versions: 20

Compression:

Stored size: 1.83 KB

Contents

# frozen_string_literal: true

module Rimless
  # Some general RSpec testing stuff.
  module RSpec
    # A collection of Rimless/RSpec helpers.
    module Helpers
      # A simple helper to parse a blob of Apache Avro data.
      #
      # @param data [String] the Apache Avro blob
      # @param opts [Hash{Symbol => Mixed}] additional options
      # @return [Hash{String => Mixed}] the parsed payload
      def avro_parse(data, **opts)
        Rimless.avro_decode(data, **opts)
      end

      # A simple helper to fake a deserialized Apache Kafka message for
      # consuming.
      #
      # @param payload [Hash{Symbol => Mixed}] the message payload
      # @param topic [String, Hash{Symbol => Mixed}] the actual message
      #   topic (full as string, or parts via hash)
      # @return [OpenStruct] the fake deserialized Kafka message
      #
      # rubocop:disable Metrics/MethodLength because of the various properties
      # rubocop:disable Style/OpenStructUse because existing specs may rely
      #   on this data type
      def kafka_message(topic: nil, headers: {}, **payload)
        OpenStruct.new(
          topic: Rimless.topic(topic),
          headers: headers,
          payload: payload,
          is_control_record: false,
          key: nil,
          offset: 206,
          partition: 0,
          create_time: Time.current,
          receive_time: Time.current,
          deserialized: true
        )
      end
      # rubocop:enable Metrics/MethodLength
      # rubocop:enable Style/OpenStructUse

      # Capture all Apache Kafka messages of the given block.
      #
      # @yield the given block to capture the messages
      # @return [Array<Hash{Symbol => Mixed}>] the captured messages
      def capture_kafka_messages(&block)
        Rimless::RSpec::Matchers::HaveSentKafkaMessage.new(nil).capture(&block)
      end
    end
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
rimless-1.10.2 lib/rimless/rspec/helpers.rb
rimless-1.10.1 lib/rimless/rspec/helpers.rb
rimless-1.10.0 lib/rimless/rspec/helpers.rb
rimless-1.9.0 lib/rimless/rspec/helpers.rb
rimless-1.8.0 lib/rimless/rspec/helpers.rb
rimless-1.7.7 lib/rimless/rspec/helpers.rb
rimless-1.7.6 lib/rimless/rspec/helpers.rb
rimless-1.7.5 lib/rimless/rspec/helpers.rb
rimless-1.7.4 lib/rimless/rspec/helpers.rb
rimless-1.7.3 lib/rimless/rspec/helpers.rb
rimless-1.7.2 lib/rimless/rspec/helpers.rb
rimless-1.7.1 lib/rimless/rspec/helpers.rb
rimless-1.7.0 lib/rimless/rspec/helpers.rb
rimless-1.6.0 lib/rimless/rspec/helpers.rb
rimless-1.5.1 lib/rimless/rspec/helpers.rb
rimless-1.5.0 lib/rimless/rspec/helpers.rb
rimless-1.4.2 lib/rimless/rspec/helpers.rb
rimless-1.4.1 lib/rimless/rspec/helpers.rb
rimless-1.4.0 lib/rimless/rspec/helpers.rb
rimless-1.3.0 lib/rimless/rspec/helpers.rb