TDD:
describe RPNCalculator do
attr_accessor :calculator
before do
@calculator = RPNCalculator.new
end
it "adds two numbers" do
calculator.push(2)
calculator.push(3)
calculator.plus
calculator.value.should == 5
end
end
我的代码:
class RPNCalculator
attr_accessor :calculator
def initialize()
@calculator = []
end
def RPNCalculator(x=0,y=0)
@calculator.push(x)
@calculator.push(y)
@calculator.map {|x,y| x + y }
end
错误:
RPNCalculator
adds two numbers (FAILED - 1)
失败:
1)RPNCalculator adds two numbers
Failure/Error: calculator.push(2)
NoMethodError:
undefined method `push' for #<RPNCalculator:0x000000021b85a8 @calculator=[]>