From e168feffdb87958a8f1847b3907cc32fda99678a Mon Sep 17 00:00:00 2001 From: David Ewan Campbell Date: Sat, 26 Mar 2022 19:17:26 +0000 Subject: [PATCH 1/5] 1st Airport Challenge commit --- .github/pull_request_template.md | 2 +- lib/airport.rb | 3 +++ spec/README.md | 43 ++++++++++++++++++++++++++++++++ spec/airport_spec.rb | 4 +++ 4 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 lib/airport.rb create mode 100644 spec/README.md create mode 100644 spec/airport_spec.rb diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index 4c209dde8f..85fa0e0073 100644 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -1,4 +1,4 @@ -# Your name +# Your name: David Ewan Campbell Please write your full name here to make it easier to find your pull request. diff --git a/lib/airport.rb b/lib/airport.rb new file mode 100644 index 0000000000..74feeec55c --- /dev/null +++ b/lib/airport.rb @@ -0,0 +1,3 @@ +class Airport + +end \ No newline at end of file diff --git a/spec/README.md b/spec/README.md new file mode 100644 index 0000000000..10076a9622 --- /dev/null +++ b/spec/README.md @@ -0,0 +1,43 @@ +David Campbell - March '22 cohort +Makers Course WEEK 2 - Airport Challenge + +- Create a small program to control flow of planes at an airport. +- Every plane has a status to say wether it is in the air or landed at the airport +- This program developed using TDD + +# initialised local git repo +# original airport challenge repo forked in github then cloned from github to local repo + +# ruby updated to 3.0.2 +# gem bundler installed/updated +# checked rspec up-to-date + +user story 1 + # As an air traffic controller + # So I can get passengers to a destination + # I want to instruct a plane to land at an airport + +-1st objective, turn user story into objects & actions + +object => airport(therefore destination) => plane(object)in air, action: tell plane to land + +object => plane => action: landed at airport + +- rspec spec/airport_spec.rb to run tests from airport_challenge folder + +# 1st ran feature tests in irb + +# created airport and plane objects and... +# ran a land_plane method on the airport calling the plane object +- all gave uninitialized constant errors + +# created an airport_spec.rb file in spec folder with a an empty spec with a class description - uninitialized constant fail but has 100 % coverage + +# created an airport.rb file and added an Airport class +# added a require to airport.rb file in the spec file -ran rspec with no fails & 100 % coverage + +# ran a feature test from irb, require'd airport.rb file and could initialize an airport object but not a plane object - return to next unit test + +# ran rubocop and tightened up code accordingly + +- 1st add, commit & push \ No newline at end of file diff --git a/spec/airport_spec.rb b/spec/airport_spec.rb new file mode 100644 index 0000000000..b4acd94033 --- /dev/null +++ b/spec/airport_spec.rb @@ -0,0 +1,4 @@ +require 'airport' + +describe Airport do +end \ No newline at end of file From ecba2035aa41a5b412fd69e485a2c5910c0daa5a Mon Sep 17 00:00:00 2001 From: David Ewan Campbell Date: Sat, 26 Mar 2022 20:36:23 +0000 Subject: [PATCH 2/5] 2nd commit added definition and wrapper example --- lib/airport.rb | 2 ++ lib/plane.rb | 3 +++ spec/README.md | 10 +++++++++- spec/airport_spec.rb | 1 + spec/plane_spec.rb | 4 ++++ 5 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 lib/plane.rb create mode 100644 spec/plane_spec.rb diff --git a/lib/airport.rb b/lib/airport.rb index 74feeec55c..3e17a33b47 100644 --- a/lib/airport.rb +++ b/lib/airport.rb @@ -1,3 +1,5 @@ class Airport + def land_plane + end end \ No newline at end of file diff --git a/lib/plane.rb b/lib/plane.rb new file mode 100644 index 0000000000..2779885934 --- /dev/null +++ b/lib/plane.rb @@ -0,0 +1,3 @@ +class Plane + +end \ No newline at end of file diff --git a/spec/README.md b/spec/README.md index 10076a9622..9e7f6ce0c2 100644 --- a/spec/README.md +++ b/spec/README.md @@ -40,4 +40,12 @@ object => plane => action: landed at airport # ran rubocop and tightened up code accordingly -- 1st add, commit & push \ No newline at end of file +- 1st add, commit & push + +# added it wrapper example to land_plane to airport_spec and ran... no method error. Added land_plane definition to Airport class and ran... passed with one example, no failures & 100 % coverage + +# created plane.rb file and plane_spec.rb file for next stage of process + +# ran rubocop + +- 2nd add and commit \ No newline at end of file diff --git a/spec/airport_spec.rb b/spec/airport_spec.rb index b4acd94033..517eadfa1a 100644 --- a/spec/airport_spec.rb +++ b/spec/airport_spec.rb @@ -1,4 +1,5 @@ require 'airport' describe Airport do + it { is_expected.to respond_to(:land_plane) } end \ No newline at end of file diff --git a/spec/plane_spec.rb b/spec/plane_spec.rb new file mode 100644 index 0000000000..b1adefd422 --- /dev/null +++ b/spec/plane_spec.rb @@ -0,0 +1,4 @@ +require 'plane' + +describe Plane do +end \ No newline at end of file From 28e2a1498127ef9a36cbea91dffae51ffe604159 Mon Sep 17 00:00:00 2001 From: David Ewan Campbell Date: Sun, 27 Mar 2022 22:49:52 +0100 Subject: [PATCH 3/5] 3rd commit take_off method added, plane files removed & README updated --- lib/airport.rb | 7 +++++-- lib/plane.rb | 3 --- spec/README.md | 34 ++++++++-------------------------- spec/airport_spec.rb | 11 +++++++++-- spec/plane_spec.rb | 4 ---- 5 files changed, 22 insertions(+), 37 deletions(-) delete mode 100644 lib/plane.rb delete mode 100644 spec/plane_spec.rb diff --git a/lib/airport.rb b/lib/airport.rb index 3e17a33b47..aa4934b0b4 100644 --- a/lib/airport.rb +++ b/lib/airport.rb @@ -1,5 +1,8 @@ class Airport - def land_plane + def land_plane(plane) end -end \ No newline at end of file + + def plane_take_off(plane) + end +end diff --git a/lib/plane.rb b/lib/plane.rb deleted file mode 100644 index 2779885934..0000000000 --- a/lib/plane.rb +++ /dev/null @@ -1,3 +0,0 @@ -class Plane - -end \ No newline at end of file diff --git a/spec/README.md b/spec/README.md index 9e7f6ce0c2..b22eef0510 100644 --- a/spec/README.md +++ b/spec/README.md @@ -1,5 +1,5 @@ David Campbell - March '22 cohort -Makers Course WEEK 2 - Airport Challenge +Makers Course WEEK 2 - AIRPORT CHALLENGE - Create a small program to control flow of planes at an airport. - Every plane has a status to say wether it is in the air or landed at the airport @@ -17,35 +17,17 @@ user story 1 # So I can get passengers to a destination # I want to instruct a plane to land at an airport --1st objective, turn user story into objects & actions +-Objectives, turn user stories into objects & actions -object => airport(therefore destination) => plane(object)in air, action: tell plane to land +object => airport(therefore destination) => plane(object)in air, action: tell plane to land, take off, cannot land when airport full... object => plane => action: landed at airport -- rspec spec/airport_spec.rb to run tests from airport_challenge folder +- rspec spec/airport_spec.rb to run tests from airport_challenge folder +calling Class defined in airport.rb file -# 1st ran feature tests in irb +README revised on third commit to make process taken clearer and concentrated on working with airport spec and airport object/class (deleted created plane class & spec file at this stage as over-complicating process) -# created airport and plane objects and... -# ran a land_plane method on the airport calling the plane object -- all gave uninitialized constant errors +# With each step I ran a feature test first in irb then an rspec unit test, making sure they failed first and read result of each failed test. I created wrapper examples in my airport_spec then created each definition in my Airport class accordingly, making sure each step was failing then passing and ensuring 100 % coverage -# created an airport_spec.rb file in spec folder with a an empty spec with a class description - uninitialized constant fail but has 100 % coverage - -# created an airport.rb file and added an Airport class -# added a require to airport.rb file in the spec file -ran rspec with no fails & 100 % coverage - -# ran a feature test from irb, require'd airport.rb file and could initialize an airport object but not a plane object - return to next unit test - -# ran rubocop and tightened up code accordingly - -- 1st add, commit & push - -# added it wrapper example to land_plane to airport_spec and ran... no method error. Added land_plane definition to Airport class and ran... passed with one example, no failures & 100 % coverage - -# created plane.rb file and plane_spec.rb file for next stage of process - -# ran rubocop - -- 2nd add and commit \ No newline at end of file +# then ran rubocop and tightened up code accordingly - no offences detected and added and commited after each method definition added passed unit tests \ No newline at end of file diff --git a/spec/airport_spec.rb b/spec/airport_spec.rb index 517eadfa1a..4988a26aa6 100644 --- a/spec/airport_spec.rb +++ b/spec/airport_spec.rb @@ -1,5 +1,12 @@ require 'airport' describe Airport do - it { is_expected.to respond_to(:land_plane) } -end \ No newline at end of file + subject(:airport) { airport = Airport.new } + it 'can instruct plane to land' do + expect(airport).to respond_to(:land_plane) + end + + it 'can instruct plane to take off' do + expect(airport).to respond_to(:plane_take_off) + end +end diff --git a/spec/plane_spec.rb b/spec/plane_spec.rb deleted file mode 100644 index b1adefd422..0000000000 --- a/spec/plane_spec.rb +++ /dev/null @@ -1,4 +0,0 @@ -require 'plane' - -describe Plane do -end \ No newline at end of file From 00dd4c20e8274c1357c49499067eae92181d557b Mon Sep 17 00:00:00 2001 From: David Ewan Campbell Date: Sun, 27 Mar 2022 23:33:48 +0100 Subject: [PATCH 4/5] 4th commit, airport_capacity added --- ...=> README_David_Campbell_Airport_Challenge.md | 16 ++++++++++++++-- lib/airport.rb | 6 ++++++ spec/airport_spec.rb | 9 ++++++++- 3 files changed, 28 insertions(+), 3 deletions(-) rename spec/README.md => README_David_Campbell_Airport_Challenge.md (71%) diff --git a/spec/README.md b/README_David_Campbell_Airport_Challenge.md similarity index 71% rename from spec/README.md rename to README_David_Campbell_Airport_Challenge.md index b22eef0510..ebcc2aa5b0 100644 --- a/spec/README.md +++ b/README_David_Campbell_Airport_Challenge.md @@ -12,11 +12,17 @@ Makers Course WEEK 2 - AIRPORT CHALLENGE # gem bundler installed/updated # checked rspec up-to-date -user story 1 +User story 1 - 3 covered # As an air traffic controller # So I can get passengers to a destination # I want to instruct a plane to land at an airport + # So I can get passengers on the way to their destination + # I want to instruct a plane to take off from an airport and confirm that it is no longer in the airport + + # To ensure safety + # I want to prevent landing when the airport is full + -Objectives, turn user stories into objects & actions object => airport(therefore destination) => plane(object)in air, action: tell plane to land, take off, cannot land when airport full... @@ -30,4 +36,10 @@ README revised on third commit to make process taken clearer and concentrated on # With each step I ran a feature test first in irb then an rspec unit test, making sure they failed first and read result of each failed test. I created wrapper examples in my airport_spec then created each definition in my Airport class accordingly, making sure each step was failing then passing and ensuring 100 % coverage -# then ran rubocop and tightened up code accordingly - no offences detected and added and commited after each method definition added passed unit tests \ No newline at end of file +# then ran rubocop and tightened up code accordingly - no offences detected and added and commited after each method definition added passed unit tests + +-4th commit before pull request - added airport_capacity to limit number of planes allowed to land in airport +- renamed and moved README file to root folder +- ran rubocop to refactor/tidy code layout(one offence not corrected yet - unused method argument - will correct next session) + +- rspec unit tests 3 examples passing with 100% coverage \ No newline at end of file diff --git a/lib/airport.rb b/lib/airport.rb index aa4934b0b4..b5851bf4e0 100644 --- a/lib/airport.rb +++ b/lib/airport.rb @@ -1,6 +1,12 @@ class Airport + def initialize(airport_capacity) + @airport_capacity = airport_capacity + @number_of_planes = 0 + end def land_plane(plane) + raise 'No space at airport for plane to land' if @number_of_planes == @airport_capacity + @number_of_planes += 1 end def plane_take_off(plane) diff --git a/spec/airport_spec.rb b/spec/airport_spec.rb index 4988a26aa6..c02dbe5e8b 100644 --- a/spec/airport_spec.rb +++ b/spec/airport_spec.rb @@ -1,7 +1,7 @@ require 'airport' describe Airport do - subject(:airport) { airport = Airport.new } + subject(:airport) { airport = Airport.new(10) } it 'can instruct plane to land' do expect(airport).to respond_to(:land_plane) end @@ -9,4 +9,11 @@ it 'can instruct plane to take off' do expect(airport).to respond_to(:plane_take_off) end + + it 'does not allow planes to land when at capacity' do + 10.times do + airport.land_plane(:plane) + end + expect { airport.land_plane(:plane).to raise_error 'No space at airport for plane to land' } + end end From b7fe4f78fa64a99cbff5ab6c147e462f52c1763f Mon Sep 17 00:00:00 2001 From: David Ewan Campbell <95500370+Ramble-Tamble-70@users.noreply.github.com> Date: Sun, 27 Mar 2022 23:40:48 +0100 Subject: [PATCH 5/5] Create pull_request_teamplate.md --- pull_request_teamplate.md | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 pull_request_teamplate.md diff --git a/pull_request_teamplate.md b/pull_request_teamplate.md new file mode 100644 index 0000000000..6202a575f8 --- /dev/null +++ b/pull_request_teamplate.md @@ -0,0 +1,4 @@ +David Campbell Pull request for Makers Academy Airport_Challenge +4th commit with added airport_capacity +one rubocop offence to correct with unused method argument +100 % coverage all tests pass