I'm struggling with using RSpec with conditional statements. What is an example of a spec file for the following lines of code? The drive method is what I am trying to break down into a spec file. I'm not sure how to go about the conditional statements.
class Car
def initialize
@fuel = 10
@distance = 0
end
def drive(miles)
if (@fuel -= miles/20) >= 0
@distance += miles
@fuel -= miles/20
else
@distance += @fuel * 20
@fuel = 0
puts "You're out of gas!"
end
end
def fuel_up
gallons_needed = 10 - @fuel
puts "The amount of gallons needed will cost you $#{3.5 * gallons_needed}"
end
def to_s
puts "I'm a car. I've driven #{@distance} miles and have #{@fuel} gallons of gas left."
end
end
car_a = Car.new
car_b = Car.new
car_a.drive(10)
car_a.to_s
car_b.drive(133)
car_b.to_s
car_b.fuel_up
car_a.fuel_up
car_a.drive(500)
10/20is0. Are you aware of that?