diff --git a/JavaScriptAirport/spec/FeatureSpec.js b/JavaScriptAirport/spec/FeatureSpec.js index 450c201f14..757d76dc7c 100644 --- a/JavaScriptAirport/spec/FeatureSpec.js +++ b/JavaScriptAirport/spec/FeatureSpec.js @@ -21,7 +21,7 @@ describe('Feature Test', function (){ plane.land(airport); spyOn(airport, 'isStormy').and.returnValue(true); expect(function(){ - plane.takeoff(); + plane.takeoff(airport); }).toThrowError('Takeoff prohibited due to storm conditions'); expect(airport.planes()).toContain(plane); }); diff --git a/JavaScriptAirport/spec/airportSpec.js b/JavaScriptAirport/spec/airportSpec.js index 0fcc6c74ef..7be1a8db1a 100644 --- a/JavaScriptAirport/spec/airportSpec.js +++ b/JavaScriptAirport/spec/airportSpec.js @@ -26,7 +26,7 @@ describe('Airport', function(){ }); it('sets default capacity', function(){ - expect(airport.DEFAULT_CAPACITY).toEqual(20) + expect(airport.capacity).toEqual(airport.DEFAULT_CAPACITY); }); it('raises an error if full', function(){ @@ -43,7 +43,17 @@ describe('Airport', function(){ }).toThrowError("Airport Empty!"); }); }); + it('checks for storm conditions', function(){ expect(airport.isStormy()).toBeFalsy(); }); + + describe('under stormy conditions',function(){ + it('does not clear planes for takeoff when stormy', function(){ + spyOn(airport,'isStormy').and.returnValue(true); + expect(function(){ + airport.clearForTakeoff(plane); + }).toThrowError('Takeoff prohibited due to storm conditions'); + }); + }); }); diff --git a/JavaScriptAirport/src/airport.js b/JavaScriptAirport/src/airport.js index 2c9403e975..5c8b61657c 100644 --- a/JavaScriptAirport/src/airport.js +++ b/JavaScriptAirport/src/airport.js @@ -16,13 +16,17 @@ class Airport{ } this._runway.push(plane); }; + clearForTakeoff(plane){ + if(this.isStormy()){ + throw new Error('Takeoff prohibited due to storm conditions'); + }; if(this._runway.length == 0){ - throw new Error("Airport Empty!"); - } - this._runway.pop(plane); - }; + throw new Error("Airport Empty!"); + }; + this._runway.pop(plane); + } isStormy(){ return false; } diff --git a/README.md b/README.md index eeb7fa875a..b49cc7bd4c 100644 --- a/README.md +++ b/README.md @@ -96,7 +96,7 @@ User story 2 and 3 - User story 2 and 3 complete . I implemented the same method User story 4 - capacity - had already begun this in user story 3 but refactored code and test to include DEFAULT_CAPACITY to get rid of the magic number. -User story 5 - +User story 5 - User story 5 completed. to pass the test, I created a 'isStormy' function that returned false by default and created a guard clause within the 'clearForTakeoff' function that would through the error when isStormy was true. I also refactored my capacity test to have 'capacity' = 'DEFAULT_CAPACITY'.