Module: Rimless::RSpec::Helpers

Defined in:
lib/rimless/rspec/helpers.rb

Overview

A collection of Rimless/RSpec helpers.

Instance Method Summary collapse

Instance Method Details

#avro_parse(data) ⇒ Hash{String => Mixed}

A simple helper to parse a blob of Apache Avro data.

Parameters:

  • data (String)

    the Apache Avro blob

  • opts (Hash{Symbol => Mixed})

    additional options

Returns:

  • (Hash{String => Mixed})

    the parsed payload



13
14
15
# File 'lib/rimless/rspec/helpers.rb', line 13

def avro_parse(data, **)
  Rimless.avro_decode(data, **)
end

#capture_kafka_messages { ... } ⇒ Array<Hash{Symbol => Mixed}>

Capture all Apache Kafka messages of the given block.

Yields:

  • the given block to capture the messages

Returns:

  • (Array<Hash{Symbol => Mixed}>)

    the captured messages



50
51
52
# File 'lib/rimless/rspec/helpers.rb', line 50

def capture_kafka_messages(&)
  Rimless::RSpec::Matchers::HaveSentKafkaMessage.new(nil).capture(&)
end

#kafka_message(topic: nil, headers: {}, **payload) ⇒ OpenStruct

A simple helper to fake a deserialized Apache Kafka message for consuming.

rubocop:disable Metrics/MethodLength – because of the various

properties

rubocop:disable Style/OpenStructUse – because existing specs may rely

on this data type

Parameters:

  • payload (Hash{Symbol => Mixed})

    the message payload

  • topic (String, Hash{Symbol => Mixed}) (defaults to: nil)

    the actual message topic (full as string, or parts via hash)

Returns:

  • (OpenStruct)

    the fake deserialized Kafka message



29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/rimless/rspec/helpers.rb', line 29

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