From 27eb64f6243d5aa4a00756893f22313b4fc34521 Mon Sep 17 00:00:00 2001 From: Seiei Miyagi Date: Thu, 13 May 2021 09:37:04 +0900 Subject: [PATCH] Support scenario name substitution Co-authored-by: Wataru MIYAGUNI --- ...nario_outline_scenario_name_substitution.feature | 13 +++++++++++++ lib/turnip/node/scenario_outline.rb | 5 +++-- spec/builder_spec.rb | 12 ++++++++++++ spec/integration_spec.rb | 2 +- 4 files changed, 29 insertions(+), 3 deletions(-) create mode 100644 examples/scenario_outline_scenario_name_substitution.feature diff --git a/examples/scenario_outline_scenario_name_substitution.feature b/examples/scenario_outline_scenario_name_substitution.feature new file mode 100644 index 0000000..f6f8cfc --- /dev/null +++ b/examples/scenario_outline_scenario_name_substitution.feature @@ -0,0 +1,13 @@ +Feature: using scenario outlines + Scenario Outline: a monster introduced himself as + Given there is a monster called + Then the monster introduced himself: + """ + Ahhhhhhh! i'm ! + """ + + Examples: + | name | + | John | + | "John Smith" | + | "O'Flannahan" | diff --git a/lib/turnip/node/scenario_outline.rb b/lib/turnip/node/scenario_outline.rb index 67fe7f1..684a9f8 100644 --- a/lib/turnip/node/scenario_outline.rb +++ b/lib/turnip/node/scenario_outline.rb @@ -57,7 +57,7 @@ def to_scenarios header = example.header example.rows.map do |row| - metadata = convert_metadata_to_scenario + metadata = convert_metadata_to_scenario(header, row) # # Replace using Example values @@ -115,10 +115,11 @@ def to_scenarios # @todo :keyword is not considered a language (en only) # @return [Hash] # - def convert_metadata_to_scenario() + def convert_metadata_to_scenario(header, row) # deep copy Marshal.load(Marshal.dump(raw)).tap do |new_raw| new_raw.delete(:examples) + new_raw[:name] = substitute(new_raw[:name], header, row) new_raw[:type] = :Scenario new_raw[:keyword] = 'Scenario' end diff --git a/spec/builder_spec.rb b/spec/builder_spec.rb index d3790e4..2d4849a 100644 --- a/spec/builder_spec.rb +++ b/spec/builder_spec.rb @@ -75,6 +75,18 @@ end end + context "with example scenario name in scenario outlines" do + let(:feature_file) { File.expand_path('../examples/scenario_outline_scenario_name_substitution.feature', File.dirname(__FILE__)) } + + it "replaces placeholders in scenario name" do + feature.scenarios.map(&:name).should eq([ + "a monster introduced himself as John", + 'a monster introduced himself as "John Smith"', + %(a monster introduced himself as "O'Flannahan") + ]) + end + end + context "with example tables in scenario outlines" do let(:feature_file) { File.expand_path('../examples/scenario_outline_table_substitution.feature', File.dirname(__FILE__)) } diff --git a/spec/integration_spec.rb b/spec/integration_spec.rb index 38bff81..e05aa3b 100644 --- a/spec/integration_spec.rb +++ b/spec/integration_spec.rb @@ -12,7 +12,7 @@ end it "prints out failures and successes" do - @result.should include('42 examples, 4 failures, 5 pending') + @result.should include('45 examples, 4 failures, 5 pending') end it "includes features in backtraces" do