class Cucumber::RbSupport::Snippet::BaseSnippet
Attributes
code_keyword[R]
multiline_argument_class[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 24 def self.cli_option_string(type) "%-7s: %-28s e.g. %s" % [type, description, example] end
new(code_keyword, pattern, multiline_argument_class)
click to toggle source
# 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
Private Class Methods
example()
click to toggle source
# File lib/cucumber/rb_support/snippet.rb, line 70 def self.example new("Given", "missing step", nil).step end
Public Instance Methods
step()
click to toggle source
# File lib/cucumber/rb_support/snippet.rb, line 20 def step "#{code_keyword}#{typed_pattern}" end
to_s()
click to toggle source
# File lib/cucumber/rb_support/snippet.rb, line 16 def to_s "#{step} #{do_block}" end
Private Instance Methods
arguments()
click to toggle source
# 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
do_block()
click to toggle source
# 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
multiline_argument_class?()
click to toggle source
# File lib/cucumber/rb_support/snippet.rb, line 66 def multiline_argument_class? multiline_argument_class == Ast::Table end
multiline_comment()
click to toggle source
# 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
replace_and_count_capturing_groups(pattern)
click to toggle source
# 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