I'm learning some Ruby at the moment and I decided to re-teach myself some design patterns from online tutorials (http://ift.tt/1JHMRPS). So I have two class files:
Car
require_relative 'Notifier'
require 'observer'
class Car
include Observable
attr_reader :mileage, :service
def initialize(mileage = 0, service = 3000)
@mileage, @service = mileage, service
add_observer(Notifier.new)
end
def log(miles)
@mileage += miles
changed
notify_observers(self, miles)
end
end
And Notifier:
class Notifier
def update(car, miles)
puts "The car has logged #{miles} miles, totalling #{car.mileage} miles traveled."
puts "The car needs to be taken in for a service!" if car.service <= car.mileage
end
end
Here is my test:
require_relative 'car'
require "test/unit"
class CarTest <
Test::Unit::TestCase
def test_simple
assert_equal("The car has logged 100 miles, totaling 2400 miles traveled.", Car.new(2300, 3000).log(100))
end
end
But whenever I run the test I receive this failure message, wondered if anyone knew of why this is happening?
[1/1] CarTest#test_simpleThe car has logged 100 miles, totalling 2400 miles traveled.
= 0.00 s
1) Failure:
test_simple(CarTest) [car_test.rb:8]:
<"The car has logged 100 miles, totaling 2400 miles traveled."> expected but was
<false>.
Aucun commentaire:
Enregistrer un commentaire