Sha256: 8fb7218322b415c0e7d436acf91c9a9db3111a64c4ff07cb84d974e83099e2f6

Contents?: true

Size: 1.03 KB

Versions: 14

Compression:

Stored size: 1.03 KB

Contents

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

      def snippet_text(step_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

        "#{step_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

14 entries across 14 versions & 1 rubygems

Version Path
cucumber-0.8.7 lib/cucumber/js_support/js_snippets.rb
cucumber-0.9.3 lib/cucumber/js_support/js_snippets.rb
cucumber-0.9.2 lib/cucumber/js_support/js_snippets.rb
cucumber-0.9.1 lib/cucumber/js_support/js_snippets.rb
cucumber-0.9.0 lib/cucumber/js_support/js_snippets.rb
cucumber-0.8.5 lib/cucumber/js_support/js_snippets.rb
cucumber-0.8.4 lib/cucumber/js_support/js_snippets.rb
cucumber-0.8.3 lib/cucumber/js_support/js_snippets.rb
cucumber-0.8.2 lib/cucumber/js_support/js_snippets.rb
cucumber-0.8.1 lib/cucumber/js_support/js_snippets.rb
cucumber-0.8.0 lib/cucumber/js_support/js_snippets.rb
cucumber-0.7.3 lib/cucumber/js_support/js_snippets.rb
cucumber-0.7.2 lib/cucumber/js_support/js_snippets.rb
cucumber-0.7.1 lib/cucumber/js_support/js_snippets.rb