From dc41d81bb313b483344428178a6fd8888377b64d Mon Sep 17 00:00:00 2001 From: Matt Wynne Date: Mon, 15 May 2017 22:08:27 +0100 Subject: [PATCH] Add a (failing) test for better source output for scenario outline steps --- .../formatter/event_stream/plugin_spec.rb | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/event-protocol/ruby/spec/cucumber/formatter/event_stream/plugin_spec.rb b/event-protocol/ruby/spec/cucumber/formatter/event_stream/plugin_spec.rb index 4afffba08b0..b4031ad9f63 100644 --- a/event-protocol/ruby/spec/cucumber/formatter/event_stream/plugin_spec.rb +++ b/event-protocol/ruby/spec/cucumber/formatter/event_stream/plugin_spec.rb @@ -2,6 +2,7 @@ require 'cucumber/configuration' require 'cucumber/core/test/case' require 'cucumber/hooks' +require 'cucumber/core/gherkin/document' describe Cucumber::Formatter::EventStream::Plugin do describe "when the test run starts" do @@ -81,6 +82,45 @@ expect(message['steps'][0]['actionLocation']).to eq({ 'uri' => 'features/step_definitions/steps.rb', 'line' => 1 }) expect(message['steps'][0]['sourceLocation']).to eq({ 'uri' => 'features/test.feature', 'line' => 4 }) end + + it "emits a source location with two lines for a Gherkin Scenario Outline step" do + test_cases = compile('features/test.feature', %{Feature: + Scenario Outline: + Given this step is + + Examples: + | status | + | passing | + }) + + passing_test_case = test_cases[0]. + with_steps(test_cases[0].test_steps.map { |test_step| test_step.with_action { } }) + output = run_test_cases([ passing_test_case ]) + message = output.find { |message| message['type'] == 'test-case-prepared' } + expect(message['steps'][0]['sourceLocation']).to eq({ 'uri' => 'features/test.feature', 'lines' => [ 7, 3 ]}) + end + + def compile(file, gherkin) + core = Object.new.extend(Cucumber::Core) + receiver = Receiver.new + core.compile([Cucumber::Core::Gherkin::Document.new(file, gherkin)], receiver) + receiver.test_cases + end + + class Receiver + attr_reader :test_cases + + def initialize + @test_cases = [] + end + + def test_case(test_case) + @test_cases << test_case + end + + def done + end + end end def location(file_colon_line)