2013-09-06 3 views
0

"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 

내가 뭘 잘못하고 있니?

+0

은 루비 설치 어떤 버전의
을 가지고있다? – Bala

+0

1) calc.rb 파일에 모든 사용자에 대한 실행 권한이 있습니까? 2) calc.rb는 상단에 세방 줄이 있습니까? 그리고 그들은 backback이라고 불립니다. – 7stud

+0

3) 경로 문제가 있다고 생각합니다. calc.rb 파일의 전체 경로를 사용해보십시오. 4) 루비 전역 변수 $? 마지막 자식 프로세스의 종료 상태에 대한 종료 상태를 포함하거나 기본적으로 nil을 포함합니다. 귀하의 오류는 당신이 성공을 0으로 말하고 있기 때문에, 그것은 $를 의미합니까? nil은 백틱에서 루비 프로세스가 실행되지 않았 음을 의미합니다. – 7stud

답변

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: 
[email protected]:~/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 
관련 문제