# File lib/cucumber/rb_support/snippet.rb, line 24 def self.cli_option_string(type) "%-7s: %-28s e.g. %s" % [type, description, example] end
# File lib/cucumber/rb_support/snippet.rb, line 9 def initialize(code_keyword, pattern, multiline_argument_class) @number_of_arguments = 0 @code_keyword = code_keyword @pattern = replace_and_count_capturing_groups(pattern) @multiline_argument_class = multiline_argument_class end
# File lib/cucumber/rb_support/snippet.rb, line 70 def self.example new("Given", "missing step", nil).step end
# File lib/cucumber/rb_support/snippet.rb, line 20 def step "#{code_keyword}#{typed_pattern}" end
# File lib/cucumber/rb_support/snippet.rb, line 16 def to_s "#{step} #{do_block}" end
# File lib/cucumber/rb_support/snippet.rb, line 52 def arguments block_args = (0...number_of_arguments).map { |n| "arg#{n+1}" } if multiline_argument_class block_args << multiline_argument_class.default_arg_name end block_args.empty? ? "" : " |#{block_args.join(", ")}|" end
# File lib/cucumber/rb_support/snippet.rb, line 43 def do_block do_block = "" do_block << "do#{arguments}\n" do_block << multiline_comment if multiline_argument_class? do_block << " pending # express the regexp above with the code you wish you had\n" do_block << "end" do_block end
# File lib/cucumber/rb_support/snippet.rb, line 66 def multiline_argument_class? multiline_argument_class == Ast::Table end
# File lib/cucumber/rb_support/snippet.rb, line 62 def multiline_comment " # #{multiline_argument_class.default_arg_name} is a #{multiline_argument_class.to_s}\n" end
# File lib/cucumber/rb_support/snippet.rb, line 32 def replace_and_count_capturing_groups(pattern) modified_pattern = ::Regexp.escape(pattern).gsub('\ ', ' ').gsub('/', '\/') ARGUMENT_PATTERNS.each do |argument_pattern| modified_pattern.gsub!(::Regexp.new(argument_pattern), argument_pattern) @number_of_arguments += modified_pattern.scan(argument_pattern).length end modified_pattern end