Permalink
Browse files

Allows tables to get substitutions from scenario outlines

  • Loading branch information...
lukaso committed Aug 18, 2012
1 parent 6af87d0 commit 129464485bdc3855328a1303096728a1f442af2c
Showing with 30 additions and 1 deletion.
  1. +11 −1 lib/turnip/builder.rb
  2. +19 −0 spec/builder_spec.rb
View
@@ -82,7 +82,17 @@ def to_scenarios(examples)
Scenario.new(@raw).tap do |scenario|
scenario.steps = steps.map do |step|
new_description = step.description.gsub(/<([^>]*)>/) { |_| Hash[headers.zip(row)][$1] }
- Step.new(new_description, step.extra_args, step.line)
+ new_extra_args = Marshal.load( Marshal.dump(step.extra_args) )
+ if index = new_extra_args.find_index { |a| a.instance_of?(Turnip::Table) }
+ table = new_extra_args[index]
+ table.raw.each_index do |i|
+ table.raw[i].each_index do |j|
+ table.raw[i][j].gsub!(/<([^>]*)>/) { |_| Hash[headers.zip(row)][$1] }
+ end
+ end
+ new_extra_args[index] = table
+ end
+ Step.new(new_description, new_extra_args, step.line)
end
end
end
View
@@ -27,4 +27,23 @@
])
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__)) }
+ let(:builder) { Turnip::Builder.build(feature_file) }
+ let(:feature) { builder.features.first }
+
+ it "replaces placeholders in tables in steps" do
+ feature.scenarios[0].steps.map(&:description).should eq([
+ "there is a monster with hitpoints:",
+ "I attack the monster and do 13 points damage",
+ "the monster should be dead"
+ ])
+ table = feature.scenarios[0].steps[0].extra_args.find {|a| a.instance_of?(Turnip::Table)}
+ table.raw[0][1].should == '10'
+ table = feature.scenarios[1].steps[0].extra_args.find {|a| a.instance_of?(Turnip::Table)}
+ table.raw[0][1].should == '8'
+ end
+
+ end
end

0 comments on commit 1294644

Please sign in to comment.