Class: Messaging::Fixtures::Writer
- Inherits:
-
Object
- Object
- Messaging::Fixtures::Writer
- Includes:
- Initializer, TestBench::Fixture
- Defined in:
- lib/messaging/fixtures/writer.rb
Constant Summary collapse
- Error =
Class.new(RuntimeError)
Class Method Summary collapse
Instance Method Summary collapse
- #assert_expected_version(expected_version) ⇒ Object
- #assert_reply_stream_name(reply_stream_name) ⇒ Object
- #assert_stream_name(stream_name) ⇒ Object
- #call ⇒ Object
Class Method Details
.build(writer, message_class, &test_block) ⇒ Object
11 12 13 14 15 16 17 18 19 20 |
# File 'lib/messaging/fixtures/writer.rb', line 11 def self.build(writer, , &test_block) data = get_data(writer, ) = data&. stream_name = data&.stream_name expected_version = data&.expected_version reply_stream_name = data&.reply_stream_name new(, , stream_name, expected_version, reply_stream_name, test_block) end |
.get_data(writer, message_class) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/messaging/fixtures/writer.rb', line 22 def self.get_data(writer, ) sink = writer.sink records = sink.written_records.select do |record| record.data..class == end if records.length > 1 raise Error, "More than one message written (Message Class: #{message_class})" end if records.empty? return nil end records.first.data end |
Instance Method Details
#assert_expected_version(expected_version) ⇒ Object
77 78 79 80 81 82 83 84 |
# File 'lib/messaging/fixtures/writer.rb', line 77 def assert_expected_version(expected_version) test "Expected version" do detail "Expected Version: #{expected_version}" detail "Written Expected Version: #{self.expected_version}" assert(expected_version == self.expected_version) end end |
#assert_reply_stream_name(reply_stream_name) ⇒ Object
86 87 88 89 90 91 92 93 |
# File 'lib/messaging/fixtures/writer.rb', line 86 def assert_reply_stream_name(reply_stream_name) test "Reply stream name" do detail "Reply stream Name: #{reply_stream_name}" detail "Written reply stream Name: #{self.reply_stream_name}" assert(reply_stream_name == self.reply_stream_name) end end |
#assert_stream_name(stream_name) ⇒ Object
68 69 70 71 72 73 74 75 |
# File 'lib/messaging/fixtures/writer.rb', line 68 def assert_stream_name(stream_name) test "Stream name" do detail "Stream Name: #{stream_name}" detail "Written Stream Name: #{self.stream_name}" assert(stream_name == self.stream_name) end end |
#call ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/messaging/fixtures/writer.rb', line 40 def call context_name = "Write: #{message_class.message_type}" context context_name do if test_block.nil? raise Error, "Write fixture must be executed with a block" end detail "Message Class: #{message_class.inspect}" written = !.nil? test "Written" do if not written detail "Remaining message tests are skipped" end assert(written) end return if not written test_block.call(self) end end |