lib/cucumber/rb_support/rb_language.rb in cucumber-1.2.5 vs lib/cucumber/rb_support/rb_language.rb in cucumber-1.3.0

- old
+ new

@@ -2,10 +2,11 @@ require 'cucumber/rb_support/rb_dsl' require 'cucumber/rb_support/rb_world' require 'cucumber/rb_support/rb_step_definition' require 'cucumber/rb_support/rb_hook' require 'cucumber/rb_support/rb_transform' +require 'cucumber/rb_support/snippet' begin require 'rspec/expectations' rescue LoadError begin @@ -81,29 +82,13 @@ nil end end.compact end - ARGUMENT_PATTERNS = ['"(.*?)"', '(\d+)'] - - def snippet_text(code_keyword, step_name, multiline_arg_class) - snippet_pattern = Regexp.escape(step_name).gsub('\ ', ' ').gsub('/', '\/') - arg_count = 0 - ARGUMENT_PATTERNS.each do |pattern| - snippet_pattern = snippet_pattern.gsub(Regexp.new(pattern), pattern) - arg_count += snippet_pattern.scan(pattern).length - end - - block_args = (0...arg_count).map {|n| "arg#{n+1}"} - block_args << multiline_arg_class.default_arg_name unless multiline_arg_class.nil? - block_arg_string = block_args.empty? ? "" : " |#{block_args.join(", ")}|" - multiline_class_comment = "" - if(multiline_arg_class == Ast::Table) - multiline_class_comment = "# #{multiline_arg_class.default_arg_name} is a #{multiline_arg_class.to_s}\n " - end - - "#{code_keyword}(/^#{snippet_pattern}$/) do#{block_arg_string}\n #{multiline_class_comment}pending # express the regexp above with the code you wish you had\nend" + def snippet_text(code_keyword, step_name, multiline_arg_class, snippet_type = :regexp) + snippet_class = typed_snippet_class(snippet_type) + snippet_class.new(code_keyword, step_name, multiline_arg_class).to_s end def begin_rb_scenario(scenario) create_world extend_world @@ -180,9 +165,25 @@ e.backtrace.push(proc.backtrace_line("World")) raise e end else o + end + end + + SNIPPET_TYPES = { + :regexp => Snippet::Regexp, + :classic => Snippet::Classic, + :percent => Snippet::Percent + } + + def typed_snippet_class(type) + SNIPPET_TYPES.fetch(type || :regexp) + end + + def self.cli_snippet_type_options + SNIPPET_TYPES.keys.sort_by(&:to_s).map do |type| + SNIPPET_TYPES[type].cli_option_string(type) end end end end end