Skip to content

Commit

Permalink
Support scenario name substitution
Browse files Browse the repository at this point in the history
Co-authored-by: Wataru MIYAGUNI <[email protected]>
  • Loading branch information
hanachin and gongo committed May 14, 2021
1 parent 81b6c0b commit 27eb64f
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 3 deletions.
13 changes: 13 additions & 0 deletions examples/scenario_outline_scenario_name_substitution.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Feature: using scenario outlines
Scenario Outline: a monster introduced himself as <name>
Given there is a monster called <name>
Then the monster introduced himself:
"""
Ahhhhhhh! i'm <name>!
"""

Examples:
| name |
| John |
| "John Smith" |
| "O'Flannahan" |
5 changes: 3 additions & 2 deletions lib/turnip/node/scenario_outline.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 <placeholder> using Example values
Expand Down Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions spec/builder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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__)) }

Expand Down
2 changes: 1 addition & 1 deletion spec/integration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 27eb64f

Please sign in to comment.