为什么Cucumber没有执行我的步骤定义?

时间:2015-01-26 14:22:11

标签: javascript windows cucumber

在Windows上工作我已经安装了Ruby和Ruby DevKit来使用Cucumber。现在我有以下基本设置:

/app
   /features
       example.feature
       /step_definitions
           example.steps.js

在example.feature文件中,我有:

Feature: This is an example feature
    In order to learn Cucumber
    As a developer
    I want to make this feature pass

    Scenario: wrote my first scenario
        Given a variable set to 1
        When I increment the variable by 2
        Then the variable should contain 3

在example.step.js文件中,我有:

'use strict';

module.exports = function () {
    this.givenNumber = 0;

    this.Given(/^a variable set to (\d+)$/, function(number, next) {
        this.givenNumber = parseInt(number);
        next();
    });

    this.When(/^I increment the variable by (\d+)$/, function (number, next) {
        this.givenNumber = this.givenNumber + parseInt(number);
        next();
    });

    this.Then(/^the variable should contain (\d+)$/, function (number, next) {
        if (this.givenNumber != number)
            throw(new Error("This test didn't pass, givenNumber is " + this.givenNumber + " expected 0"));
        next();
    });
};

现在,当我从/ app目录运行'cucumber'时,我不断得到以下输出:

1 scenario (1 undefined)
3 steps (3 undefined)
0m0.004s

我尝试移动文件,添加--require选项等,但似乎没有任何帮助。

有什么想法吗?

1 个答案:

答案 0 :(得分:0)

显然,这不能直接使用'黄瓜'命令。 使用grunt进行设置并且grunt-cucumber任务似乎按预期工作:

我的Gruntfile.js

module.exports = function (grunt) {
    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']);
};

另外:如果你使用的是量角器。它有黄瓜构建。只需为量角器创建正确的配置(protractor.conf.js):

exports.config = {

    specs: [
        //'e2e/features/*.feature'
        '**/*.feature'
    ],

    capabilities: {
        'browserName': 'chrome'
    },

    baseUrl: 'http://localhost:9000/',

    framework: 'cucumber'
}