class Cucumber::RbSupport::Snippet::BaseSnippet

Attributes

code_keyword[R]
multiline_argument[R]
number_of_arguments[R]
pattern[R]

Public Class Methods

cli_option_string(type) click to toggle source
# File lib/cucumber/rb_support/snippet.rb, line 39
def self.cli_option_string(type)
  "%-7s: %-28s e.g. %s" % [type, description, example]
end
new(code_keyword, pattern, multiline_argument) click to toggle source
# File lib/cucumber/rb_support/snippet.rb, line 24
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

Private Class Methods

example() click to toggle source
# File lib/cucumber/rb_support/snippet.rb, line 73
def self.example
  new("Given", "missing step", MultilineArgument::None.new).step
end

Public Instance Methods

step() click to toggle source
# File lib/cucumber/rb_support/snippet.rb, line 35
def step
  "#{code_keyword}#{typed_pattern}"
end
to_s() click to toggle source
# File lib/cucumber/rb_support/snippet.rb, line 31
def to_s
  "#{step} #{do_block}"
end

Private Instance Methods

arguments() click to toggle source
# File lib/cucumber/rb_support/snippet.rb, line 67
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
do_block() click to toggle source
# File lib/cucumber/rb_support/snippet.rb, line 58
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
replace_and_count_capturing_groups(pattern) click to toggle source
# File lib/cucumber/rb_support/snippet.rb, line 47
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