Sha256: 29e8cbd049cbcaed74c4ae5b710b81e163a69d458a52b0da29d42c8290efe1f3

Contents?: true

Size: 1.85 KB

Versions: 20

Compression:

Stored size: 1.85 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) {
        Cucumber::Messages::Source.new({
          uri: '//whatever/uri',
          data: feature_content,
          media_type: 'text/x.cucumber.gherkin+plain'
        })
      }

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

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

      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

20 entries across 20 versions & 1 rubygems

Version Path
cucumber-gherkin-18.1.1 spec/gherkin/stream/parser_message_stream_spec.rb
cucumber-gherkin-18.1.0 spec/gherkin/stream/parser_message_stream_spec.rb
cucumber-gherkin-18.0.0 spec/gherkin/stream/parser_message_stream_spec.rb
cucumber-gherkin-17.0.2 spec/gherkin/stream/parser_message_stream_spec.rb
cucumber-gherkin-17.0.1 spec/gherkin/stream/parser_message_stream_spec.rb
cucumber-gherkin-17.0.0 spec/gherkin/stream/parser_message_stream_spec.rb
cucumber-gherkin-16.0.0 spec/gherkin/stream/parser_message_stream_spec.rb
cucumber-gherkin-15.0.2 spec/gherkin/stream/parser_message_stream_spec.rb
cucumber-gherkin-15.0.1 spec/gherkin/stream/parser_message_stream_spec.rb
cucumber-gherkin-15.0.0 spec/gherkin/stream/parser_message_stream_spec.rb
cucumber-gherkin-14.2.0 spec/gherkin/stream/parser_message_stream_spec.rb
cucumber-gherkin-14.1.0 spec/gherkin/stream/parser_message_stream_spec.rb
cucumber-gherkin-14.0.1 spec/gherkin/stream/parser_message_stream_spec.rb
cucumber-gherkin-14.0.0 spec/gherkin/stream/parser_message_stream_spec.rb
cucumber-gherkin-13.0.0 spec/gherkin/stream/parser_message_stream_spec.rb
cucumber-gherkin-12.0.0 spec/gherkin/stream/parser_message_stream_spec.rb
cucumber-gherkin-11.0.0 spec/gherkin/stream/parser_message_stream_spec.rb
cucumber-gherkin-10.0.0 spec/gherkin/stream/parser_message_stream_spec.rb
cucumber-gherkin-9.2.0 spec/gherkin/stream/parser_message_stream_spec.rb
cucumber-gherkin-9.1.0 spec/gherkin/stream/parser_message_stream_spec.rb