Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support scenario name substitution #237

Merged
merged 1 commit into from
May 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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