Sha256: 5de3df8e14479f9a775a1a28832f9bffb093e8f5d3309b0f33afd3f178135239

Contents?: true

Size: 1.43 KB

Versions: 2

Compression:

Stored size: 1.43 KB

Contents

require 'cucumber/messages'

module Cucumber
  module Messages
    describe 'messages' do
      it "can be serialised over an ndjson stream" do
        outgoing_messages = [
          {'source' => {'data' => 'Feature: Hello'}},
          {'attachment' => {'binary' => [1,2,3,4].pack('C*')}}
        ]

        io = StringIO.new
        write_outgoing_messages(outgoing_messages, io)

        io.rewind
        incoming_messages = NdjsonToMessageEnumerator.new(io)

        expect(incoming_messages.to_a).to(eq(outgoing_messages))
      end

      it "ignores empty lines" do
        outgoing_messages = [
          {'source' => {'data' => 'Feature: Hello'}},
          {'attachment' => {'binary' => [1,2,3,4].pack('C*')}}
        ]

        io = StringIO.new
        write_outgoing_messages(outgoing_messages, io)
        io.write("\n\n")

        io.rewind
        incoming_messages = NdjsonToMessageEnumerator.new(io)

        expect(incoming_messages.to_a).to(eq(outgoing_messages))
      end

      it "includes offending line in error message" do
        io = StringIO.new
        io.puts('BLA BLA')

        io.rewind
        incoming_messages = NdjsonToMessageEnumerator.new(io)

        expect { incoming_messages.to_a }.to(raise_error('Not JSON: BLA BLA'))
      end

      def write_outgoing_messages(messages, out)
        messages.each do |message|
          out.write(message.to_json)
          out.write("\n")
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
cucumber-messages-16.0.1 spec/cucumber/messages/ndjson_serialization_spec.rb
cucumber-messages-16.0.0 spec/cucumber/messages/ndjson_serialization_spec.rb