Permalink
Browse files

Beefing up tests

  • Loading branch information...
Stephen Cresswell
Stephen Cresswell committed Dec 26, 2012
1 parent 3fc02aa commit 95f80a0879b89441313bb39cea168fa1214ee58f
Showing with 26 additions and 9 deletions.
  1. +10 −3 test/test-scenarios.js
  2. +16 −6 test/test-steps.js
View
@@ -9,6 +9,15 @@ test('Developer runs a test step', function() {
])
});
+test('Developer uses regex groups to define test step arguments', function() {
+ yadda.yadda([
+ "Given a new Yadda instance",
+ "when Dirk adds a test step, 'count up to (\\d+) and down to (\\d+)'",
+ "and runs 'count up to 10 and down to 5'",
+ "then 'count up to (\\d+) and down to (\\d+)' is invoked with arguments 10 and 5"
+ ])
+})
+
test('Developer adds a conflicting literal test step', function() {
yadda.yadda([
"Given a new Yadda instance",
@@ -44,6 +53,4 @@ test('Developer runs a test step with an ambiguous template, where a best match
"but when Dirk runs 'Given pirate Rob\'s old parrot has green feathers' is run'",
"then 'Given pirate (.+) old parrot has green feathers' is executed 1 time"
])
-});
-
-// Literals
+});
View
@@ -6,14 +6,15 @@ var steps = new Steps()
})
.when("(?:Dirk adds|adds) (?:a|another) test step, '(.+)'", function(template) {
- shared.executions[template] = 0;
+ shared.executions[template] = [];
shared.yadda.steps.addStep(template, function() {
- shared.executions[template]++;
+ var executions = shared.executions[template];
+ executions[executions.length] = arguments;
});
})
.then("(?:Dirk|he) is prevented from adding a conflicting test step, '(.+)'", function(template) {
- var existing = shared.yadda.steps.findStep(template);
+ var existing = shared.yadda.steps.steps[template];
try {
shared.yadda.steps.addStep(template, function() {});
throw "Conflicting step was not reported";
@@ -26,9 +27,8 @@ var steps = new Steps()
shared.yadda.steps.runStep(text);
})
-.then("'(.+)' is executed (\\d) time(?:s)?", function(text, number) {
- var step = shared.yadda.steps.findStep(text);
- ok(shared.executions[step.template] == number);
+.then("'(.+)' is executed (\\d) time(?:s)?", function(template, number) {
+ ok(shared.executions[template].length == number);
})
.then("(?:Dirk|he) is prevented from running an ambiguous test step, '(.+)'", function(text) {
@@ -39,3 +39,13 @@ var steps = new Steps()
ok(e.match("Unable to determine which of .+ or .+ is more likely for \\[" + text + "]"));
}
})
+
+.then ("'(.+)' is invoked with arguments (\\d+) and (\\d+)", function(template, arg1, arg2) {
+ var executions = shared.executions[template];
+ ok(executions.length > 0);
+
+ var lastExecution = executions[executions.length - 1];
+ ok(lastExecution.length == 2);
+ ok(lastExecution[0] == arg1);
+ ok(lastExecution[1] == arg2);
+})

0 comments on commit 95f80a0

Please sign in to comment.