Permalink
Browse files

Merge branch 'lennart/coffee' into lennart/master

  • Loading branch information...
lennart committed Jan 22, 2012
2 parents bea1d01 + 958de3f commit 07f927b9577db7cb18dbca3e67ca3fcd717f1327
@@ -14,6 +14,13 @@ var ArgumentParser = function(argv) {
self.storeOptions(options);
},
+ snippetLang: function undefinedSnippetLanguage() {
+ var useCoffeeScript = self.getOptionOrDefault(ArgumentParser.COFFEE_SCRIPT_FLAG_NAME,
+ ArgumentParser.DEFAULT_COFFEE_SCRIPT_FLAG_VALUE);
+
+ return useCoffeeScript ? "coffee" : "javascript";
+ },
+
getFeatureFilePaths: function getFeatureFilePaths() {
var unexpandedFeaturePaths = self.getUnexpandedFeaturePaths();
var expandedFeaturePaths = ArgumentParser.FeaturePathExpander.expandPaths(unexpandedFeaturePaths);
@@ -51,16 +58,18 @@ var ArgumentParser = function(argv) {
getKnownOptionDefinitions: function getKnownOptionDefinitions() {
var definitions = {};
- definitions[ArgumentParser.REQUIRE_OPTION_NAME] = [path, Array];
- definitions[ArgumentParser.HELP_FLAG_NAME] = Boolean;
- definitions[ArgumentParser.VERSION_FLAG_NAME] = Boolean;
+ definitions[ArgumentParser.REQUIRE_OPTION_NAME] = [path, Array];
+ definitions[ArgumentParser.HELP_FLAG_NAME] = Boolean;
+ definitions[ArgumentParser.COFFEE_SCRIPT_FLAG_NAME] = Boolean;
+ definitions[ArgumentParser.VERSION_FLAG_NAME] = Boolean;
return definitions;
},
getShortenedOptionDefinitions: function getShortenedOptionDefinitions() {
var definitions = {};
- definitions[ArgumentParser.REQUIRE_OPTION_SHORT_NAME] = [ArgumentParser.LONG_OPTION_PREFIX + ArgumentParser.REQUIRE_OPTION_NAME];
- definitions[ArgumentParser.HELP_FLAG_SHORT_NAME] = [ArgumentParser.LONG_OPTION_PREFIX + ArgumentParser.HELP_FLAG_NAME];
+ definitions[ArgumentParser.REQUIRE_OPTION_SHORT_NAME] = [ArgumentParser.LONG_OPTION_PREFIX + ArgumentParser.REQUIRE_OPTION_NAME];
+ definitions[ArgumentParser.HELP_FLAG_SHORT_NAME] = [ArgumentParser.LONG_OPTION_PREFIX + ArgumentParser.HELP_FLAG_NAME];
+ definitions[ArgumentParser.COFFEE_SCRIPT_FLAG_SHORT_NAME] = [ArgumentParser.LONG_OPTION_PREFIX + ArgumentParser.COFFEE_SCRIPT_FLAG_NAME];
return definitions;
},
@@ -94,6 +103,9 @@ ArgumentParser.NUMBER_OF_LEADING_ARGS_TO_SLICE = 2;
ArgumentParser.DEFAULT_FEATURES_DIRECTORY = "features";
ArgumentParser.FEATURE_FILENAME_REGEXP = /\/[^\/]+\.feature$/i;
ArgumentParser.LONG_OPTION_PREFIX = "--";
+ArgumentParser.COFFEE_SCRIPT_FLAG_NAME = "coffee";
+ArgumentParser.COFFEE_SCRIPT_FLAG_SHORT_NAME = "c";
+ArgumentParser.DEFAULT_COFFEE_SCRIPT_FLAG_VALUE = false;
ArgumentParser.REQUIRE_OPTION_NAME = "require";
ArgumentParser.REQUIRE_OPTION_SHORT_NAME = "r";
ArgumentParser.HELP_FLAG_NAME = "help";
@@ -19,6 +19,8 @@ var Configuration = function(argv) {
return supportCodeLibrary;
},
+ snippetLang: argumentParser.snippetLang(),
+
isHelpRequested: function isHelpRequested() {
var isHelpRequested = argumentParser.isHelpRequested();
return isHelpRequested;
@@ -6,17 +6,21 @@ var StepDefinitionSnippetBuilder = function(step, configuration) {
var self = {
buildSnippet: function buildSnippet() {
+ if (!configuration)
+ configuration = {};
var functionName = self.buildStepDefinitionFunctionName();
var pattern = self.buildStepDefinitionPattern();
var parameters = self.buildStepDefinitionParameters();
+ // TODO: Add a CLI option to change to CoffeScript
+ var snippetLang = configuration.snippetLang || "javascript";
var snippet =
- StepDefinitionSnippetBuilder.STEP_DEFINITION_START +
- functionName +
- StepDefinitionSnippetBuilder.STEP_DEFINITION_INNER1 +
- pattern +
- StepDefinitionSnippetBuilder.STEP_DEFINITION_INNER2 +
- parameters +
- StepDefinitionSnippetBuilder.STEP_DEFINITION_END;
+ StepDefinitionSnippetBuilder[snippetLang].STEP_DEFINITION_START +
+ functionName +
+ StepDefinitionSnippetBuilder[snippetLang].STEP_DEFINITION_INNER1 +
+ pattern +
+ StepDefinitionSnippetBuilder[snippetLang].STEP_DEFINITION_INNER2 +
+ parameters +
+ StepDefinitionSnippetBuilder[snippetLang].STEP_DEFINITION_END;
return snippet;
},
@@ -85,10 +89,19 @@ var StepDefinitionSnippetBuilder = function(step, configuration) {
return self;
};
-StepDefinitionSnippetBuilder.STEP_DEFINITION_START = 'this.';
-StepDefinitionSnippetBuilder.STEP_DEFINITION_INNER1 = '(';
-StepDefinitionSnippetBuilder.STEP_DEFINITION_INNER2 = ', function(';
-StepDefinitionSnippetBuilder.STEP_DEFINITION_END = ") {\n // express the regexp above with the code you wish you had\n callback.pending();\n});\n";
+StepDefinitionSnippetBuilder.coffee = {
+ STEP_DEFINITION_START: "",
+ STEP_DEFINITION_INNER1: " ",
+ STEP_DEFINITION_INNER2: ", (",
+ STEP_DEFINITION_END: ") ->\n # express the regexp above with the code you wish you had\n callback.pending()\n\n"
+};
+StepDefinitionSnippetBuilder.javascript = {
+ STEP_DEFINITION_START: 'this.',
+ STEP_DEFINITION_INNER1: "(",
+ STEP_DEFINITION_INNER2: ", function(",
+ STEP_DEFINITION_END: ") {\n // express the regexp above with the code you wish you had\n callback.pending();\n});\n"
+};
+
StepDefinitionSnippetBuilder.STEP_DEFINITION_DOC_STRING = 'string';
StepDefinitionSnippetBuilder.STEP_DEFINITION_DATA_TABLE = 'table';
StepDefinitionSnippetBuilder.STEP_DEFINITION_CALLBACK = 'callback';
@@ -4,13 +4,14 @@ require('../../support/configurations_shared_examples.js');
describe("Cucumber.Cli.Configuration", function() {
var Cucumber = requireLib('cucumber');
- var argv, configuration;
+ var argv, configuration, snippetLang;
var argumentParser;
var context = {};
beforeEach(function() {
argv = createSpy("arguments (argv)");
- argumentParser = createSpyWithStubs("argument parser", {parse: null});
+ snippetLang = createSpy("undefined snippet language");
+ argumentParser = createSpyWithStubs("argument parser", {parse: null, snippetLang: snippetLang});
spyOn(Cucumber.Cli, 'ArgumentParser').andReturn(argumentParser);
configuration = Cucumber.Cli.Configuration(argv);
context['configuration'] = configuration;
@@ -10,8 +10,62 @@ describe("Cucumber.SupportCode.StepDefinitionSnippetBuilder", function() {
beforeEach(function() {
step = createSpy("step");
snippetBuilder = Cucumber.SupportCode.StepDefinitionSnippetBuilder(step);
+
+ });
+
+ describe("using coffee-script snippet language", function () {
+
+ beforeEach(function() {
+ snippetBuilder = Cucumber.SupportCode.StepDefinitionSnippetBuilder(step, {
+ snippetLang: "coffee"
+ });
+ });
+
+ describe("buildSnippet()", function() {
+ var functionName, pattern, parameters;
+
+ beforeEach(function() {
+ functionName = "defineSomeStep";
+ pattern = "/^some step pattern$/";
+ parameters = "some, parameters, and, the, callback";
+ spyOn(snippetBuilder, 'buildStepDefinitionFunctionName').andReturn(functionName);
+ spyOn(snippetBuilder, 'buildStepDefinitionPattern').andReturn(pattern);
+ spyOn(snippetBuilder, 'buildStepDefinitionParameters').andReturn(parameters);
+ });
+
+ it("builds the step definition's function name", function() {
+ snippetBuilder.buildSnippet();
+ expect(snippetBuilder.buildStepDefinitionFunctionName).toHaveBeenCalled();
+ });
+
+ it("builds the step definition's pattern", function() {
+ snippetBuilder.buildSnippet();
+ expect(snippetBuilder.buildStepDefinitionPattern).toHaveBeenCalled();
+ });
+
+ it("builds the step definition's parameters", function() {
+ snippetBuilder.buildSnippet();
+ expect(snippetBuilder.buildStepDefinitionParameters).toHaveBeenCalled();
+ });
+
+ it("returns the snippet", function() {
+ var actualSnippet = snippetBuilder.buildSnippet();
+ var expectedSnippet =
+ "" +
+ functionName +
+ " " +
+ pattern +
+ ", (" +
+ parameters +
+ ") ->\n # express the regexp above with the code you wish you had\n callback.pending()\n\n";
+ expect(actualSnippet).toBe(expectedSnippet);
+ });
+ });
+
});
+
+
describe("buildSnippet()", function() {
var functionName, pattern, parameters;

0 comments on commit 07f927b

Please sign in to comment.