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
4 changes: 4 additions & 0 deletions models/auto.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
require_relative './vehicle'

class Auto < Vehicle
end
7 changes: 7 additions & 0 deletions models/moto.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require_relative './vehicle'

class Moto < Vehicle
def self.wheels
2
end
end
14 changes: 14 additions & 0 deletions models/vehicle.rb
Original file line number Diff line number Diff line change
@@ -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
37 changes: 37 additions & 0 deletions spec/auto_spec.rb
Original file line number Diff line number Diff line change
@@ -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})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Normally here, you wouldn't bother assigning the hash to "options" just to send in to Auto. You could write it as:

auto = Auto.new({:color => 'black', :make => 'Volkswagen', :model => 'Golf', :year => 2012})

And ruby also allows:

auto = Auto.new(:color => 'black', :make => 'Volkswagen', :model => 'Golf', :year => 2012)

Those will all get munged into a single hash variable. Finally, I really like this syntax better (the 1.9 hash syntax), but this is an aesthetic and team choice:

auto = Auto.new( 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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some RSpec magic here, you could write:

@auto.should be_a(Vehicle)

end

end
17 changes: 17 additions & 0 deletions spec/moto_spec.rb
Original file line number Diff line number Diff line change
@@ -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
4 changes: 4 additions & 0 deletions spec/vehicle_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
require_relative '../models/vehicle'

describe Vehicle do
end