Sha256: 19e7e471b9e4e191991f673a053aba2d6b53a7008d9ca7c52fe3e870cf1a24f1

Contents?: true

Size: 1.03 KB

Versions: 41

Compression:

Stored size: 1.03 KB

Contents

module Cucumber
  module JsSupport
    module JsSnippets
      PARAM_PATTERN = /"([^"]*)"/
      ESCAPED_PARAM_PATTERN = '"([^\\"]*)"'

      def snippet_text(code_keyword, step_name, multiline_arg_class)
        escaped = Regexp.escape(step_name).gsub('\ ', ' ').gsub('/', '\/')
        escaped = escaped.gsub(PARAM_PATTERN, ESCAPED_PARAM_PATTERN)

        n = 0
        block_args = escaped.scan(ESCAPED_PARAM_PATTERN).map do |a|
          n += 1
          "arg#{n}"
        end
        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}(/^#{escaped}$/, function(#{block_arg_string}){\n  #{multiline_class_comment}  //express the regexp above with the code you wish you had\n});"
      end
    end
  end
end

Version data entries

41 entries across 41 versions & 8 rubygems

Version Path
cucumber-1.0.6 lib/cucumber/js_support/js_snippets.rb
cucumber-1.0.5 lib/cucumber/js_support/js_snippets.rb
cucumber-1.0.4 lib/cucumber/js_support/js_snippets.rb
cucumber-1.0.3 lib/cucumber/js_support/js_snippets.rb
cucumber-1.0.2 lib/cucumber/js_support/js_snippets.rb
cucumber-1.0.1 lib/cucumber/js_support/js_snippets.rb
cucumber-1.0.0 lib/cucumber/js_support/js_snippets.rb
cucumber-0.8.6 lib/cucumber/js_support/js_snippets.rb
cucumber-0.10.7 lib/cucumber/js_support/js_snippets.rb
cucumber-0.10.6 lib/cucumber/js_support/js_snippets.rb
cucumber-0.10.5 lib/cucumber/js_support/js_snippets.rb
cucumber-0.10.3 lib/cucumber/js_support/js_snippets.rb
cucumber-0.10.2 lib/cucumber/js_support/js_snippets.rb
cucumber-0.10.1 lib/cucumber/js_support/js_snippets.rb
stefl-cucumber-0.10.1 lib/cucumber/js_support/js_snippets.rb
vim-jar-0.1.2.0001 bundler/ruby/1.8/gems/cucumber-0.9.4/lib/cucumber/js_support/js_snippets.rb
vim-jar-0.1.2 bundler/ruby/1.8/gems/cucumber-0.9.4/lib/cucumber/js_support/js_snippets.rb
vim-jar-0.1.1 bundler/ruby/1.8/gems/cucumber-0.9.4/lib/cucumber/js_support/js_snippets.rb
vim-jar-0.1.0 bundler/ruby/1.8/gems/cucumber-0.9.4/lib/cucumber/js_support/js_snippets.rb
cucumber-0.10.0 lib/cucumber/js_support/js_snippets.rb