2014-10-10 2 views
0

나는 아주 간단한 Google 검색처럼 보이는 것을 찾을 수 없습니다.rspec에서 raise_error를 어떻게 해결합니까?

def plus 
    if @calculator.length == 0 
     raise ArgumentError.new("calculator is empty") 
    end 
    sum = @calculator[-1] + @calculator[-2] 
    2.times {@calculator.pop} 
    @calculator.push(sum) 
end 

그러나 그것은 아무것도 해결되지 않습니다 나는 RPN 계산기 프로그램 메신저 서면 더하기 방법

it "fails informatively when there's not enough values stacked away" do 
    expect { 
    calculator.plus 
    }.to raise_error("calculator is empty") 

내 코드의 내 프로그램에 RSpec에있는 것은. 나는 특히 예외에 관해서는 프로그래밍에 익숙하지 않으므로 어떤 도움을 주시면 감사하겠습니다.

나는 그것의 진짜로 간단하다는 것을 확실하다, 그러나 나는 도처에보고있는 1 시간 이상 동안 이것에 붙어 있었다.

 
F  Failure/Error: expect { 
     expected Exception with "calculator is empty", got # with backtrace: 
     # ./lib/12_rpn_calculator.rb:22:in `minus' 
     # ./spec/12_rpn_calculator_spec.rb:124:in `block (3 levels) in ' 
     # ./spec/12_rpn_calculator_spec.rb:123:in `block (2 levels) in ' 
+0

여기서 수정해야 할 부분이 무엇인지 ... 무엇을보고 계십니까? –

+0

원래 게시판에 오류를 넣었지만 명령 프롬프트에서 붙여 넣은 방법을 엉망으로 만들고 싶지 않았습니다. –

+0

나는 그것을 이해했다. .. 한숨 쉬워진다. .. if를 없앤다. raise @ calculator.length <= 1이라면 "calculator is empty"이다. –

답변

-2

내가 다음과 같이 썼다 : 나는 번들 RSpec에 프로그램을 실행할 때

은 내가 오류 메시지입니다. 이 테스트를 해결하는 데 많은 실패가있었습니다.

def times 
    [email protected] 
    [email protected] 
    if n1==nil || n2==nil 
    raise('calculator is empty') 
    else 
    @calculator.push(n2.to_f*n1.to_f) 
    end 
end 
관련 문제