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
describea newItineraryobject. - Create a new test spec to check the new
Itineraryobject can be instantiated. - Write the code that makes this test pass.
- Create a new test spec to check the new
Itineraryobject has aportsproperty. - Write the code that makes this test pass.
- Refactor the current tests and code for
Shipso that:-
Shiphas apreviousPortproperty set tonull. - The
setSailmethod sets apreviousPortproperty on the ship to the current port.
-
- Refactor the
Shiptest suite so aShiptakes anItineraryobject instead of aPortobject. TheItineraryobject will have 2Portobjects stored in an array on itsportsproperty. - Refactor the
it can dock at a different porttest so that no argument is passed toship.dock, and asserts thecurrentPortto be the next port in theItineraryinstance. The tests will break. - Write the code that makes the tests pass again.
- Add, commit with a meaningful message, and push to GitHub.