在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选项等,但是似乎无济于事。

有任何想法吗?

最佳答案

显然,这不能使用“ cucumber”命令直接执行。
使用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'
}

关于javascript - 为什么Cucumber不执行我的步骤定义?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/28151920/

10-09 17:58
查看更多