我在我的解决方案中设置了 Cucumber-JS 和 Grunt-JS。
我的文件夹结构如下所示:
+ Project
+ features
- Search.feature
+ step_definitions
- Search_steps.js
+ support
- world.js
- package.json
- gruntfile.js
我在 gruntfile.js 中添加了一个 Cucumber-JS 任务:
// Project configuration.
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
cucumberjs: {
src: 'features',
options: {
steps: 'features/step_definitions',
format: 'pretty'
}
}
});
grunt.loadNpmTasks('grunt-cucumber');
grunt.registerTask('default', ['cucumberjs']);
我已经写出了我的功能文件:
Feature: Search
As a user of the website
I want to search
So that I can view items
Scenario: Searching for items
Given I am on the website
When I go to the homepage
Then I should see a location search box
还有我的步骤定义文件:
var SearchSteps = module.exports = function () {
this.World = require('../support/world').World;
this.Given('I am on the website', function(callback) {
callback.pending();
});
this.When('I go to the homepage', function (callback) {
callback.pending();
});
this.Then('I should see a location search box', function (callback) {
callback.pending();
});
};
还有我的 world.js 文件:
var World = function (callback) {
callback(this);
};
exports.World = World;
但是当我在命令行运行 grunt 时,虽然它似乎看到了我的功能,但它似乎从未运行任何步骤。
我得到的是:
Running "cucumberjs:src" (cucumberjs) task
Feature: Search
Scenario: Searching for items
Given I am on the website
When I go to the homepage
Then I should see a location search box
1 scenario (1 pending)
3 steps (1 pending, 2 skipped)
Done, without errors.
Cucumber 似乎没有注意我在测试中放入的内容。
即使我放入了一些明显的逻辑错误,例如:
this.Given('I am on the website', function(callback) {
var x = 0 / 0;
callback.pending();
});
它只是忽略它并打印上述消息。
我似乎可以从 Cucumber 中得到任何错误的唯一方法是在 step 文件中放置一个彻底的语法错误。例如,删除一个右括号。然后我得到这样的东西:
Running "cucumberjs:src" (cucumberjs) task
C:\dev\Project\features\step_definitions\Search_steps.js:14
};
^
Warning: Unexpected token ; Use --force to continue.
Aborted due to warnings.
我在这里想念什么?