Browse files

Snippets for steps that use Step Tables or Pystrings include block pa…

…ram and object type hint comment
  • Loading branch information...
1 parent e58e1ed commit b436d7800dffedceaec61bb4e50ec0aeb069873a @josephwilk josephwilk committed Apr 1, 2009
View
1 History.txt
@@ -2,6 +2,7 @@
=== New features
* Allow Step Definitions to use |*varargs|, but only on Ruby 1.9. (Aslak Helles??y)
+* Snippets for steps that use Step Tables or Pystrings include block param and object type hint comment (#247 Joseph Wilk)
== 0.2.3 2009-03-30
View
12 examples/self_test/features/undefined_multiline_args.feature
@@ -0,0 +1,12 @@
+Feature: undefined multiline args
+
+ Scenario: pystring
+ Given a pystring
+ """
+ example
+ """
+
+ Scenario: table
+ Given a table
+ | table |
+ |example|
View
6 features/cucumber_cli.feature
@@ -237,15 +237,15 @@ Feature: Cucumber command line
Scenario: Multiple formatters and outputs
When I run cucumber --format progress --out tmp/progress.txt --format pretty --out tmp/pretty.txt --dry-run features/lots_of_undefined.feature
- And examples/self_test/tmp/progress.txt should contain
+ And "examples/self_test/tmp/progress.txt" should contain
"""
UUUUU
1 scenario
5 undefined steps
"""
- And examples/self_test/tmp/pretty.txt should match
+ And "examples/self_test/tmp/pretty.txt" should match
"""
Feature: Lots of undefined
@@ -362,7 +362,7 @@ Feature: Cucumber command line
Scenario: Reformat files with --autoformat
When I run cucumber --autoformat tmp/formatted features
- Then examples/self_test/tmp/formatted/features/sample.feature should contain
+ Then "examples/self_test/tmp/formatted/features/sample.feature" should contain
"""
@one
Feature: Sample
View
23 features/snippet.feature
@@ -0,0 +1,23 @@
+Feature: Snippets
+ In order to help speed up writing step definitions
+ As a feature editor
+ I want snippet suggestions for undefined step definitions
+
+ Scenario: Snippet for undefined step with a pystring
+ When I run cucumber features/undefined_multiline_args.feature:3 -n
+ Then the output should contain
+ """
+ Given /^a pystring$/ do |string|
+ # string is a Cucumber::Ast::PyString
+ pending
+ end
+ """
+ Scenario: Snippet for undefined step with a step table
+ When I run cucumber features/undefined_multiline_args.feature:9 -n
+ Then the output should contain
+ """
+ Given /^a table$/ do |table|
+ # table is a Cucumber::Ast::Table
+ pending
+ end
+ """
View
8 features/step_definitions/cucumber_steps.rb
@@ -21,10 +21,14 @@
end
end
-Then /^(.*) should contain$/ do |file, text|
+Then /^the output should contain$/ do |text|
+ @out.should include(text)
+end
+
+Then /^"(.*)" should contain$/ do |file, text|
IO.read(file).should == text
end
-Then /^(.*) should match$/ do |file, text|
+Then /^"(.*)" should match$/ do |file, text|
IO.read(file).should =~ Regexp.new(text)
end
View
6 lib/cucumber/ast/py_string.rb
@@ -17,6 +17,11 @@ module Ast
# Note how the indentation from the source is stripped away.
#
class PyString
+
+ def self.default_arg_name
+ "string"
+ end
+
def initialize(start_line, end_line, string, quotes_indent)
@start_line, @end_line = start_line, end_line
@string, @quotes_indent = string.gsub(/\\"/, '"'), quotes_indent
@@ -52,7 +57,6 @@ def arguments_replaced(arguments) #:nodoc:
def to_sexp #:nodoc:
[:py_string, to_s]
end
-
end
end
end
View
4 lib/cucumber/ast/step_invocation.rb
@@ -98,6 +98,10 @@ def keyword
@step.keyword
end
+ def multiline_arg
+ @step.multiline_arg
+ end
+
def file_colon_line
@step.file_colon_line
end
View
4 lib/cucumber/ast/table.rb
@@ -12,6 +12,10 @@ class Table
attr_accessor :file
+ def self.default_arg_name
+ "table"
+ end
+
def initialize(raw, conversions = NULL_CONVERSIONS.dup)
# Verify that it's square
raw.transpose
View
3 lib/cucumber/formatter/console.rb
@@ -74,7 +74,8 @@ def print_snippets(options)
return if undefined.empty?
snippets = undefined.map do |step|
step_name = Undefined === step.exception ? step.exception.step_name : step.name
- snippet = @step_mother.snippet_text(step.actual_keyword, step_name)
+ step_multiline_class = step.multiline_arg ? step.multiline_arg.class : nil
+ snippet = @step_mother.snippet_text(step.actual_keyword, step_name, step_multiline_class)
snippet
end.compact.uniq
View
6 lib/cucumber/step_definition.rb
@@ -59,7 +59,7 @@ class StepDefinition
PARAM_PATTERN = /"([^\"]*)"/
ESCAPED_PARAM_PATTERN = '"([^\\"]*)"'
- def self.snippet_text(step_keyword, step_name)
+ def self.snippet_text(step_keyword, step_name, multiline_arg_class = nil)
escaped = Regexp.escape(step_name).gsub('\ ', ' ').gsub('/', '\/')
escaped = escaped.gsub(PARAM_PATTERN, ESCAPED_PARAM_PATTERN)
@@ -68,9 +68,11 @@ def self.snippet_text(step_keyword, step_name)
n += 1
"arg#{n}"
end
+ block_args << multiline_arg_class.default_arg_name unless multiline_arg_class.nil?
block_arg_string = block_args.empty? ? "" : " |#{block_args.join(", ")}|"
+ multiline_class_string = multiline_arg_class ? "# #{multiline_arg_class.default_arg_name} is a #{multiline_arg_class.to_s}\n " : ""
- "#{step_keyword} /^#{escaped}$/ do#{block_arg_string}\n pending\nend"
+ "#{step_keyword} /^#{escaped}$/ do#{block_arg_string}\n #{multiline_class_string}pending\nend"
end
class MissingProc < StandardError
View
4 lib/cucumber/step_mother.rb
@@ -139,8 +139,8 @@ def step_definitions
@step_definitions ||= []
end
- def snippet_text(step_keyword, step_name)
- @snippet_generator.snippet_text(step_keyword, step_name)
+ def snippet_text(step_keyword, step_name, multiline_arg_class)
+ @snippet_generator.snippet_text(step_keyword, step_name, multiline_arg_class)
end
def before_and_after(scenario, skip=false)

0 comments on commit b436d78

Please sign in to comment.