gpt4 book ai didi

javascript - 为什么 Cucumber 不执行我的步骤定义?

转载 作者:行者123 更新时间:2023-11-28 07:40:05 26 4
gpt4 key购买 nike

在 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 。它内置了 Cucumber。只需为 Protractor 创建正确的配置(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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com