Module: Lepus::Testing
- Defined in:
- lib/lepus/testing.rb,
lib/lepus/testing/exchange.rb,
lib/lepus/testing/rspec_matchers.rb,
lib/lepus/testing/message_builder.rb
Defined Under Namespace
Modules: RSpecMatchers Classes: Exchange, MessageBuilder
Class Method Summary collapse
-
.clear_all_messages! ⇒ Object
Clear all messages from all fake exchanges.
-
.consumer_capture_errors! ⇒ Object
Disable consumer error re-raising (default behavior converts to :reject).
-
.consumer_perform(consumer_class, message_or_payload) ⇒ Symbol
Test a consumer with a message.
-
.consumer_raise_errors! ⇒ Object
When enabled, consumer exceptions are re-raised instead of being converted to :reject This is useful in specs, so RSpec can capture failures instead of false positives.
-
.consumer_raise_errors? ⇒ Boolean
Returns true if consumer errors should be re-raised in tests.
-
.disable! ⇒ Object
Disable fake publishing mode and consumer error re-raising.
-
.enable! ⇒ Object
Enable fake publishing mode and consumer error re-raising.
-
.exchange(name) ⇒ Object
Get a specific fake exchange by name.
-
.exchanges ⇒ Object
Get all fake exchanges.
-
.fake_publisher! ⇒ Object
Enable fake publishing mode for testing When enabled, messages are stored in fake exchanges instead of being sent to RabbitMQ.
-
.fake_publisher_disable! ⇒ Object
Disable fake publishing mode for testing.
-
.fake_publisher_enabled? ⇒ Boolean
Check if fake publishing is enabled.
-
.message_builder ⇒ MessageBuilder
Create a message builder for custom scenarios.
-
.producer_messages(producer_class) ⇒ Object
Get messages for a specific producer class.
Class Method Details
.clear_all_messages! ⇒ Object
Clear all messages from all fake exchanges
55 56 57 |
# File 'lib/lepus/testing.rb', line 55 def Exchange. end |
.consumer_capture_errors! ⇒ Object
Disable consumer error re-raising (default behavior converts to :reject)
45 46 47 |
# File 'lib/lepus/testing.rb', line 45 def consumer_capture_errors! @consumer_raise_errors_enabled = false end |
.consumer_perform(consumer_class, message_or_payload) ⇒ Symbol
Test a consumer with a message
86 87 88 89 90 |
# File 'lib/lepus/testing.rb', line 86 def consumer_perform(consumer_class, ) = () consumer = consumer_class.new consumer.process_delivery(.delivery_info, ., .payload) end |
.consumer_raise_errors! ⇒ Object
When enabled, consumer exceptions are re-raised instead of being converted to :reject This is useful in specs, so RSpec can capture failures instead of false positives
40 41 42 |
# File 'lib/lepus/testing.rb', line 40 def consumer_raise_errors! @consumer_raise_errors_enabled = true end |
.consumer_raise_errors? ⇒ Boolean
Returns true if consumer errors should be re-raised in tests
50 51 52 |
# File 'lib/lepus/testing.rb', line 50 def consumer_raise_errors? @consumer_raise_errors_enabled == true end |
.disable! ⇒ Object
Disable fake publishing mode and consumer error re-raising
17 18 19 20 |
# File 'lib/lepus/testing.rb', line 17 def disable! fake_publisher_disable! consumer_capture_errors! end |
.enable! ⇒ Object
Enable fake publishing mode and consumer error re-raising
11 12 13 14 |
# File 'lib/lepus/testing.rb', line 11 def enable! fake_publisher! consumer_raise_errors! end |
.exchange(name) ⇒ Object
Get a specific fake exchange by name
65 66 67 |
# File 'lib/lepus/testing.rb', line 65 def exchange(name) Exchange[name] end |
.exchanges ⇒ Object
Get all fake exchanges
60 61 62 |
# File 'lib/lepus/testing.rb', line 60 def exchanges Exchange.all end |
.fake_publisher! ⇒ Object
Enable fake publishing mode for testing When enabled, messages are stored in fake exchanges instead of being sent to RabbitMQ
24 25 26 |
# File 'lib/lepus/testing.rb', line 24 def fake_publisher! @fake_publisher_enabled = true end |
.fake_publisher_disable! ⇒ Object
Disable fake publishing mode for testing
34 35 36 |
# File 'lib/lepus/testing.rb', line 34 def fake_publisher_disable! @fake_publisher_enabled = false end |
.fake_publisher_enabled? ⇒ Boolean
Check if fake publishing is enabled
29 30 31 |
# File 'lib/lepus/testing.rb', line 29 def fake_publisher_enabled? @fake_publisher_enabled == true end |
.message_builder ⇒ MessageBuilder
Create a message builder for custom scenarios
94 95 96 |
# File 'lib/lepus/testing.rb', line 94 def MessageBuilder.new end |
.producer_messages(producer_class) ⇒ Object
Get messages for a specific producer class
70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/lepus/testing.rb', line 70 def (producer_class) return [] unless producer_class.respond_to?(:definition) begin exchange_name = producer_class.definition.exchange_name Exchange[exchange_name]. rescue # If there's an error getting the exchange name, return empty array [] end end |