Permalink
Browse files

Make sure alternative/optional words aren't captured

  • Loading branch information...
1 parent 6a2b870 commit 73e6af33507568ca0c4ac90f0863941c39f3bbc1 @jnicklas committed Apr 26, 2012
Showing with 43 additions and 6 deletions.
  1. +20 −0 examples/steps/steps.rb
  2. +17 −0 examples/steps_with_variations.feature
  3. +5 −5 lib/turnip/step_definition.rb
  4. +1 −1 spec/integration_spec.rb
View
@@ -79,6 +79,26 @@
@song.to_s.split("\n").length.should eq(count)
end
+step "it should be strong/tough" do
+ @monster.should >= 2
+end
+
+step "it should be (a) badass" do
+ @monster.should >= 2
+end
+
+step "it should be (a) badass" do
+ @monster.should >= 2
+end
+
+step "it should be terrible(st)" do
+ @monster.should >= 2
+end
+
+step "it (should) have/has :count (terrifying) hitpoint(s)" do |count|
+ @monster.should == count
+end
+
step "raise error" do
raise "foobar"
end
@@ -0,0 +1,17 @@
+Feature: steps with variations, such as alternative words or optional words
+ Scenario: alternative words
+ Given there is a strong monster
+ Then it should be strong
+ And it should be tough
+ Scenario: optional words
+ Given there is a strong monster
+ Then it should be badass
+ And it should be a badass
+ Scenario: optional parts of words
+ Given there is a strong monster
+ Then it should be terrible
+ And it should be terriblest
+ Scenario: putting it all together
+ Given there is a strong monster
+ Then it should have 2 terrifying hitpoints
+ And it has 2 hitpoint
@@ -35,17 +35,17 @@ def match(description)
def compile_regexp
regexp = Regexp.escape(expression)
+ regexp.gsub!(PLACEHOLDER_REGEXP) do |_|
+ "(?<#{$1}>#{Placeholder.resolve($1.to_sym)})"
+ end
regexp.gsub!(COMMAND_REGEXP) do |_|
"(?:[`]([^`]+)[`])"
end
regexp.gsub!(OPTIONAL_WORD_REGEXP) do |_|
- [$1, $2, $3].compact.map { |m| "(#{m})?" }.join
+ [$1, $2, $3].compact.map { |m| "(?:#{m})?" }.join
end
regexp.gsub!(ALTERNATIVE_WORD_REGEXP) do |_|
- "(#{$1}#{$2.tr('/', '|')})"
- end
- regexp.gsub!(PLACEHOLDER_REGEXP) do |_|
- "(?<#{$1}>#{Placeholder.resolve($1.to_sym)})"
+ "(?:#{$1}#{$2.tr('/', '|')})"
end
Regexp.new("^#{regexp}$")
end
View
@@ -11,7 +11,7 @@
end
it "prints out failures and successes" do
- @result.should include('29 examples, 3 failures, 3 pending')
+ @result.should include('33 examples, 3 failures, 3 pending')
end
it "includes features in backtraces" do

0 comments on commit 73e6af3

Please sign in to comment.