Skip to content

Commit 3a5151f

Browse files
author
babelberry
committed
Created plane, working on airport
0 parents  commit 3a5151f

File tree

5 files changed

+88
-0
lines changed

5 files changed

+88
-0
lines changed

lib/airport.rb

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
class Airport
2+
3+
def initialize
4+
@in_airport ||= []
5+
end
6+
7+
def dock(plane)
8+
@in_airport << plane
9+
end
10+
11+
def filled_spaces
12+
@in_airport.count
13+
end
14+
15+
def release(plane)
16+
@in_airport.pop
17+
self
18+
end
19+
20+
end

lib/plane.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
class Plane
2+
def initialize
3+
@grounded = true
4+
end
5+
6+
def grounded?
7+
@grounded
8+
end
9+
10+
def take_off
11+
@grounded = false
12+
end
13+
14+
def land
15+
@grounded = true
16+
end
17+
end

lor

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.....
2+
3+
Finished in 0.00203 seconds (files took 0.09163 seconds to load)
4+
5 examples, 0 failures

spec/airport_spec.rb

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
require 'airport'
2+
3+
4+
describe Airport do
5+
6+
let(:airport) { Airport.new }
7+
let(:plane) { double = 'plane' }
8+
9+
10+
context 'take off and landing' do
11+
it 'can have a plane land in it' do
12+
airport.dock(plane)
13+
expect(airport.filled_spaces).to eq 1
14+
end
15+
16+
it 'can have a plane take off from it' do
17+
airport.dock(plane)
18+
airport.release(plane)
19+
expect(airport.filled_spaces).to eq 0
20+
end
21+
22+
23+
end
24+
25+
end

spec/planes_spec.rb

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
require 'plane'
2+
3+
describe Plane do
4+
5+
let(:plane) {Plane.new}
6+
7+
it "is grounded when created" do
8+
expect(plane.grounded?).to be true
9+
end
10+
11+
it "can take off" do
12+
plane.take_off
13+
expect(plane.grounded?).to be false
14+
end
15+
16+
it "can land" do
17+
plane.take_off
18+
plane.land
19+
expect(plane.grounded?).to be true
20+
end
21+
22+
end

0 commit comments

Comments
 (0)