class Cucumber::RbSupport::Snippet::BaseSnippet
def self.cli_option_string(type)
def self.cli_option_string(type) "%-7s: %-28s e.g. %s" % [type, description, example] end
def self.example
def self.example new("Given", "missing step", MultilineArgument::None.new).step end
def arguments
def arguments block_args = (0...number_of_arguments).map { |n| "arg#{n+1}" } multiline_argument.append_block_argument_to(block_args) block_args.empty? ? "" : " |#{block_args.join(", ")}|" end
def do_block
def do_block do_block = "" do_block << "do#{arguments}\n" multiline_argument.append_comment_to(do_block) do_block << " pending # Write code here that turns the phrase above into concrete actions\n" do_block << "end" do_block end
def initialize(code_keyword, pattern, multiline_argument)
def initialize(code_keyword, pattern, multiline_argument) @number_of_arguments = 0 @code_keyword = code_keyword @pattern = replace_and_count_capturing_groups(pattern) @multiline_argument = MultilineArgumentSnippet.new(multiline_argument) end
def replace_and_count_capturing_groups(pattern)
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
def step
def step "#{code_keyword}#{typed_pattern}" end
def to_s
def to_s "#{step} #{do_block}" end