diff --git a/.rspec b/.rspec new file mode 100644 index 0000000..5052887 --- /dev/null +++ b/.rspec @@ -0,0 +1 @@ +--color \ No newline at end of file diff --git a/models/automobile.rb b/models/automobile.rb new file mode 100644 index 0000000..ec38f36 --- /dev/null +++ b/models/automobile.rb @@ -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 \ No newline at end of file diff --git a/models/motorcycle.rb b/models/motorcycle.rb new file mode 100644 index 0000000..2c7afad --- /dev/null +++ b/models/motorcycle.rb @@ -0,0 +1,9 @@ +require_relative 'vehicle' + +class Motorcycle < Vehicle + + def self.number_of_wheels + 2 + end + +end \ No newline at end of file diff --git a/models/vehicle.rb b/models/vehicle.rb new file mode 100644 index 0000000..afb440a --- /dev/null +++ b/models/vehicle.rb @@ -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 \ No newline at end of file diff --git a/spec/automobile_spec.rb b/spec/automobile_spec.rb new file mode 100644 index 0000000..7cc08df --- /dev/null +++ b/spec/automobile_spec.rb @@ -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 \ No newline at end of file diff --git a/spec/motorcycle_spec.rb b/spec/motorcycle_spec.rb new file mode 100644 index 0000000..7875832 --- /dev/null +++ b/spec/motorcycle_spec.rb @@ -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 \ No newline at end of file diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb new file mode 100644 index 0000000..4401797 --- /dev/null +++ b/spec/spec_helper.rb @@ -0,0 +1,4 @@ +require 'rspec' +require_relative '../models/automobile' +require_relative '../models/vehicle' +require_relative '../models/motorcycle' \ No newline at end of file diff --git a/spec/vehicle_spec.rb b/spec/vehicle_spec.rb new file mode 100644 index 0000000..aea9d43 --- /dev/null +++ b/spec/vehicle_spec.rb @@ -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 \ No newline at end of file