Ships have Itineraries that have Ports ;TLDR
We have to read the user story very carefully here to identify a new object Itinerary
which has ports
. It also appears the functionality of our Ship
's dock
method will change - a ship should now dock at the next port on an Itinerary
instance.
Challenge
Create a new Itinerary
object and refactor existing code to work with the new behaviour introduced by the above user story.
To complete this challenge, you will need to:
- Discuss with your classmates how the domain model now looks.
- Create a new test file, which should
describe
a newItinerary
object. - Create a new test spec to check the new
Itinerary
object can be instantiated. - Write the code that makes this test pass.
- Create a new test spec to check the new
Itinerary
object has aports
property. - Write the code that makes this test pass.
- Refactor the current tests and code for
Ship
so that:-
Ship
has apreviousPort
property set tonull
. - The
setSail
method sets apreviousPort
property on the ship to the current port.
-
- Refactor the
Ship
test suite so aShip
takes anItinerary
object instead of aPort
object. TheItinerary
object will have 2Port
objects stored in an array on itsports
property. - Refactor the
it can dock at a different port
test so that no argument is passed toship.dock
, and asserts thecurrentPort
to be the next port in theItinerary
instance. The tests will break. - Write the code that makes the tests pass again.
- Add, commit with a meaningful message, and push to GitHub.