Class: Rimless::RSpec::Matchers::HaveSentKafkaMessage
- Inherits:
-
RSpec::Matchers::BuiltIn::BaseMatcher
- Object
- RSpec::Matchers::BuiltIn::BaseMatcher
- Rimless::RSpec::Matchers::HaveSentKafkaMessage
- Includes:
- RSpec::Mocks::ExampleMethods
- Defined in:
- lib/rimless/rspec/matchers.rb
Overview
The Apache Kafka message expectation.
Instance Method Summary collapse
-
#at_least(count) ⇒ HaveSentKafkaMessage
Set the expected amount of message (at least).
-
#at_most(count) ⇒ HaveSentKafkaMessage
Set the expected amount of message (at most).
-
#capture { ... } ⇒ Array<Hash{Symbol => Mixed}>
Capture all Apache Kafka messages of the given block.
-
#does_not_match?(proc) ⇒ Boolean
The actual RSpec API check for the expectation (negative).
-
#exactly(count) ⇒ HaveSentKafkaMessage
Set the expected amount of message (exactly).
-
#initialize(schema) ⇒ HaveSentKafkaMessage
constructor
Instantiate a new expectation object.
-
#matches?(proc) ⇒ Boolean
The actual RSpec API check for the expectation.
-
#once ⇒ HaveSentKafkaMessage
Just syntactic sugar for a regular exactly(:once) call.
-
#supports_block_expectations? ⇒ Boolean
Serve the RSpec matcher API and signalize we support block evaluation.
-
#thrice ⇒ HaveSentKafkaMessage
Just syntactic sugar for a regular exactly(:thrice) call.
-
#times ⇒ HaveSentKafkaMessage
Just syntactic sugar.
-
#twice ⇒ HaveSentKafkaMessage
Just syntactic sugar for a regular exactly(:twice) call.
-
#with(**args) ⇒ HaveSentKafkaMessage
Collect the expectation arguments for the Kafka message passing.
-
#with_data(**args) ⇒ HaveSentKafkaMessage
Collect the expectations for the encoded message.
Constructor Details
#initialize(schema) ⇒ HaveSentKafkaMessage
Instantiate a new expectation object.
16 17 18 19 20 21 22 23 |
# File 'lib/rimless/rspec/matchers.rb', line 16 def initialize(schema) super @schema = schema @args = {} @data = {} @messages = [] set_expected_number(:exactly, 1) end |
Instance Method Details
#at_least(count) ⇒ HaveSentKafkaMessage
Set the expected amount of message (at least).
67 68 69 70 |
# File 'lib/rimless/rspec/matchers.rb', line 67 def at_least(count) set_expected_number(:at_least, count) self end |
#at_most(count) ⇒ HaveSentKafkaMessage
Set the expected amount of message (at most).
76 77 78 79 |
# File 'lib/rimless/rspec/matchers.rb', line 76 def at_most(count) set_expected_number(:at_most, count) self end |
#capture { ... } ⇒ Array<Hash{Symbol => Mixed}>
Capture all Apache Kafka messages of the given block.
29 30 31 32 |
# File 'lib/rimless/rspec/matchers.rb', line 29 def capture(&block) matches?(block) @messages end |
#does_not_match?(proc) ⇒ Boolean
The actual RSpec API check for the expectation (negative).
rubocop:disable Naming/PredicatePrefix – because we just serve
the RSpec API here
139 140 141 142 143 |
# File 'lib/rimless/rspec/matchers.rb', line 139 def does_not_match?(proc) set_expected_number(:at_least, 1) !matches?(proc) end |
#exactly(count) ⇒ HaveSentKafkaMessage
Set the expected amount of message (exactly).
58 59 60 61 |
# File 'lib/rimless/rspec/matchers.rb', line 58 def exactly(count) set_expected_number(:exactly, count) self end |
#matches?(proc) ⇒ Boolean
The actual RSpec API check for the expectation.
120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/rimless/rspec/matchers.rb', line 120 def matches?(proc) unless proc.is_a? Proc raise ArgumentError, 'have_sent_kafka_message and ' \ 'sent_kafka_message only support block ' \ 'expectations' end proc.call check end |
#once ⇒ HaveSentKafkaMessage
Just syntactic sugar for a regular exactly(:once) call.
91 92 93 |
# File 'lib/rimless/rspec/matchers.rb', line 91 def once exactly(:once) end |
#supports_block_expectations? ⇒ Boolean
Serve the RSpec matcher API and signalize we support block evaluation.
112 113 114 |
# File 'lib/rimless/rspec/matchers.rb', line 112 def supports_block_expectations? true end |
#thrice ⇒ HaveSentKafkaMessage
Just syntactic sugar for a regular exactly(:thrice) call.
105 106 107 |
# File 'lib/rimless/rspec/matchers.rb', line 105 def thrice exactly(:thrice) end |
#times ⇒ HaveSentKafkaMessage
Just syntactic sugar.
84 85 86 |
# File 'lib/rimless/rspec/matchers.rb', line 84 def times self end |
#twice ⇒ HaveSentKafkaMessage
Just syntactic sugar for a regular exactly(:twice) call.
98 99 100 |
# File 'lib/rimless/rspec/matchers.rb', line 98 def twice exactly(:twice) end |
#with(**args) ⇒ HaveSentKafkaMessage
Collect the expectation arguments for the Kafka message passing. (eg. topic)
39 40 41 42 |
# File 'lib/rimless/rspec/matchers.rb', line 39 def with(**args) @args = args self end |
#with_data(**args) ⇒ HaveSentKafkaMessage
Collect the expectations for the encoded message. The passed message will be decoded accordingly for the check.
49 50 51 52 |
# File 'lib/rimless/rspec/matchers.rb', line 49 def with_data(**args) @data = args self end |