Skip to content

Commit

Permalink
emit readable, more concise /"(.*?)"/ rather than /"([^"]*)"/
Browse files Browse the repository at this point in the history
I suggested this change while reviewing a cucumber-using project:
  - Given /^"([^"]*)" instance's provider is not accessible$/ do |arg1|
  + Given /^"(.*?)" instance's provider is not accessible$/ do |arg1|
since the use of non-greedy .*? is equivalent and more readable.
Then I learned that these were based on suggestions from cucumber,
so now I'm suggesting the improvement here.
  • Loading branch information
Jim Meyering committed Feb 27, 2012
1 parent 2ccea1e commit af4625c
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion lib/cucumber/js_support/js_snippets.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module Cucumber
module JsSupport
module JsSnippets
PARAM_PATTERN = /"([^"]*)"/
PARAM_PATTERN = /"(.*?)"/
ESCAPED_PARAM_PATTERN = '"([^\\"]*)"'

def snippet_text(code_keyword, step_name, multiline_arg_class)
Expand Down
2 changes: 1 addition & 1 deletion lib/cucumber/rb_support/rb_language.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def step_matches(name_to_match, name_to_format)
end.compact
end

ARGUMENT_PATTERNS = ['"([^"]*)"', '(\d+)']
ARGUMENT_PATTERNS = ['"(.*?)"', '(\d+)']

def snippet_text(code_keyword, step_name, multiline_arg_class)
snippet_pattern = Regexp.escape(step_name).gsub('\ ', ' ').gsub('/', '\/')
Expand Down
10 changes: 5 additions & 5 deletions spec/cucumber/rb_support/rb_language_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def unindented(s)

it "should recognise a mix of ints, strings and why not a table too" do
rb.snippet_text('Given', 'I have 9 "awesome" cukes in 37 "boxes"', Cucumber::Ast::Table).should == unindented(%{
Given /^I have (\\d+) "([^"]*)" cukes in (\\d+) "([^"]*)"$/ do |arg1, arg2, arg3, arg4, table|
Given /^I have (\\d+) "(.*?)" cukes in (\\d+) "(.*?)"$/ do |arg1, arg2, arg3, arg4, table|
# table is a Cucumber::Ast::Table
pending # express the regexp above with the code you wish you had
end
Expand All @@ -40,15 +40,15 @@ def unindented(s)

it "should recognise quotes in name and make according regexp" do
rb.snippet_text('Given', 'A "first" arg', nil).should == unindented(%{
Given /^A "([^"]*)" arg$/ do |arg1|
Given /^A "(.*?)" arg$/ do |arg1|
pending # express the regexp above with the code you wish you had
end
})
end

it "should recognise several quoted words in name and make according regexp and args" do
rb.snippet_text('Given', 'A "first" and "second" arg', nil).should == unindented(%{
Given /^A "([^"]*)" and "([^"]*)" arg$/ do |arg1, arg2|
Given /^A "(.*?)" and "(.*?)" arg$/ do |arg1, arg2|
pending # express the regexp above with the code you wish you had
end
})
Expand All @@ -64,7 +64,7 @@ def unindented(s)

it "should be helpful with tables" do
rb.snippet_text('Given', 'A "first" arg', Cucumber::Ast::Table).should == unindented(%{
Given /^A "([^"]*)" arg$/ do |arg1, table|
Given /^A "(.*?)" arg$/ do |arg1, table|
# table is a Cucumber::Ast::Table
pending # express the regexp above with the code you wish you had
end
Expand Down Expand Up @@ -279,4 +279,4 @@ class << rb.current_world

end
end
end
end

0 comments on commit af4625c

Please sign in to comment.