我正在进行“务实的Cucumber”第一个项目,但在我的步骤定义中遇到了未定义方法错误。错误来自于$?.success?。不用说,我很困惑。我是否缺少宝石或其他东西?
下面是步骤定义:
Given /^the input "(.*?)"$/ do |input|
@input = input
end
When /^the calculator is run$/ do
@output = 'ruby calc.rb #{@input}'
raise('Command failed!') unless $?.success? #$?.success? is failing. look that up.
end
Then /^the output should be "(.*?)"$/ do |arg1|
pending # express the regexp above with the code you wish you had
end
这里是错误信息。
Feature: Adding
Scenario: Add two numbers # features/adding.feature:3
Given the input "2+2" # features/step_definitions/calculator_steps.rb:1
When the calculator is run # features/step_definitions/calculator_steps.rb:5
undefined method `success?' for nil:NilClass (NoMethodError)
./features/step_definitions/calculator_steps.rb:7:in `/^the calculator is run$/'
features/adding.feature:5:in `When the calculator is run'
Then the output should be "4" # features/step_definitions/calculator_steps.rb:10
Failing Scenarios:
cucumber features/adding.feature:3 # Scenario: Add two numbers
1 scenario (1 failed)
3 steps (1 failed, 1 skipped, 1 passed)
0m0.012s
那么,问题出在哪里呢?我知道 .success? 是正确的,为什么 $? 没有被注册呢?谢谢!