Skip to content
Browse files

Fixed a bug in snippet printer. Multiple quoted args weren't handled …

…correctly
  • Loading branch information...
1 parent 3137d36 commit 6986673c6abb68ef45a507afdf090b7f0eee61ea @aslakhellesoy aslakhellesoy committed Mar 30, 2009
Showing with 17 additions and 12 deletions.
  1. +9 −12 lib/cucumber/step_definition.rb
  2. +8 −0 spec/cucumber/step_definition_spec.rb
View
21 lib/cucumber/step_definition.rb
@@ -56,23 +56,20 @@ def text_length
# end
#
class StepDefinition
+ PARAM_PATTERN = /"([^\"]*)"/
+ ESCAPED_PARAM_PATTERN = '"([^\\"]*)"'
+
def self.snippet_text(step_keyword, step_name)
escaped = Regexp.escape(step_name).gsub('\ ', ' ').gsub('/', '\/')
- param_pattern = /"([^\"]*)"/
+ escaped = escaped.gsub(PARAM_PATTERN, ESCAPED_PARAM_PATTERN)
- match = escaped.match(param_pattern)
- if match
- n = 0
- block_args = match.captures.map do |a|
- n += 1
- "arg#{n}"
- end
- block_arg_string = " |#{block_args.join(", ")}|"
- else
- block_arg_string = ""
+ n = 0
+ block_args = escaped.scan(ESCAPED_PARAM_PATTERN).map do |a|
+ n += 1
+ "arg#{n}"
end
+ block_arg_string = block_args.empty? ? "" : " |#{block_args.join(", ")}|"
- escaped = escaped.gsub(param_pattern, '"([^\\"]*)"')
"#{step_keyword} /^#{escaped}$/ do#{block_arg_string}\n pending\nend"
end
View
8 spec/cucumber/step_definition_spec.rb
@@ -82,6 +82,14 @@ def unindented(s)
})
end
+ it "should recognise several quoted words in name and make according regexp and args" do
+ StepDefinition.snippet_text('Given', 'A "first" and "second" arg').should == unindented(%{
+ Given /^A "([^\\"]*)" and "([^\\"]*)" arg$/ do |arg1, arg2|
+ pending
+ end
+ })
+ end
+
it "should not use quote group when there are no quotes" do
StepDefinition.snippet_text('Given', 'A first arg').should == unindented(%{
Given /^A first arg$/ do

0 comments on commit 6986673

Please sign in to comment.
Something went wrong with that request. Please try again.