Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Didn't fork before, made a clone so submitting challenge in one commit #2518

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions lib/airport.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
class Airport
def initialize
@planes = []
@capacity = 20
@weather = Weather.new
end

def takeoff(plane)
if @weather.stormy?
raise "Sorry, no takeoff when it's stormy"
else
raise "Sorry, this plane is not in the airport" unless @planes.include? plane
@planes.delete(plane)
end
end

def land(plane)
if @weather.stormy?
raise "Sorry, no landing when it's stormy"
else
raise "Sorry this airport is full" unless @planes.length < @capacity
@planes << plane
end
end

attr_accessor :capacity
attr_reader :weather
attr_reader :planes
end
2 changes: 2 additions & 0 deletions lib/plane.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class Plane
end
12 changes: 12 additions & 0 deletions lib/weather.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
class Weather

def initialize
a = rand(4)
a > 3 ? @weather = "sunny" : @weather = "stormy"
end

def stormy?
@weather == "stormy" ? "true" : "false"
end

end
55 changes: 55 additions & 0 deletions spec/airport_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
require 'Airport'
require 'Plane'
require 'Weather'

describe Airport do
it { is_expected.to respond_to(:land).with(1).argument }

it 'plane is no longer in the airport after takeoff' do
allow(subject.weather).to receive(:stormy?).and_return(false)
a = Plane.new
subject.land(a)
subject.takeoff(a)
expect(subject.planes).not_to include a
end

it "plane won't land if airport is full" do
allow(subject.weather).to receive(:stormy?).and_return(false)
subject.capacity.times { subject.land(Plane.new) }
expect { subject.land(Plane.`new) }.to raise_error
end

it "plane won't takeoff if not in airport" do
plane = Plane.new
expect { subject.takeoff(plane) }.to raise_error
end

it "airport will accept changes in capacity and not accept planes over it" do
allow(subject.weather).to receive(:stormy?).and_return(false)
subject.capacity = 30
30.times { subject.land(Plane.new) }
expect { subject.land(Plane.new) }.to raise_error
end

it "airport will accept changes in capacity and will accept plane upto it" do
allow(subject.weather).to receive(:stormy?).and_return(false)
subject.capacity = 30
29.times { subject.land(Plane.new) }
expect { subject.land(Plane.new) }.not_to raise_error
end

it "won't allow takeoff if the weather is stormy" do
weather = Weather.new
allow(weather).to receive(:stormy?).and_return(true)
p = Plane.new
subject.planes << p
expect { subject.takeoff(p) }.to raise_error
end

it "won't allow landing if the weather is stormy" do
weather = Weather.new
allow(weather).to receive(:stormy?).and_return(true)
expect { subject.land(Plane.new) }.to raise_error
end

end
5 changes: 5 additions & 0 deletions spec/weather_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
require 'Weather'

describe Weather do
it { is_expected.to respond_to(:stormy?) }
end