Issue about Ruby class Timer in rspec -
i ruby newbie trying create class timer following rspec:
require 'timer' describe "timer" before(:each) @timer = timer.new end "should initialize 0 seconds" @timer.seconds.should == 0 end describe 'time_string' "should display 0 seconds 00:00:00" @timer.seconds = 0 @timer.time_string.should == "00:00:00" end "should display 12 seconds 00:00:12" @timer.seconds = 12 @timer.time_string.should == "00:00:12" end "should display 66 seconds 00:01:06" @timer.seconds = 66 @timer.time_string.should == "00:01:06" end "should display 4000 seconds 01:06:40" @timer.seconds = 4000 @timer.time_string.should == "01:06:40" end end
but don't understand rspec's return error message, says "timer should initialize 0 seconds", stuck @ beginning code , appreciate can explain what's wrong code below. thanks.
class timer def intialize(seconds) @seconds = seconds end def seconds=(new_seconds = 0) @seconds = new_seconds end def seconds @seconds end end
i think initialize
method should take optional argument:
class timer def initialize(seconds = 0) @seconds = seconds end def seconds=(new_seconds) @seconds = new_seconds end end
Comments
Post a Comment