新手试图学习黄瓜和红宝石

时间:2013-09-06 20:32:58

标签: ruby cucumber

我正在尝试在“The Cucumber Book”一书的Calculator项目中执行第2步。我试图按照此表单中给出的上一个答案来使用backtricks而不是单引号但我仍然收到以下相同的错误消息:

.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

我可以做错什么?

1 个答案:

答案 0 :(得分:0)

calc.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