diff --git a/models/auto.rb b/models/auto.rb new file mode 100644 index 0000000..45d01ed --- /dev/null +++ b/models/auto.rb @@ -0,0 +1,4 @@ +require_relative './vehicle' + +class Auto < Vehicle +end \ No newline at end of file diff --git a/models/moto.rb b/models/moto.rb new file mode 100644 index 0000000..7455fb5 --- /dev/null +++ b/models/moto.rb @@ -0,0 +1,7 @@ +require_relative './vehicle' + +class Moto < Vehicle + def self.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..8f55786 --- /dev/null +++ b/models/vehicle.rb @@ -0,0 +1,14 @@ +class Vehicle + attr_accessor :color, :make, :model, :year + + def initialize(options = {color: nil, make: nil, model: nil, year: nil}) + @color = options.fetch(:color) + @make = options.fetch(:make) + @model = options.fetch(:model) + @year = options.fetch(:year) + end + + def self.wheels + 4 + end +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..3c817fb --- /dev/null +++ b/spec/auto_spec.rb @@ -0,0 +1,37 @@ +require_relative '../models/auto' + +describe Auto do + before(:each) do + @auto = Auto.new + end + + it "should return number of wheels" do + Auto.wheels.should eq(4) + end + + it 'should have color attribute' do + @auto.should respond_to(:color) + end + + it 'should have make attribute' do + @auto.should respond_to(:make) + end + + it 'should have model attribute' do + @auto.should respond_to(:model) + end + + it 'should have year attribute' do + @auto.should respond_to(:year) + end + + it 'should accept a hash of info to update variables' do + auto = Auto.new(options = {:color => 'black', :make => 'Volkswagen', :model => 'Golf', :year => 2012}) + auto.make.should eq('Volkswagen') + end + + it 'should inherit from vehicle' do + @auto.is_a?(Vehicle).should be_true + end + +end \ No newline at end of file diff --git a/spec/moto_spec.rb b/spec/moto_spec.rb new file mode 100644 index 0000000..97096f2 --- /dev/null +++ b/spec/moto_spec.rb @@ -0,0 +1,17 @@ +require_relative '../models/moto' + +describe Moto do + + before(:each) do + @moto = Moto.new + end + + it 'should inherit from Vehicle' do + @moto.is_a?(Vehicle).should be_true + end + + it 'should have 2 tires' do + Moto.wheels.should eq(2) + end + +end \ No newline at end of file diff --git a/spec/vehicle_spec.rb b/spec/vehicle_spec.rb new file mode 100644 index 0000000..10828de --- /dev/null +++ b/spec/vehicle_spec.rb @@ -0,0 +1,4 @@ +require_relative '../models/vehicle' + +describe Vehicle do +end