I had this code passing ALL the specs the other day, so I moved it into another folder (for completed assignments). When I tried to run the specs again on it from there, I couldn't get the file to load despite typing the path exactly (several times) as I saw it. Hmmmm. Is there some special way to run rspecs from a subfolder?? Anyways, So I moved it back to the main directory it was in, and tried from there, and suddenly it would't pass!! I must have accidentally deleted something. But for the life of me after almost two days...I just DON'T SEE IT. I've gone through it a million times and it seems like it should be working, and when I take the methods out of the class they return as expected. I need fresh eyes. Why is this code suddenly not passing?
class :: Timer
attr_accessor :seconds, :padded, :time_string
def initialize(seconds = 0)
@seconds = seconds
end
def padded(num)
num = num.to_s
num.length == 1 ? "0#{num}" : "#{num}"
end
def time_string=(seconds)
@seconds = seconds
mins = 0
hours = 0
if seconds == 0
return "00:00:00"
elsif seconds < 60
return "00:00:#{padded(seconds)}"
end
while seconds > 59
mins += 1
seconds -= 60
if mins > 59
hours += 1
mins -= 60
end
end#while
return "#{padded(hours)}:#{padded(mins)}:#{padded(seconds)}"
end
end#class
Here are the specs:
require_relative '09_timer'
describe "Timer" do
before(:each) do
@timer = Timer.new
end
it "should initialize to 0 seconds" do
@timer.seconds.should == 0
end
describe 'time_string' do
it "should display 0 seconds as 00:00:00" do
@timer.seconds = 0
@timer.time_string.should == "00:00:00"
end
it "should display 12 seconds as 00:00:12" do
@timer.seconds = 12
@timer.time_string.should == "00:00:12"
end
it "should display 66 seconds as 00:01:06" do
@timer.seconds = 66
@timer.time_string.should == "00:01:06"
end
it "should display 4000 seconds as 01:06:40" do
@timer.seconds = 4000
@timer.time_string.should == "01:06:40"
end
end
# One way to implement the Timer is with a helper method.
# Uncomment these specs if you want to test-drive that
# method, then call that method from inside of time_string.
#
describe 'padded' do
it 'pads zero' do
@timer.padded(0).should == '00'
end
it 'pads one' do
@timer.padded(1).should == '01'
end
it "doesn't pad a two-digit number" do
@timer.padded(12).should == '12'
end
end
end