Sha256: cec8022c6e4ee35c3b527f4927ee5e95c75a82c40cd8d977bdd23f03c38044d7

Contents?: true

Size: 1.83 KB

Versions: 4

Compression:

Stored size: 1.83 KB

Contents

require 'rspec'
require 'gherkin/stream/parser_message_stream'

module Gherkin
  module Stream
    describe ParserMessageStream do
      let(:feature_content) {
        "Feature: my feature\n" \
        "  Scenario: a scenario\n" \
        "    Given some context"
      }

      let(:source_feature) {
        {
          uri: '//whatever/uri',
          data: feature_content,
          mediaType: 'text/x.cucumber.gherkin+plain'
        }
      }

      let(:options) {
        {
          include_gherkin_document: true,
        }
      }

      let(:gherkin_document) {
        ParserMessageStream.new([], [source_feature], options).messages.first[:gherkinDocument]
      }

      let(:scenario_id) { gherkin_document[:feature][:children].first[:scenario][:id] }

      context '#messages' do
        it "raises an exception on second iteration" do
          messages = ParserMessageStream.new([], [source_feature], options).messages

          expect { messages.map(&:to_s) }.not_to raise_exception
          expect { messages.map(&:to_s) }.to raise_exception(Gherkin::DoubleIterationException)
        end
      end

      context 'options.id_generator' do
        context 'when not set' do
          it 'generates random UUIDs' do
            expect(scenario_id).to match(/[0-9a-fA-F]{8}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{12}/)
          end
        end


        context 'when set' do
          let(:id_generator) { double }
          let(:options) {
            {
              include_gherkin_document: true,
              id_generator: id_generator
            }
          }

          it 'uses the generator instance to produce the IDs' do
            allow(id_generator).to receive(:new_id).and_return('some-random-id')
            expect(scenario_id).to eq('some-random-id')
          end
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
cucumber-gherkin-19.0.3 spec/gherkin/stream/parser_message_stream_spec.rb
cucumber-gherkin-19.0.2 spec/gherkin/stream/parser_message_stream_spec.rb
cucumber-gherkin-19.0.1 spec/gherkin/stream/parser_message_stream_spec.rb
cucumber-gherkin-19.0.0 spec/gherkin/stream/parser_message_stream_spec.rb