执行结果: 0 scenarios 0 steps 0m0.000s
在features目录下,创建feature文件
Feature: Adding Scenario: Add two numbers Given the input “2+2” When the calculator is run Then the output should be “4”在my-first-project目录下,执行cucumber执行结果: Feature: Adding
Scenario: Add two numbers # features/adding.feature:2 Given the input “2+2” # features/adding.feature:3 When the calculator is run # features/adding.feature:4 Then the output should be “4” # features/adding.feature:5
1 scenario (1 undefined) 3 steps (3 undefined) 0m0.013s
You can implement step definitions for undefined steps with these snippets:
Given(“the input {string}”) do |string| pending # Write code here that turns the phrase above into concrete actions end
When(“the calculator is run”) do pending # Write code here that turns the phrase above into concrete actions end
Then(“the output should be {string}”) do |string| pending # Write code here that turns the phrase above into concrete actions end
运行cucumber命令时,会扫描features中的文件,每个feature中包含多个Scenario, Scenario中的step会调用step definitions中的编写的测试代码,以上错误,就是因为step definitions中没有feature文件对应的定义代码
Given(/^the input “([^”]*)”$/) do |input| @input = input end
When(/^the calculator is run$/) do @output = ruby features/support/calc.rb #{@input} raise(‘Command failed’) unless $?.success? end
Then(/^the output should be “([^”]*)”$/) do |expected_output| puts @expected_output
未完待续。。。
