0

我正在尝试在“黄瓜书”一书中的计算器项目中执行第 2 步。我已尝试按照此表单中给出的先前答案使用反技巧而不是单引号,但我仍然收到以下相同的错误消息:

.F-

(::) failed steps (::)

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'

Failing Scenarios:
cucumber features/adding.feature:3 # Scenario: Add two numbers

1 scenario (1 failed)
3 steps (1 failed, 1 skipped, 1 passed)
0m0.002s

这是我之前在您的论坛上找到的确切步骤信息:

Given /^the input "([^"]*)"$/ do |input|
  @input = input
end

When /^the calculator is run$/ do
  @output = `ruby calc.rb #{@input}`
  raise('Command failed!') unless $?.success?   
end

Then /^the output should be "([^"]*)"$/ do |arg1|
  pending # express the regexp above with the code you wish you had
end

我做错了什么?

4

1 回答 1

0

计算.rb:

#!/usr/bin/env ruby

# install bc with 'sudo apt-get install bc'

if ARGV.size > 0
    command='echo ' +  ARGV.join('') + ' | bc'
    exec(command)
end
...
Now my cucumber output looks like:
auser@worker1:~/cucumber/calculator# cucumber
Feature: Adding

  Scenario: Add two numbers       # features/adding.feature:2
    Given the input "2+2"         # features/step_definitions/calculator_steps.rb:1
    When the calculator is run    # features/step_definitions/calculator_steps.rb:5
    Then the output should be "4" # features/step_definitions/calculator_steps.rb:10

1 scenario (1 passed)
3 steps (3 passed)
0m0.021s
于 2013-10-06T06:22:31.430 回答