Skip to content
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
1 change: 1 addition & 0 deletions .rspec
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--color
20 changes: 20 additions & 0 deletions models/automobile.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
require_relative 'Vehicle'

class Automobile < Vehicle

attr_reader :color, :make, :model, :year

def initialize(color, make, model, year)
@color = color
@make = make
@model = model
@year = year
end

def update(args)
@color = args.fetch(:color) if args[:color]
@make = args.fetch(:make) if args[:make]
@model = args.fetch(:model) if args[:model]
@year = args.fetch(:year) if args[:year]
end
end
9 changes: 9 additions & 0 deletions models/motorcycle.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
require_relative 'vehicle'

class Motorcycle < Vehicle

def self.number_of_wheels
2
end

end
17 changes: 17 additions & 0 deletions models/vehicle.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
class Vehicle

@@vehicles_made ||= 0

def self.number_of_wheels
4
end

def self.vehicle_count
@@vehicles_made
end

def initialize
@@vehicles_made += 1
end

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

describe Automobile do

let(:auto) { Automobile.new("Yellow", "Honda", "Accord", "1988")}

it "returns the number of wheels for its class" do
Automobile.number_of_wheels.should eq(4)
end

it "has a color" do
auto.color.should eq("Yellow")
end

it "has a make" do
auto.make.should eq("Honda")
end

it "has a model" do
auto.model.should eq("Accord")
end

it "has a year" do
auto.year.should eq("1988")
end

it "can have one of its attributes updated by hash" do
auto.update(color: "Blue")
auto.color.should eq("Blue")
end

it "can have many of its attributes updated by hash" do
auto.update(color: "Red", year: "1993")
auto.color.should eq("Red")
auto.year.should eq("1993")
end

it "can have all of its attributes updated by hash" do
auto.update(color: "Green", model: "Camry", make: "Toyota", year: "2003")
auto.color.should eq("Green")
auto.make.should eq("Toyota")
auto.model.should eq("Camry")
auto.year.should eq("2003")
end
end
13 changes: 13 additions & 0 deletions spec/motorcycle_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
require 'spec_helper'

describe Motorcycle do

it "does not have 4 tires" do
Motorcycle.number_of_wheels.should_not eq(4)
end

it "has 2 tires" do
Vehicle.number_of_wheels.should eq(4)
Motorcycle.number_of_wheels.should eq(2)
end
end
4 changes: 4 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
require 'rspec'
require_relative '../models/automobile'
require_relative '../models/vehicle'
require_relative '../models/motorcycle'
12 changes: 12 additions & 0 deletions spec/vehicle_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
require 'spec_helper'

describe Vehicle do

it "tracks the creation of one vehicle" do
expect{Motorcycle.new}.to change{Vehicle.vehicle_count}.by(1)
end

# it "tracks the creation of many vehicles" do
# expect{Motorcycle.new, Automobile.new, Motorcycle.new}.to change{Vehicle.vehicle_count}.by(1)
# end
end