From 2a7ec9a2980bd54a47745f63b9952ae897636c09 Mon Sep 17 00:00:00 2001 From: Baljit Rakhra Date: Sat, 26 Mar 2022 20:35:35 +0000 Subject: [PATCH 01/11] user story to land a plane completed --- lib/airport.rb | 16 ++++++++++++++++ lib/plane.rb | 2 ++ spec/airport_spec.rb | 29 +++++++++++++++++++++++++++++ spec/plane_spec.rb | 4 ++++ 4 files changed, 51 insertions(+) create mode 100644 lib/airport.rb create mode 100644 lib/plane.rb create mode 100644 spec/airport_spec.rb create mode 100644 spec/plane_spec.rb diff --git a/lib/airport.rb b/lib/airport.rb new file mode 100644 index 0000000000..e63b832e0d --- /dev/null +++ b/lib/airport.rb @@ -0,0 +1,16 @@ +class Airport + attr_reader :plane + + def initialize + @plane = [] + end + + def land(plane) + @plane << plane + end + + def takeoff + @plane.pop + end + +end diff --git a/lib/plane.rb b/lib/plane.rb new file mode 100644 index 0000000000..fa2a84f30c --- /dev/null +++ b/lib/plane.rb @@ -0,0 +1,2 @@ +class Plane +end diff --git a/spec/airport_spec.rb b/spec/airport_spec.rb new file mode 100644 index 0000000000..3988aa01d2 --- /dev/null +++ b/spec/airport_spec.rb @@ -0,0 +1,29 @@ +require 'airport' + +describe Airport do + it { is_expected.to respond_to(:land).with(1).argument } + + describe '#lands' do + + it 'the planes' do + plane = Plane.new + expect(subject.land(plane)).to eq(subject.plane) + end + end + + describe '#take-offs' do + + it 'lets planes to take - off' do + plane = Plane.new + subject.land(plane) + expect(subject.takeoff).to be_truthy + end + + it 'checks if the planes has taken - off' do + plane = Plane.new + subject.land(plane) + subject.takeoff + expect(plane.has_taken_off?).to be true + end + end +end diff --git a/spec/plane_spec.rb b/spec/plane_spec.rb new file mode 100644 index 0000000000..22792b7957 --- /dev/null +++ b/spec/plane_spec.rb @@ -0,0 +1,4 @@ +require 'plane' + +describe Plane do +end From 30800cd27db022dd4f0c0555357c10fa3b793809 Mon Sep 17 00:00:00 2001 From: Baljit Rakhra Date: Sat, 26 Mar 2022 20:49:52 +0000 Subject: [PATCH 02/11] user story regarding ATC to be able to instruct plane to take off and confirm completed --- lib/airport.rb | 6 ++++-- lib/plane.rb | 4 ++++ spec/airport_spec.rb | 10 +++++----- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/lib/airport.rb b/lib/airport.rb index e63b832e0d..cc716b00d9 100644 --- a/lib/airport.rb +++ b/lib/airport.rb @@ -1,6 +1,6 @@ class Airport attr_reader :plane - + def initialize @plane = [] end @@ -10,7 +10,9 @@ def land(plane) end def takeoff + plane_that_took_off = @plane.last @plane.pop + return plane_that_took_off end - + end diff --git a/lib/plane.rb b/lib/plane.rb index fa2a84f30c..ca5834233d 100644 --- a/lib/plane.rb +++ b/lib/plane.rb @@ -1,2 +1,6 @@ class Plane + + def taken_off? + @taken_off = true + end end diff --git a/spec/airport_spec.rb b/spec/airport_spec.rb index 3988aa01d2..c66df617c1 100644 --- a/spec/airport_spec.rb +++ b/spec/airport_spec.rb @@ -20,10 +20,10 @@ end it 'checks if the planes has taken - off' do - plane = Plane.new - subject.land(plane) - subject.takeoff - expect(plane.has_taken_off?).to be true - end + plane = Plane.new + subject.land(plane) + subject.takeoff + expect(plane.taken_off?).to be true + end end end From c88c4217d358e289bc4b3ce51b499f076d6118f4 Mon Sep 17 00:00:00 2001 From: Baljit Rakhra Date: Sat, 26 Mar 2022 21:14:57 +0000 Subject: [PATCH 03/11] user story regarding default capacity for the airport created --- lib/airport.rb | 11 ++++++----- spec/airport_spec.rb | 5 +++-- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/lib/airport.rb b/lib/airport.rb index cc716b00d9..79bfab9ae4 100644 --- a/lib/airport.rb +++ b/lib/airport.rb @@ -1,18 +1,19 @@ class Airport attr_reader :plane + DEFAULT_CAPACITY = 10 - def initialize + def initialize(capacity = DEFAULT_CAPACITY) @plane = [] + @capacity = capacity end def land(plane) @plane << plane end - def takeoff - plane_that_took_off = @plane.last - @plane.pop - return plane_that_took_off + def takeoff(plane) + @plane.delete(plane) + return plane end end diff --git a/spec/airport_spec.rb b/spec/airport_spec.rb index c66df617c1..b6c13863b2 100644 --- a/spec/airport_spec.rb +++ b/spec/airport_spec.rb @@ -15,14 +15,15 @@ it 'lets planes to take - off' do plane = Plane.new + p1 = Plane.new subject.land(plane) - expect(subject.takeoff).to be_truthy + expect(subject.takeoff(plane)).to eq(plane) end it 'checks if the planes has taken - off' do plane = Plane.new subject.land(plane) - subject.takeoff + subject.takeoff(plane) expect(plane.taken_off?).to be true end end From 0ae52038f5f8cb3fc882a2472f20b8239686aa95 Mon Sep 17 00:00:00 2001 From: Baljit Rakhra Date: Sat, 26 Mar 2022 21:49:05 +0000 Subject: [PATCH 04/11] if airport is full then no landing allowed --- lib/airport.rb | 3 ++- spec/airport_spec.rb | 13 +++++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/lib/airport.rb b/lib/airport.rb index 79bfab9ae4..12f6e05dac 100644 --- a/lib/airport.rb +++ b/lib/airport.rb @@ -1,5 +1,5 @@ class Airport - attr_reader :plane + attr_reader :plane, :capacity DEFAULT_CAPACITY = 10 def initialize(capacity = DEFAULT_CAPACITY) @@ -8,6 +8,7 @@ def initialize(capacity = DEFAULT_CAPACITY) end def land(plane) + fail'Airport is full no landing allowed' if @plane.count >= DEFAULT_CAPACITY @plane << plane end diff --git a/spec/airport_spec.rb b/spec/airport_spec.rb index b6c13863b2..be367ede94 100644 --- a/spec/airport_spec.rb +++ b/spec/airport_spec.rb @@ -3,12 +3,21 @@ describe Airport do it { is_expected.to respond_to(:land).with(1).argument } - describe '#lands' do + describe '# landing' do it 'the planes' do plane = Plane.new expect(subject.land(plane)).to eq(subject.plane) end + + it 'has a Default capcity' do + expect(subject.capacity).to eq(Airport::DEFAULT_CAPACITY) + end + + it '--to be prevented when airport is full' do + Airport::DEFAULT_CAPACITY.times { subject.land Plane.new } + expect {subject.land Plane.new }.to raise_error 'Airport is full no landing allowed' + end end describe '#take-offs' do @@ -25,6 +34,6 @@ subject.land(plane) subject.takeoff(plane) expect(plane.taken_off?).to be true - end + end end end From 59133f44ba4c75e09a866c2664d2e2531b38d4bf Mon Sep 17 00:00:00 2001 From: Baljit Rakhra Date: Sun, 27 Mar 2022 12:34:26 +0100 Subject: [PATCH 05/11] user story to prevent takeoff when weather is stormy added --- lib/airport.rb | 25 +++++++++++++++++-------- lib/plane.rb | 4 +--- lib/weather.rb | 13 +++++++++++++ spec/airport_spec.rb | 28 +++++++++++----------------- 4 files changed, 42 insertions(+), 28 deletions(-) create mode 100644 lib/weather.rb diff --git a/lib/airport.rb b/lib/airport.rb index 12f6e05dac..9e540a10c4 100644 --- a/lib/airport.rb +++ b/lib/airport.rb @@ -1,20 +1,29 @@ +require 'weather' +require 'plane' + class Airport - attr_reader :plane, :capacity + attr_reader :planes, :capacity DEFAULT_CAPACITY = 10 - def initialize(capacity = DEFAULT_CAPACITY) - @plane = [] + def initialize(capacity = DEFAULT_CAPACITY, weather: Weather.new) + @planes = [] @capacity = capacity + @weather = weather end def land(plane) - fail'Airport is full no landing allowed' if @plane.count >= DEFAULT_CAPACITY - @plane << plane + fail 'Due to stormy weather no landing allowed' if stormy? + fail 'Airport is full no landing allowed' if @planes.count >= DEFAULT_CAPACITY + @planes << plane end def takeoff(plane) - @plane.delete(plane) - return plane + fail 'Due to stormy weather no landing allowed' if stormy? + @planes.delete(plane) + 'plane has taken off' + end + + def stormy? + @weather.stormy end - end diff --git a/lib/plane.rb b/lib/plane.rb index ca5834233d..6ecfb55ec4 100644 --- a/lib/plane.rb +++ b/lib/plane.rb @@ -1,6 +1,4 @@ class Plane - def taken_off? - @taken_off = true - end + end diff --git a/lib/weather.rb b/lib/weather.rb new file mode 100644 index 0000000000..179d590325 --- /dev/null +++ b/lib/weather.rb @@ -0,0 +1,13 @@ +class Weather + def stormy + random_outlook == :stormy + end + + private + + OUTLOOKS = [:stormy, :fine, :fine, :fine] + + def random_outlook + OUTLOOKS.sample + end +end diff --git a/spec/airport_spec.rb b/spec/airport_spec.rb index be367ede94..e165e84a57 100644 --- a/spec/airport_spec.rb +++ b/spec/airport_spec.rb @@ -1,13 +1,15 @@ require 'airport' describe Airport do + let(:plane) { Plane.new } + let(:airport) { Airport.new } it { is_expected.to respond_to(:land).with(1).argument } + describe '# landing' do it 'the planes' do - plane = Plane.new - expect(subject.land(plane)).to eq(subject.plane) + expect(subject.land(plane)).to eq(subject.planes) end it 'has a Default capcity' do @@ -15,25 +17,17 @@ end it '--to be prevented when airport is full' do - Airport::DEFAULT_CAPACITY.times { subject.land Plane.new } - expect {subject.land Plane.new }.to raise_error 'Airport is full no landing allowed' + Airport::DEFAULT_CAPACITY.times { subject.land Plane.new } + expect { subject.land Plane.new }.to raise_error 'Airport is full no landing allowed' end end describe '#take-offs' do - - it 'lets planes to take - off' do - plane = Plane.new - p1 = Plane.new - subject.land(plane) - expect(subject.takeoff(plane)).to eq(plane) + it { is_expected.to respond_to(:takeoff).with(1).argument } + + it 'is prevented due to stormy weather' do + allow(airport).to receive(:stormy?).and_return true + expect { airport.takeoff plane }.to raise_error "Due to stormy weather no landing allowed" end - - it 'checks if the planes has taken - off' do - plane = Plane.new - subject.land(plane) - subject.takeoff(plane) - expect(plane.taken_off?).to be true - end end end From eb392ae82e7a155961ae3da9ce404b9485ad3653 Mon Sep 17 00:00:00 2001 From: Baljit Rakhra Date: Sun, 27 Mar 2022 12:45:15 +0100 Subject: [PATCH 06/11] user story to stop landing during stomy weather added --- spec/airport_spec.rb | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/spec/airport_spec.rb b/spec/airport_spec.rb index e165e84a57..9219b53462 100644 --- a/spec/airport_spec.rb +++ b/spec/airport_spec.rb @@ -3,22 +3,24 @@ describe Airport do let(:plane) { Plane.new } let(:airport) { Airport.new } + it { is_expected.to respond_to(:land).with(1).argument } - describe '# landing' do - - it 'the planes' do - expect(subject.land(plane)).to eq(subject.planes) - end - + it 'has a Default capcity' do - expect(subject.capacity).to eq(Airport::DEFAULT_CAPACITY) + expect(airport.capacity).to eq(Airport::DEFAULT_CAPACITY) end it '--to be prevented when airport is full' do - Airport::DEFAULT_CAPACITY.times { subject.land Plane.new } - expect { subject.land Plane.new }.to raise_error 'Airport is full no landing allowed' + allow(airport).to receive(:stormy?).and_return false + Airport::DEFAULT_CAPACITY.times { airport.land Plane.new } + expect { airport.land Plane.new }.to raise_error 'Airport is full no landing allowed' + end + + it 'is prevented due to stormy weather' do + allow(airport).to receive(:stormy?).and_return true + expect { airport.land plane }.to raise_error "Due to stormy weather no landing allowed" end end From 457aadfdc3957148201c9f860f5642106ff57af7 Mon Sep 17 00:00:00 2001 From: Baljit Rakhra Date: Sun, 27 Mar 2022 14:27:42 +0100 Subject: [PATCH 07/11] edge cases handeling added --- lib/airport.rb | 4 ++++ lib/plane.rb | 10 ++++++++-- spec/airport_spec.rb | 12 ++++++++++++ 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/lib/airport.rb b/lib/airport.rb index 9e540a10c4..796bb98e3e 100644 --- a/lib/airport.rb +++ b/lib/airport.rb @@ -12,13 +12,17 @@ def initialize(capacity = DEFAULT_CAPACITY, weather: Weather.new) end def land(plane) + fail "Plane is not in the air" if plane.in_flight? fail 'Due to stormy weather no landing allowed' if stormy? fail 'Airport is full no landing allowed' if @planes.count >= DEFAULT_CAPACITY + plane.in_flight = false @planes << plane end def takeoff(plane) fail 'Due to stormy weather no landing allowed' if stormy? + fail 'Plane is not at the airport' unless plane.in_flight? + plane.in_flight = true @planes.delete(plane) 'plane has taken off' end diff --git a/lib/plane.rb b/lib/plane.rb index 6ecfb55ec4..f40a16e13e 100644 --- a/lib/plane.rb +++ b/lib/plane.rb @@ -1,4 +1,10 @@ class Plane - - + attr_accessor :in_flight + def initialize(in_flight = false) + @in_flight = in_flight + end + + def in_flight? + @in_flight + end end diff --git a/spec/airport_spec.rb b/spec/airport_spec.rb index 9219b53462..d1de73a8ee 100644 --- a/spec/airport_spec.rb +++ b/spec/airport_spec.rb @@ -22,6 +22,12 @@ allow(airport).to receive(:stormy?).and_return true expect { airport.land plane }.to raise_error "Due to stormy weather no landing allowed" end + + it 'raise an error when plane is not in the air before landing'do + allow(airport).to receive(:stormy?).and_return false + plane = Plane.new(true) + expect { airport.land plane }.to raise_error "Plane is not in the air" + end end describe '#take-offs' do @@ -31,5 +37,11 @@ allow(airport).to receive(:stormy?).and_return true expect { airport.takeoff plane }.to raise_error "Due to stormy weather no landing allowed" end + + it 'raise an error when plane is not in the airport before taking off'do + allow(airport).to receive(:stormy?).and_return false + plane = Plane.new(false) + expect { airport.takeoff plane }.to raise_error "Plane is not at the airport" + end end end From 7ed1e4db196ea2803943c84338a60f33346f075b Mon Sep 17 00:00:00 2001 From: Baljit Rakhra Date: Mon, 28 Mar 2022 07:36:31 +0100 Subject: [PATCH 08/11] Test coverage increased to 98.80% and rubocop checks completed --- lib/airport.rb | 3 +-- lib/plane.rb | 5 +++-- spec/airport_spec.rb | 23 ++++++++++++++++------- spec/weather_spec.rb | 19 +++++++++++++++++++ 4 files changed, 39 insertions(+), 11 deletions(-) create mode 100644 spec/weather_spec.rb diff --git a/lib/airport.rb b/lib/airport.rb index 796bb98e3e..ef2766092f 100644 --- a/lib/airport.rb +++ b/lib/airport.rb @@ -21,8 +21,7 @@ def land(plane) def takeoff(plane) fail 'Due to stormy weather no landing allowed' if stormy? - fail 'Plane is not at the airport' unless plane.in_flight? - plane.in_flight = true + fail 'Plane is not at the airport' if plane.in_flight? @planes.delete(plane) 'plane has taken off' end diff --git a/lib/plane.rb b/lib/plane.rb index f40a16e13e..edad113829 100644 --- a/lib/plane.rb +++ b/lib/plane.rb @@ -1,7 +1,8 @@ class Plane - attr_accessor :in_flight + attr_accessor :in_flight + def initialize(in_flight = false) - @in_flight = in_flight + @in_flight = in_flight end def in_flight? diff --git a/spec/airport_spec.rb b/spec/airport_spec.rb index d1de73a8ee..08158c8e59 100644 --- a/spec/airport_spec.rb +++ b/spec/airport_spec.rb @@ -3,8 +3,8 @@ describe Airport do let(:plane) { Plane.new } let(:airport) { Airport.new } - - it { is_expected.to respond_to(:land).with(1).argument } + let(:weather) { Weather.new } + describe '# landing' do @@ -23,7 +23,7 @@ expect { airport.land plane }.to raise_error "Due to stormy weather no landing allowed" end - it 'raise an error when plane is not in the air before landing'do + it 'raise an error when plane is not in the air before landing' do allow(airport).to receive(:stormy?).and_return false plane = Plane.new(true) expect { airport.land plane }.to raise_error "Plane is not in the air" @@ -33,15 +33,24 @@ describe '#take-offs' do it { is_expected.to respond_to(:takeoff).with(1).argument } + it 'informs that the plane has taken off' do + allow(airport).to receive(:stormy?).and_return false + airport.planes << plane + expect(airport.takeoff plane).to eq 'plane has taken off' + end + it 'gets weather status' do + allow(airport).to receive(:stormy?).and_return false + expect(weather.stormy).to be_in([true, false]) + end it 'is prevented due to stormy weather' do allow(airport).to receive(:stormy?).and_return true expect { airport.takeoff plane }.to raise_error "Due to stormy weather no landing allowed" end - it 'raise an error when plane is not in the airport before taking off'do - allow(airport).to receive(:stormy?).and_return false - plane = Plane.new(false) - expect { airport.takeoff plane }.to raise_error "Plane is not at the airport" + it 'raise an error when plane is not in the airport before taking off' do + allow(airport).to receive(:stormy?).and_return false + plane.in_flight = true + expect { airport.takeoff plane }.to raise_error "Plane is not at the airport" end end end diff --git a/spec/weather_spec.rb b/spec/weather_spec.rb new file mode 100644 index 0000000000..89d84ac4a4 --- /dev/null +++ b/spec/weather_spec.rb @@ -0,0 +1,19 @@ +require 'weather' + +describe Weather do + let(:weather) { Weather.new } + + it { is_expected.to respond_to(:stormy) } + + describe '#tells the weather condition' do + it "is sunny" do + allow(weather).to receive(:random_outlook).and_return(:fine) + expect(weather.stormy).to eq false + end + + it "is stormy" do + allow(weather).to receive(:random_outlook).and_return(:stormy) + expect(weather.stormy).to eq true + end + end +end From f97282ee8b0380c062925234bcabf907c0f7fcb4 Mon Sep 17 00:00:00 2001 From: Baljit Rakhra Date: Mon, 28 Mar 2022 08:40:29 +0100 Subject: [PATCH 09/11] tested for multiple take-off's and landing's --- spec/airport_spec.rb | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/spec/airport_spec.rb b/spec/airport_spec.rb index 08158c8e59..a4878ad81b 100644 --- a/spec/airport_spec.rb +++ b/spec/airport_spec.rb @@ -14,7 +14,7 @@ it '--to be prevented when airport is full' do allow(airport).to receive(:stormy?).and_return false - Airport::DEFAULT_CAPACITY.times { airport.land Plane.new } + Airport::DEFAULT_CAPACITY.times { airport.land Plane.new } expect { airport.land Plane.new }.to raise_error 'Airport is full no landing allowed' end @@ -28,6 +28,11 @@ plane = Plane.new(true) expect { airport.land plane }.to raise_error "Plane is not in the air" end + it 'lands multiple planes' do # bonus points + allow(airport).to receive(:stormy?).and_return false + 5.times { airport.land Plane.new } + expect { airport.land Plane.new }.not_to raise_error + end end describe '#take-offs' do @@ -40,7 +45,7 @@ end it 'gets weather status' do allow(airport).to receive(:stormy?).and_return false - expect(weather.stormy).to be_in([true, false]) + expect(weather.stormy).to be(true).or be(false) end it 'is prevented due to stormy weather' do allow(airport).to receive(:stormy?).and_return true @@ -52,5 +57,10 @@ plane.in_flight = true expect { airport.takeoff plane }.to raise_error "Plane is not at the airport" end + it 'multiple planes' do # bonus points + allow(airport).to receive(:stormy?).and_return false + 5.times { airport.land Plane.new } + expect { airport.takeoff plane }.not_to raise_error + end end end From 3d225ff27103ca8d47fc63b690178d36a3871b91 Mon Sep 17 00:00:00 2001 From: "Baljit Rakhra (he/him)" <99490100+baljitrakhra@users.noreply.github.com> Date: Mon, 28 Mar 2022 08:48:05 +0100 Subject: [PATCH 10/11] Updated README.md I took inspiration from Jordan Manu's README.md to write my README.md --- README.md | 66 +++++++++++++++++++------------------------------------ 1 file changed, 23 insertions(+), 43 deletions(-) diff --git a/README.md b/README.md index 6dd4fa6bc9..95ed12f124 100644 --- a/README.md +++ b/README.md @@ -12,27 +12,35 @@ Airport Challenge = ===(_________) ``` +# Airport Challenge -Instructions ---------- +This Airport challenge allows users to instruct a plane to land and take off from an airport, but only if the weather is sunny! -* Feel free to use google, your notes, books, etc. but work on your own -* If you refer to the solution of another coach or student, please put a link to that in your README -* If you have a partial solution, **still check in a partial solution** -* You must submit a pull request to this repo with your code by 10am Monday morning +## Getting started -Steps -------- +- First step - Fork this repo and clone it to your local machine +- Second step - Run the command gem install bundler (if you don't have bundler already) +- Third step - When the installation completes, run bundle -1. Fork this repo, and clone to your local machine -2. Run the command `gem install bundler` (if you don't have bundler already) -3. When the installation completes, run `bundle` -4. Complete the following task: -Task ------ +## How to use -We have a request from a client to write the software to control the flow of planes at an airport. The planes can land and take off provided that the weather is sunny. Occasionally it may be stormy, in which case no planes can land or take off. Here are the user stories that we worked out in collaboration with the client: +Now, I know you're excited to get your pilot's hat on, but please read these instructions first, which will walk you through how to test my program. + +- Open your terminal and navigate to the Airport_challenge directory +- Run irb and require './lib/airport.rb' +- You can create plane instances (plane = Plane.new) and airport instances (airport = Airport.new). +- To instruct a plane to take off from an airport you can use the 'takeoff' method (airport.takeoff(plane)) +- To instruct a plane to land you can use the 'land' method (airport.land(plane)) +## Some things to note +- The airport's default capacity is set to 10 planes, so if you would like to change the airports default capacity, you can pass your desired capacity as an integer to the airport instance eg (airport = Airport.new(20)) +- You will only be able to land and take-off planes if the weather is sunny. Luckily, the weather is sunny 75% of the time, and stormy the other 25%. + +## Running tests + +- If you would like to run my unit tests, run rspec in the Airport_challenge directory. + +## User stories ``` As an air traffic controller @@ -59,31 +67,3 @@ As an air traffic controller To ensure safety I want to prevent landing when weather is stormy ``` - -Your task is to test drive the creation of a set of classes/modules to satisfy all the above user stories. You will need to use a random number generator to set the weather (it is normally sunny but on rare occasions it may be stormy). In your tests, you'll need to use a stub to override random weather to ensure consistent test behaviour. - -Your code should defend against [edge cases](http://programmers.stackexchange.com/questions/125587/what-are-the-difference-between-an-edge-case-a-corner-case-a-base-case-and-a-b) such as inconsistent states of the system ensuring that planes can only take off from airports they are in; planes that are already flying cannot take off and/or be in an airport; planes that are landed cannot land again and must be in an airport, etc. - -For overriding random weather behaviour, please read the documentation to learn how to use test doubles: https://www.relishapp.com/rspec/rspec-mocks/docs . There’s an example of using a test double to test a die that’s relevant to testing random weather in the test. - -Please create separate files for every class, module and test suite. - -In code review we'll be hoping to see: - -* All tests passing -* High [Test coverage](https://github.com/makersacademy/course/blob/main/pills/test_coverage.md) (>95% is good) -* The code is elegant: every class has a clear responsibility, methods are short etc. - -Reviewers will potentially be using this [code review rubric](docs/review.md). Referring to this rubric in advance will make the challenge somewhat easier. You should be the judge of how much challenge you want this at this moment. - -**BONUS** - -* Write an RSpec **feature** test that lands and takes off a number of planes - -Note that is a practice 'tech test' of the kinds that employers use to screen developer applicants. More detailed submission requirements/guidelines are in [CONTRIBUTING.md](CONTRIBUTING.md) - -Finally, don’t overcomplicate things. This task isn’t as hard as it may seem at first. - -* **Submit a pull request early.** - -* Finally, please submit a pull request before Monday at 10am with your solution or partial solution. However much or little amount of code you wrote please please please submit a pull request before Monday at 10am. From 2fb8eb90cbdc162d0b975452c97da4dd105a447b Mon Sep 17 00:00:00 2001 From: Baljit Rakhra Date: Mon, 28 Mar 2022 11:06:08 +0100 Subject: [PATCH 11/11] converted require to require_relative plus added status changer for inflight to takeoff method --- lib/airport.rb | 5 +++-- spec/airport_spec.rb | 2 +- spec/plane_spec.rb | 2 +- spec/weather_spec.rb | 2 +- 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/airport.rb b/lib/airport.rb index ef2766092f..d3d33fdbbe 100644 --- a/lib/airport.rb +++ b/lib/airport.rb @@ -1,5 +1,5 @@ -require 'weather' -require 'plane' +require_relative '../lib/weather.rb' +require_relative '../lib/plane.rb' class Airport attr_reader :planes, :capacity @@ -22,6 +22,7 @@ def land(plane) def takeoff(plane) fail 'Due to stormy weather no landing allowed' if stormy? fail 'Plane is not at the airport' if plane.in_flight? + plane.in_flight = true @planes.delete(plane) 'plane has taken off' end diff --git a/spec/airport_spec.rb b/spec/airport_spec.rb index a4878ad81b..9cd13a9c9a 100644 --- a/spec/airport_spec.rb +++ b/spec/airport_spec.rb @@ -1,4 +1,4 @@ -require 'airport' +require_relative '../lib/airport.rb' describe Airport do let(:plane) { Plane.new } diff --git a/spec/plane_spec.rb b/spec/plane_spec.rb index 22792b7957..f6cf0bf0ac 100644 --- a/spec/plane_spec.rb +++ b/spec/plane_spec.rb @@ -1,4 +1,4 @@ -require 'plane' +require_relative '../lib/plane.rb' describe Plane do end diff --git a/spec/weather_spec.rb b/spec/weather_spec.rb index 89d84ac4a4..e0a521ba5e 100644 --- a/spec/weather_spec.rb +++ b/spec/weather_spec.rb @@ -1,4 +1,4 @@ -require 'weather' +require_relative '../lib/weather.rb' describe Weather do let(:weather) { Weather.new }