diff --git a/models/auto.rb b/models/auto.rb new file mode 100644 index 0000000..ab8bbfb --- /dev/null +++ b/models/auto.rb @@ -0,0 +1,46 @@ +class Vehicle + attr_accessor :color, :make, :model, :year, :wheel +## +# Initialize new vehicle; if no arguments are provided, default to "None" + def initialize(args) + @color = args[:color] ||= "None" + @make = args[:make] ||= "None" + @model = args[:model] ||= "None" + @year = args[:year] ||= "None" + end +## +# If I want to update the Vehicle, so shall it be + def updater(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).to_s if args[:year] + end +## +# Such wheels, so round +# May have been overzealous +# +# Could have done: +# def number_of_wheels +# 4 +# end +# +# But wanted to mess with arguments +## + def self.number_of_wheels(wheels) + @wheel = wheels + return @wheel + end +end + + +class Automobile < Vehicle + Automobile.number_of_wheels(4) +end + + +## +# Doesn't have a redefined method, but should still give us correct wheels. +class Motorcycle < Vehicle + Motorcycle.number_of_wheels(2) +end \ No newline at end of file diff --git a/spec/auto_spec.rb b/spec/auto_spec.rb new file mode 100644 index 0000000..3990b0e --- /dev/null +++ b/spec/auto_spec.rb @@ -0,0 +1,44 @@ +require './models/auto' +require 'rspec' + +describe Automobile do + + let(:auto) {Automobile.new(color: "Red",make: "Ford",model: "Fiesta",year: "2014")} + +## +# Passing tests + it "should have a color" do + auto.color.should eq("Red") + end + it "should have a make" do + auto.make.should eq("Ford") + end + it "should have a model" do + auto.model.should eq("Fiesta") + end + it "should have a year made" do + auto.year.should eq("2014") + end + it "should be able to update via hash" do + auto.updater(color: "Blue",make: "Chevy", model: "Nova SS", year: "1968") + auto.color.should eq("Blue") + auto.make.should eq("Chevy") + auto.model.should eq("Nova SS") + auto.year.should eq("1968") + end + it "should have 4 the wheels" do + Automobile.number_of_wheels(4).should eq(4) + end + it "should not have 300 wheels" do + Automobile.number_of_wheels(300).should_not eq(4) + end +end + +describe Motorcycle do + it "should have 2 wheels" do + Motorcycle.number_of_wheels(2).should eq(2) + end + it "should not have 4 wheels" do + Motorcycle.number_of_wheels(4).should_not eq(2) + end +end \ No newline at end of file