Skip to content

Commit

Permalink
Merge pull request #331 from martco/(snippet-pattern)
Browse files Browse the repository at this point in the history
  • Loading branch information
os97673 committed Feb 18, 2013
2 parents a3c125e + 02f7d9e commit 71bfca8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
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 @@ -93,7 +93,7 @@ def snippet_text(code_keyword, step_name, multiline_arg_class)
multiline_class_comment = "# #{multiline_arg_class.default_arg_name} is a #{multiline_arg_class.to_s}\n "
end

"#{code_keyword} /^#{snippet_pattern}$/ do#{block_arg_string}\n #{multiline_class_comment}pending # express the regexp above with the code you wish you had\nend"
"#{code_keyword}(/^#{snippet_pattern}$/) do#{block_arg_string}\n #{multiline_class_comment}pending # express the regexp above with the code you wish you had\nend"
end

def begin_rb_scenario(scenario)
Expand Down
22 changes: 15 additions & 7 deletions spec/cucumber/rb_support/rb_language_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,26 @@ def unindented(s)
end

describe "snippets" do


it "should wrap snippet patterns in parentheses" do
rb.snippet_text('Given', 'A "string" with 4 spaces', nil).should == unindented(%{
Given(/^A "(.*?)" with (\\d+) spaces$/) do |arg1, arg2|
pending # express the regexp above with the code you wish you had
end
})
end

it "should recognise numbers in name and make according regexp" do
rb.snippet_text('Given', 'Cloud 9 yeah', nil).should == unindented(%{
Given /^Cloud (\\d+) yeah$/ do |arg1|
Given(/^Cloud (\\d+) yeah$/) do |arg1|
pending # express the regexp above with the code you wish you had
end
})
end

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,31 +48,31 @@ 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
})
end

it "should not use quote group when there are no quotes" do
rb.snippet_text('Given', 'A first arg', nil).should == unindented(%{
Given /^A first arg$/ do
Given(/^A first arg$/) do
pending # express the regexp above with the code you wish you had
end
})
end

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

0 comments on commit 71bfca8

Please sign in to comment.