Skip to content

Commit

Permalink
Add support for scenario outlines and examples (close #155)
Browse files Browse the repository at this point in the history
Also closes #10 and closes #75.

Squashed commit of the following:

commit aeb2630
Author: Ben Van Treese <vantreeseba@gmail.com>
Date:   Mon Feb 24 17:26:14 2014 -0600

    fixing spec for assembler

commit 4f76479
Author: Ben Van Treese <vantreeseba@gmail.com>
Date:   Mon Feb 24 17:25:09 2014 -0600

    removing duplicated step insertion

commit e7e2198
Author: Ben Van Treese <vantreeseba@gmail.com>
Date:   Tue Feb 18 17:07:41 2014 -0600

    added dependency to underscore.string, changed snippet builder to camelize outline variables when put into arguments list

commit 66b9f7d
Author: Ben Van Treese <vantreeseba@gmail.com>
Date:   Mon Feb 17 09:43:11 2014 -0600

    adding error message when a user tries to use examples outside of a scenario outline

commit 04b984d
Author: Ben Van Treese <vantreeseba@gmail.com>
Date:   Mon Feb 17 09:32:09 2014 -0600

    updating version of connect in package.json to 2.13.0

commit a038071
Author: Ben Van Treese <vantreeseba@gmail.com>
Date:   Tue Feb 11 14:33:28 2014 -0600

    fixing some issues with cli step / json formatter feature on windows

commit bc7b840
Author: Ben Van Treese <vantreeseba@gmail.com>
Date:   Mon Feb 10 21:30:06 2014 -0600

    removing step_definition_snippet_steps that were not implemented

commit d8efad6
Author: Ben Van Treese <vantreeseba@gmail.com>
Date:   Mon Feb 10 21:25:29 2014 -0600

    cleaning up travis to remove trying to install bundler, actually implemented scenario outline steps, implemented snipper builder steps for example outline snippets

commit 60b437c
Author: Ben Van Treese <vantreeseba@gmail.com>
Date:   Mon Feb 10 11:08:51 2014 -0600

    trying to get bundler installed globally for rvm.

commit 28224ef
Author: Ben Van Treese <vantreeseba@gmail.com>
Date:   Mon Feb 10 10:32:19 2014 -0600

    fixing specs on payloadType

commit 1cd669c
Author: Ben Van Treese <vantreeseba@gmail.com>
Date:   Mon Feb 10 10:30:06 2014 -0600

    changing payload_type to payloadType

commit aa471b3
Author: Ben Van Treese <vantreeseba@gmail.com>
Date:   Mon Feb 10 10:24:18 2014 -0600

    making buildScenarios 'polymorphic'

commit 35a5462
Author: Ben Van Treese <vantreeseba@gmail.com>
Date:   Mon Feb 10 10:14:04 2014 -0600

    renaming scenarios parts of feature to featureElements

commit 28ce292
Author: Ben Van Treese <vantreeseba@gmail.com>
Date:   Mon Feb 10 10:01:19 2014 -0600

    changing name of stored scenarios in feature to feature elements

commit 65039bd
Author: Ben Van Treese <vantreeseba@gmail.com>
Date:   Sat Feb 8 17:40:16 2014 -0600

    apparently sudo install is wrong on travis gems :P

commit f4803c6
Author: Ben Van Treese <vantreeseba@gmail.com>
Date:   Sat Feb 8 17:37:39 2014 -0600

    adding bundler install step to travis.yml

commit 4a39f81
Author: Ben Van Treese <vantreeseba@gmail.com>
Date:   Sat Feb 8 17:34:45 2014 -0600

    removing stupid .orig files

commit ed2812d
Author: Ben Van Treese <vantreeseba@gmail.com>
Date:   Sat Feb 8 17:28:36 2014 -0600

    adding more assembler tests

commit 17715a5
Author: Ben Van Treese <vantreeseba@gmail.com>
Date:   Sat Feb 8 16:57:04 2014 -0600

    cleaning up steps a little, cleaning up assembler functions for scenario_outlines

commit d10585d
Author: Ben Van Treese <vantreeseba@gmail.com>
Date:   Sat Feb 8 16:43:07 2014 -0600

    adding specs for outline_step and changes to step

commit afdf537
Author: Ben Van Treese <vantreeseba@gmail.com>
Date:   Sat Feb 8 16:36:11 2014 -0600

    making current tests pass

commit 8359996
Author: unknown <jharlin@NormanDev2.telogical.com>
Date:   Fri Feb 7 19:06:06 2014 -0600

    adding back steps

commit 8d4439e
Author: unknown <jharlin@NormanDev2.telogical.com>
Date:   Fri Feb 7 19:04:59 2014 -0600

    Added better suggestion output for missing scenario outline steps

commit 3ba5088
Author: unknown <jharlin@NormanDev2.telogical.com>
Date:   Fri Feb 7 18:06:36 2014 -0600

    basic scenario outline functionality completed

commit f3659a3
Author: Ben Van Treese <vantreeseba@gmail.com>
Date:   Fri Feb 7 09:29:28 2014 -0600

    more specs on scenario outline

commit 5168174
Author: Ben Van Treese <vantreeseba@gmail.com>
Date:   Thu Feb 6 22:01:45 2014 -0600

    started on scenario_outline specs, and finished example_specs

commit f8b8d35
Author: Ben Van Treese <vantreeseba@gmail.com>
Date:   Thu Feb 6 20:24:58 2014 -0600

    got all scenario_outline.feature passing

commit 25269b7
Author: unknown <jharlin@NormanDev2.telogical.com>
Date:   Thu Feb 6 16:12:32 2014 -0600

    trying to get to the bottom of stack overflow error

commit 323500a
Author: unknown <jharlin@NormanDev2.telogical.com>
Date:   Thu Feb 6 16:02:36 2014 -0600

    Fixing jasmine specs for ast_tree_walker visiting scenarios

commit d993e88
Author: Ben Van Treese <vantreeseba@gmail.com>
Date:   Thu Feb 6 15:22:55 2014 -0600

    commenting out failing features

commit 084da1a
Author: Ben Van Treese <vantreeseba@gmail.com>
Date:   Thu Feb 6 14:36:57 2014 -0600

    re-adding scenario outline feature, cleaning up some steps, cleanin up scenario outline and data table

commit 77d4caf
Author: Ben Van Treese <vantreeseba@gmail.com>
Date:   Wed Feb 5 15:55:38 2014 -0600

    trying to get scenario outlines working

commit b013d39
Merge: 1967b21 b5bd31a
Author: Ben Van Treese <vantreeseba@gmail.com>
Date:   Wed Feb 5 15:21:39 2014 -0600

    trying to merge in master

commit 1967b21
Author: Fedotov Daniil <hairyhum@gmail.com>
Date:   Wed Jun 27 15:08:07 2012 +0400

    [+] Prepared for pull request

commit 09c25ee
Author: Fedotov Daniil <hairyhum@gmail.com>
Date:   Wed Jun 27 15:01:45 2012 +0400

    [+] Fixing index

commit 7699725
Author: Fedotov Daniil <hairyhum@gmail.com>
Date:   Sat Jun 9 17:06:49 2012 +0400

    [*] Added scenario outline test

commit d940ac2
Author: Fedotov Daniil <hairyhum@gmail.com>
Date:   Sat Jun 9 15:25:49 2012 +0400

    [+] added cucumber tests for scenarios and outlines
    [*] Fixed data table example mapping

commit 9965ff9
Author: Fedotov Daniil <fedotov.danil@gmail.com>
Date:   Fri Jun 8 22:20:35 2012 +0400

    [*] Fixing some collection calls

commit fc08ef8
Author: Fedotov Daniil <hairyhum@gmail.com>
Date:   Mon Jun 4 18:12:10 2012 +0400

    [*] witnessNewScenario every example row

commit d563a1d
Author: Fedotov Daniil <hairyhum@gmail.com>
Date:   Fri Jun 1 15:23:22 2012 +0400

    [*] Changed example row reporting

commit f8b27ea
Author: Fedotov Daniil <hairyhum@gmail.com>
Date:   Wed May 30 19:16:16 2012 +0400

    outline fix

commit db6d9c5
Author: Fedotov Daniil <hairyhum@gmail.com>
Date:   Wed May 30 15:19:43 2012 +0400

    [*] Scenarios and outlines events

commit e437a70
Author: Fedotov Daniil <hairyhum@gmail.com>
Date:   Wed May 30 12:12:06 2012 +0400

    [*] Prepared UIA version

commit 016df31
Author: Fedotov Daniil <fedotov.danil@gmail.com>
Date:   Mon May 28 01:00:35 2012 +0400

    [+] Added step definitions and examples
  • Loading branch information
vantreeseba authored and jbpros committed Mar 5, 2014
1 parent b5bd31a commit c2a9916
Show file tree
Hide file tree
Showing 35 changed files with 852 additions and 202 deletions.
78 changes: 78 additions & 0 deletions features/scenario_outlines.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
Feature: Scenario Outlines and Examples

Scenario: Basic outline
Given the following feature:
"""
Feature: testing scenarios
Background:
Given a background step
Scenario Outline: outline
When a <some> step
Then i get <result>
Examples:
| some | result |
| passing | passed |
| failing | skipped |
"""
And the step "a background step" has a passing mapping
And the step "a passing step" has a passing mapping
And the step "a failing step" has a failing mapping
And the step "i get passed" has a passing mapping
And the step "i get skipped" has a passing mapping
When Cucumber runs the feature
Then the scenario called "outline" is reported as failing
And the step "a background step" passes
And the step "a passing step" passes
And the step "a failing step" passes
And the step "i get passed" passes
And the step "i get skipped" is skipped

Scenario: Outline with table
Given the following feature:
"""
Feature: testing scenarios
Scenario Outline: outline
When a table step:
| first | second |
| <first> | <second> |
Examples:
| first | second |
| 1 | 2 |
"""
And the step "a table step:" has a passing mapping that receives a data table
When Cucumber runs the feature
Then the received data table array equals the following:
"""
[["first","second"],["1","2"]]
"""

Scenario: Outline with doc string
Given the following feature:
"""
Feature: testing scenarios
Scenario Outline: outline
When a doc string step:
\"\"\"
I am doc string in <example> example
And there are <string> string
\"\"\"
Examples:
| example | string |
| first | some |
"""
And the step "a doc string step:" has a passing mapping that receives a doc string
When Cucumber runs the feature
Then the received doc string equals the following:
"""
I am doc string in first example
And there are some string
"""

Scenario Outline: outline
When a <some> step
Then i get <result>
Examples:
| some | result |
| passing | passed |
| failing | skipped |
8 changes: 8 additions & 0 deletions features/step_definition_snippets.feature
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,11 @@ Feature: step definition snippets
"""
When Cucumber executes the scenario
Then a "Given" step definition snippet for /^I have some "([^"]*)", "([^"]*)" and "([^"]*)" cucumbers$/ with 3 parameters is suggested
Scenario: outline steps with examples
Given a scenario with:
"""
Given I have <some> cucumbers
"""
When Cucumber executes the scenario
Then a "Given" example step definition snippet for /^I have "(.*)" cucumbers$/ with 1 parameters is suggested
4 changes: 2 additions & 2 deletions features/step_definitions/cli_steps.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,9 @@ var cliSteps = function cliSteps() {
var actualError = lastRun['error'];
var actualStderr = lastRun['stderr'];

expectedOutput = expectedOutput.replace(/<current-directory>/g, tmpDir);
expectedOutput = expectedOutput.replace(/<current-directory>/g, tmpDir.replace(/\\/g,'/'));

try { var actualJson = JSON.parse(actualOutput); }
try { var actualJson = JSON.parse(actualOutput.replace(/\\\\/g,'/')); }
catch(err) { throw new Error("Error parsing actual JSON:\n" + actualOutput); }

try { var expectedJson = JSON.parse(expectedOutput); }
Expand Down
114 changes: 15 additions & 99 deletions features/step_definitions/cucumber_steps.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
var cucumberSteps = function() {
var Given = When = Then = this.defineStep;
var Given = When = Then = this.defineStep;
var World = require('./cucumber_world').World;
this.World = World;

Expand All @@ -21,18 +21,6 @@ var cucumberSteps = function() {
this.addAroundHook(callback);
});

Given(/^an untagged hook$/, function(callback) {
this.addUntaggedHook(callback);
});

Given(/^a hook tagged with "([^"]*)"$/, function(tags, callback) {
this.addHookWithTags(tags, callback);
});

Given(/^an around hook tagged with "([^"]*)"$/, function(tags, callback) {
this.addAroundHookWithTags(tags, callback);
});

Given(/^the step "([^"]*)" has a failing mapping$/, function(stepName, callback) {
this.addFailingMapping(stepName, {}, callback);
});
Expand Down Expand Up @@ -96,6 +84,14 @@ setTimeout(callback.pending, 10);\
callback();
});

Given(/^the step "([^"]*)" has a passing mapping that receives a doc string$/, function(stepName, callback) {
this.stepDefinitions += "Given(/^" + stepName + "$/, function(docString, callback) {\
world.docString = docString;\
callback();\
});";
callback();
});

Given(/^the following data table in a step:$/, function(dataTable, callback) {
this.featureSource += "Feature:\n";
this.featureSource += " Scenario:\n";
Expand All @@ -111,31 +107,6 @@ setTimeout(callback.pending, 10);\
callback();
});

Given(/^a scenario without any tags$/, function(callback) {
this.addPassingScenarioWithoutTags();
callback();
});

Given(/^a scenario tagged with "([^"]*)"$/, function(tag, callback) {
this.addPassingScenarioWithTags(tag);
callback();
});

Given(/^a scenario tagged with "([^"]*)" and "([^"]*)"$/, function(tag1, tag2, callback) {
this.addPassingScenarioWithTags(tag1, tag2);
callback();
});

Given(/^a scenario tagged with "([^"]*)", "([^"]*)" and "([^"]*)"$/, function(tag1, tag2, tag3, callback) {
this.addPassingScenarioWithTags(tag1, tag2, tag3);
callback();
});

Given(/^a feature tagged with "([^"]*)"$/, function(tag, callback) {
this.createEmptyFeature({tags: [tag]});
callback();
});

Given(/^several features$/, function(callback) {
this.features = [
["feature1", "Feature: One\n\n Scenario:\n"],
Expand All @@ -149,10 +120,6 @@ setTimeout(callback.pending, 10);\
this.runFeature({}, callback);
});

When(/^Cucumber executes a scenario(?: with no tags)?$/, function(callback) {
this.runAScenario(callback);
});

this.When(/^Cucumber executes a scenario using that mapping$/, function(callback) {
this.runAScenarioCallingMapping(callback);
});
Expand All @@ -165,13 +132,9 @@ setTimeout(callback.pending, 10);\
this.runAScenarioCallingWorldFunction(callback);
});

When(/^Cucumber executes a scenario tagged with "([^"]*)"$/, function(tag, callback) {
this.addPassingScenarioWithTags(tag);
this.runFeature({}, callback);
});

When(/^Cucumber runs the feature$/, function(callback) {
this.runFeature({}, callback);
//callback.pending();
});

When(/^Cucumber runs the features$/, function(callback) {
Expand Down Expand Up @@ -200,38 +163,6 @@ callback();\
this.runFeature({}, callback);
});

When(/^Cucumber executes scenarios tagged with "([^"]*)"$/, function(tag, callback) {
this.runFeature({tags: [tag]}, callback);
});

When(/^Cucumber executes scenarios not tagged with "([^"]*)"$/, function(tag, callback) {
this.runFeature({tags: ['~'+tag]}, callback);
});

When(/^Cucumber executes scenarios tagged with "([^"]*)" or "([^"]*)"$/, function(tag1, tag2, callback) {
this.runFeature({tags: [tag1 + ', ' + tag2]}, callback);
});

When(/^Cucumber executes scenarios tagged with both "([^"]*)" and "([^"]*)"$/, function(tag1, tag2, callback) {
this.runFeature({tags: [tag1, tag2]}, callback);
});

When(/^Cucumber executes scenarios not tagged with "([^"]*)" nor "([^"]*)"$/, function(tag1, tag2, callback) {
this.runFeature({tags: ['~'+tag1, '~'+tag2]}, callback);
});

When(/^Cucumber executes scenarios not tagged with both "([^"]*)" and "([^"]*)"$/, function(tag1, tag2, callback) {
this.runFeature({tags: ['~' + tag1 + ', ~' + tag2]}, callback);
});

When(/^Cucumber executes scenarios tagged with "([^"]*)" or without "([^"]*)"$/, function(tag1, tag2, callback) {
this.runFeature({tags: [tag1 + ', ~' + tag2]}, callback);
});

When(/^Cucumber executes scenarios tagged with "([^"]*)" but not with both "([^"]*)" and "([^"]*)"$/, function(tag1, tag2, tag3, callback) {
this.runFeature({tags: [tag1, '~' + tag2, '~' + tag3]}, callback);
});

Then(/^the scenario passes$/, function(callback) {
this.assertPassedScenario();
callback();
Expand Down Expand Up @@ -309,6 +240,11 @@ callback();\
callback();
});

Then(/^the received doc string equals the following:$/, function(docString, callback) {
this.assertEqual(docString, World.mostRecentInstance.docString);
callback();
});

this.Then(/^the explicit World object function should have been called$/, function(callback) {
this.assertTrue(this.explicitWorldFunctionCalled);
callback();
Expand Down Expand Up @@ -341,25 +277,5 @@ callback();\
this.assertCycleSequenceExcluding('hook');
callback();
});

Then(/^(?:only the first|the) scenario is executed$/, function(callback) {
this.assertExecutedNumberedScenarios(1);
callback();
});

Then(/^only the first two scenarios are executed$/, function(callback) {
this.assertExecutedNumberedScenarios(1, 2);
callback();
});

Then(/^only the third scenario is executed$/, function(callback) {
this.assertExecutedNumberedScenarios(3);
callback();
});

Then(/^only the second, third and fourth scenarios are executed$/, function(callback) {
this.assertExecutedNumberedScenarios(2, 3, 4);
callback();
});
};
module.exports = cucumberSteps;
2 changes: 1 addition & 1 deletion features/step_definitions/cucumber_world.js
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ proto.assertScenarioNotReportedAsFailing = function assertScenarioNotReportedAsF
};

proto.assertPassedStep = function assertPassedStep(stepName) {
if (!this.isStepTouched(stepName))
if (!this.isStepTouched(stepName))
throw(new Error("Expected step \"" + stepName + "\" to have passed."));
};

Expand Down
27 changes: 27 additions & 0 deletions features/step_definitions/scenario_execution_steps.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
var scenario_exection_steps = function() {
var Given = When = Then = this.defineStep;
var World = require('./cucumber_world').World;
this.World = World;


Then(/^(?:only the first|the) scenario is executed$/, function(callback) {
this.assertExecutedNumberedScenarios(1);
callback();
});

Then(/^only the first two scenarios are executed$/, function(callback) {
this.assertExecutedNumberedScenarios(1, 2);
callback();
});

Then(/^only the third scenario is executed$/, function(callback) {
this.assertExecutedNumberedScenarios(3);
callback();
});

Then(/^only the second, third and fourth scenarios are executed$/, function(callback) {
this.assertExecutedNumberedScenarios(2, 3, 4);
callback();
});
};
module.exports = scenario_exection_steps;
17 changes: 17 additions & 0 deletions features/step_definitions/scenario_outline_steps.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
var scenario_outline_steps = function() {
var Given = When = Then = this.defineStep;
var World = require('./cucumber_world').World;
this.World = World;

this.When(/^a (.*) step$/, function (some, callback) {
this.assertTrue(some === "passing" || some === "failing");
callback();
});

this.Then(/^i get (.*)$/, function (result, callback) {
this.assertTrue(result === "passed" || result === "skipped");
callback();
});
}

module.exports = scenario_outline_steps;
14 changes: 14 additions & 0 deletions features/step_definitions/step_definition_snippets_steps.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
var stepDefinitionSnippetsSteps = function() {
var Given = When = Then = this.defineStep;
var World = require('./cucumber_world').World;
this.World = World;

this.Then(/^a "([^"]*)" example step definition snippet for \/\^I have "([^"]*)" cucumbers\$\/ with (\d+) parameters is suggested$/, function (stepName, snippetParameter, paramCount, callback) {
this.assertEqual(stepName, "Given");
this.assertEqual(snippetParameter,'(.*)');
this.assertEqual(paramCount,"1");
callback();
});
}

module.exports = stepDefinitionSnippetsSteps;
Loading

0 comments on commit c2a9916

Please sign in to comment.