Skip to content

Loading…

Tables support example variables #68

Merged
merged 16 commits into from

4 participants

@lukaso

This patch makes the following feature correctly substitute <hp> with 10 and 8, just as it would if they were placeholders in the step definition.

Feature: using scenario outlines
  Scenario Outline: a simple outline
    Given there is a monster with hitpoints:
      | hit_points |
      | <hp>       |
   When I attack the monster and do <damage> points damage
    Then the monster should be <state>

    Examples:
      | hp   | damage | state   |
      | 10   | 13     | dead    |
      | 8    | 5      | alive   |
@travisbot

This pull request fails (merged 0bca446 into 110af0f).

@lukaso

@jnicklas This has now been running flawlessly for us for the past week with over 1300 examples (not all of which are using this feature, but part of a test suite). The functionality has tests, and the Travis errors are all existing ones that this pull request didn't introduce. Be great if you could give your feedback or even better if you merge it. :)

@PragTob

tests are failing? WTF :-/ Should get fixed.

@lukaso

@PragTob @jnicklas I've tried to look into the root failure in the travis tests, but I can't get the failure to happen on my travis setup even though the repos are identical (your master and my travis-test): http://travis-ci.org/#!/simplybusiness/turnip.

So something very weird is going on.

Also, ruby-head is failing on installing Gherkin.

@PragTob

Haha I just noticed the very same thing on my travis setup... maybe it was a bug on their side that is fixed by now?

I don't know but maybe testing with ruby-head should not be done, but that's the call of @jnicklas :-)

@jnicklas
Owner

Yes, we should put ruby-head as an allowed failure at least. Travis has been giving me problems in pretty much all my projects lately, which is why I haven't paid too much attention to this lately.

@lukaso
@jnicklas
Owner

Your pull request looks good by the way, but it's quite big, so I need to find the time to review it carefully before I merge it.

@jnicklas
Owner

Just a little tip (and really not a criticism), in the future, you might want to squash related commits before you send a pull request. It makes it easier to review.

@lukaso
@lukaso
@jnicklas jnicklas merged commit e3be114 into jnicklas:master

1 check failed

Details default The Travis build failed
@lukaso

@jnicklas Thanks for the merge!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Aug 18, 2012
  1. @lukaso
  2. @lukaso
  3. @lukaso

    Fix integration test

    lukaso committed
  4. @lukaso
Commits on Aug 19, 2012
  1. @lukaso
  2. @lukaso
  3. @lukaso
  4. @lukaso

    Bit more refactoring to dry up.

    lukaso committed
  5. @lukaso

    Refactor

    lukaso committed
  6. @lukaso

    Refactor

    lukaso committed
  7. @lukaso

    Shrink down a bit.

    lukaso committed
  8. @lukaso
  9. @lukaso

    Remove unneeded method.

    lukaso committed
Commits on Aug 20, 2012
  1. @lukaso

    Improve wording

    lukaso committed
  2. @lukaso

    Push version for our gem server

    lukaso committed
    Do not merge into topic branch
  3. @lukaso

    Undo version change

    lukaso committed
    Should not change version for pull request.
View
12 examples/scenario_outline_table_substitution.feature
@@ -0,0 +1,12 @@
+Feature: using scenario outlines
+ Scenario Outline: a simple outline
+ Given there is a monster with hitpoints:
+ | hit_points |
+ | <hp> |
+ When I attack the monster and do <damage> points damage
+ Then the monster should be <state>
+
+ Examples:
+ | hp | damage | state |
+ | 10 | 13 | dead |
+ | 8 | 5 | alive |
View
14 lib/turnip/builder.rb
@@ -81,12 +81,22 @@ def to_scenarios(examples)
rows.map do |row|
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_description = substitute(step.description, headers, row)
+ new_extra_args = step.extra_args.map do |ea|
+ next ea unless ea.instance_of?(Turnip::Table)
+ Turnip::Table.new(ea.map {|t_row| t_row.map {|t_col| substitute(t_col, headers, row) } })
+ end
+ Step.new(new_description, new_extra_args, step.line)
end
end
end
end
+
+ private
+
+ def substitute(text, headers, row)
+ text.gsub(/<([^>]*)>/) { |_| Hash[headers.zip(row)][$1] }
+ end
end
class Step < Struct.new(:description, :extra_args, :line)
View
19 spec/builder_spec.rb
@@ -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.hashes[0]['hit_points'].should == '10'
+ table = feature.scenarios[1].steps[0].extra_args.find {|a| a.instance_of?(Turnip::Table)}
+ table.hashes[0]['hit_points'].should == '8'
+ end
+
+ end
end
View
2 spec/integration_spec.rb
@@ -11,7 +11,7 @@
end
it "prints out failures and successes" do
- @result.should include('33 examples, 3 failures, 3 pending')
+ @result.should include('35 examples, 3 failures, 5 pending')
end
it "includes features in backtraces" do
View
6 spec/table_spec.rb
@@ -8,6 +8,11 @@
it 'returns the raw table' do
table.raw.should == [['foo', 'bar'], ['quox', '42']]
end
+
+ it 'reflects changes in the raw table' do
+ table.raw[1][1] = '55'
+ table.raw.should == [['foo', 'bar'], ['quox', '55']]
+ end
end
describe '#to_a' do
@@ -71,4 +76,5 @@
table.map(&:first).should == ['moo', 'quox']
end
end
+
end
Something went wrong with that request. Please try again.