Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
7617310
Panda Assignment submission.
codeblahblah Feb 3, 2014
66d4a23
Corrections to Panda Assignment submission.
codeblahblah Feb 3, 2014
86755ba
Tiger Assignment submission.
codeblahblah Feb 3, 2014
4344aac
Panda and Tiger assignment corrections.
codeblahblah Feb 4, 2014
93e0222
Added update feature to Automobile class.
codeblahblah Feb 4, 2014
4fa755a
Stopped update method from resetting instance variables if set.
codeblahblah Feb 4, 2014
31b8b38
Feature: Allow overwrite on update.
codeblahblah Feb 4, 2014
c5bf5c3
Feature: Fixed typos.
codeblahblah Feb 4, 2014
3a2f800
Eagle level: Create a class variable (@@) in the Vehicle that tracks …
codeblahblah Feb 6, 2014
73bb8b6
Eagle level: Corrected Automobile super method call to take zero argu…
codeblahblah Feb 6, 2014
cb981b9
Eagle level: First attempt at Vehicle search method based on https://…
codeblahblah Feb 6, 2014
4fba59b
Eagle level: Implemented Vehicle search method.
codeblahblah Feb 6, 2014
d7b7038
Eagle level: Added a more dynamic 'register' method.
codeblahblah Feb 6, 2014
8af26ed
Eagle level: Added first RSpec test for Motorcycle class.
codeblahblah Feb 6, 2014
4b8b0bb
Cleaned up registration process and add test case ideas.
codeblahblah Feb 7, 2014
e476509
Feature: Added .build . First Automobile test case now passes.
codeblahblah Feb 7, 2014
4e247f2
Feature: Added Automobile and Motorcycle test specs.
codeblahblah Feb 8, 2014
c7e1d6d
Switched to RSpec's let(:sym) {} syntax and added more tests.
codeblahblah Feb 11, 2014
0ef2e55
Latest Vehicle test specfications including #search test
codeblahblah Feb 11, 2014
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
70 changes: 70 additions & 0 deletions models/eagle.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
class Vehicle

@@vehicles = []
def initialize

end

def self.count
@@vehicles.count
end

def self.search(args)

results = @@vehicles
args.each do |key, value|
results.select!{|vehicle| vehicle.send(key) == value.to_sym}
end
results
end

def self.all_vehicles
@@vehicles
end

def self.wheels
2
end
end


class Automobile < Vehicle
@@auto = []
attr_accessor :color, :make, :model, :year
def self.wheels
4
end

def initialize(args)
@color = args[:color]
@make = args[:make]
@model = args[:model]
@year = args[:year]
super()
end

def self.build(args)
auto = Automobile.new(args)
@@vehicles << auto
@@auto << auto
auto
end

def update(new_args)
@color = new_args[:color] if new_args[:color]
@make = new_args[:make] if new_args[:make]
@model = new_args[:model] if new_args[:model]
@year = new_args[:year] if new_args[:year]
end

def self.all_autos
@@auto
end

def self.count
@@auto.count
end
end

class Motorcycle < Vehicle
end
15 changes: 15 additions & 0 deletions models/panda.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
class Automobile
attr_accessor :color, :make, :model, :year
def self.wheels
4
end

def initialize(args)
@color = args[:color]
@make = args[:make]
@model = args[:model]
@year = args[:year]
end
end

puts Automobile.wheels
40 changes: 40 additions & 0 deletions models/tiger.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
class Vehicle
def self.wheels
2
end
end

class Automobile < Vehicle

attr_accessor :color, :make, :model, :year
def self.wheels
4
end

def initialize(args)
@color = args[:color]
@make = args[:make]
@model = args[:model]
@year = args[:year]
end

def update(new_args)
@color = new_args[:color] if new_args[:color]
@make = new_args[:make] if new_args[:make]
@model = new_args[:model] if new_args[:model]
@year = new_args[:year] if new_args[:year]
end
end

class Motorcycle < Vehicle
end

puts Motorcycle.wheels

auto = Automobile.new(color: 'Red', make: 'Ford', model: 'Mustang', year: 2007)
p auto
auto.update(color: 'Blue', year: 2012)
puts auto.color
puts auto.year
Copy link
Member

Choose a reason for hiding this comment

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

what does purs auto.model output? Is it what you expect?

puts auto.model

115 changes: 115 additions & 0 deletions spec/automobile_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
require 'rspec'
require '../models/eagle'

describe Automobile do
describe '.wheels' do
it 'should return four' do
Automobile.wheels.should eq(4)
end
end

let (:auto) { Automobile.new(model: 'Mustang', color: 'Red', make: 'Ford', year: 2007)}

describe "#new" do
it "takes four parameters and returns a Automobile object" do
auto.should be_an_instance_of Automobile
end

it 'should inherit from vehicle' do
auto.is_a?(Vehicle).should be_true
end
end

describe "#model" do
it 'should have model attribute' do
auto.should respond_to(:model)
end

it "returns the correct model" do
auto.model.should eql 'Mustang'
end
end

describe "#color" do
it 'should have color attribute' do
auto.should respond_to(:color)
end

it "returns the correct color" do
auto.color.should eql 'Red'
end
end

describe "#make" do
it 'should have make attribute' do
auto.should respond_to(:make)
end

it "returns the correct make" do
auto.make.should eql 'Ford'
end
end

describe "#year" do
it 'should have year attribute' do
auto.should respond_to(:year)
end

it "returns the correct year" do
auto.year.should eql 2007
end
end

describe "#update" do
context "with no parameters" do
it "should keep the Automobile unchanged if no parameters are given " do
auto.update({})
auto.model.should eql 'Mustang'
auto.color.should eql 'Red'
auto.make.should eql 'Ford'
auto.year.should eql 2007
end
end

it 'should update the model attribute' do
auto.update(model: 'Calibre')
auto.model.should eql 'Calibre'
end
it 'should update the color attribute' do
auto.update(color: 'Blue')
auto.color.should eql 'Blue'
end
it 'should update the make attribute' do
auto.update(make: 'Dodge')
auto.make.should eql 'Dodge'
end
it 'should update the year attribute' do
auto.update(year: 2009)
auto.year.should eql 2009
end

context "with all parameters" do
it 'should takes four parameters and changes the entire Automobile object' do
auto.update(model: 'Explorer', color: 'Silver', make: 'Ford', year: 1998)
auto.model.should eql 'Explorer'
auto.color.should eql 'Silver'
auto.make.should eql 'Ford'
auto.year.should eql 1998
end
end
end

describe "#build" do
it "records the auto when I build it" do
auto = Automobile.build(model: 'Mustang', color: 'Red', make: 'Ford', year: 2007)
expect(Automobile.all_autos).to include (auto)
expect(Vehicle.all_vehicles).to include (auto)
end

it "should increment the Vehicle count" do
expect{Automobile.build model: :honda, color: :blue, make: 'Civic', year: 2013}.to change{Vehicle.count}.from(1).to(2)
end
end
end


22 changes: 22 additions & 0 deletions spec/motorcycle_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
require 'rspec'
require '../models/eagle'

describe Motorcycle do
let (:bike) {Motorcycle.new}

describe '.wheels' do
it 'should return two' do
Motorcycle.wheels.should eq(2)
end
end

describe "#new" do
it "takes no parameters and returns a Motorcycle object" do
bike.should be_an_instance_of Motorcycle
end

it 'should inherit from vehicle' do
bike.is_a?(Vehicle).should be_true
end
end
end
34 changes: 34 additions & 0 deletions spec/scenarios.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#Vehicle scenarios
Vehicle.wheels
8.times { Vehicle.new } and Vehicle.count == 8
Vehicle.search(color: "blue", model: "honda").inspect


#Automobilce scenarios
Automobile.is_a?(Automobile)
Automobile.wheels == 4
auto = Automobile.new(model: 'Mustang', color: 'Red', make: 'Ford', year: 2007)
auto.color == 'Red'
auto.update(color: 'Blue', year: 2012)
auto.color == 'Blue'
auto.make = 'Ford'
auto.year == 2012

Automobile.new model: :mazda, color: :red, make: 'Civic', year: 2012
Automobile.new model: :toyota, color: :red, make: 'Corolla', year: 2010
Automobile.new model: :honda, color: :blue, make: 'Civic', year: 2013
Automobile.new model: :mazda, color: :blue, make: 'Accord', year: 2003
Vehicle.count == 5 #=> after all the above tests have run

Automobile.count #=> 0
Automobile.build(model: 'Mustang', color: 'Red', make: 'Ford', year: 2007)
Automobile.count #=> 1

#Motorcycle
Motorcycle.wheels
4.times { Motorcycle.new } and Vehicle.count == 4
Motorcycle.is_a?(Motorcycle)




35 changes: 35 additions & 0 deletions spec/vehicle_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
require 'rspec'
require '../models/eagle'

describe Vehicle do

let(:vehicle) { Vehicle.new }

describe '.wheels' do
it 'should return two' do
Vehicle.wheels.should eq(2)
end
end

describe "#new" do
it "takes no parameters and returns a Vehicle object" do
vehicle.should be_an_instance_of Vehicle
end
end

describe "#search" do
it "should find an Automobile when it is searched for" do
Automobile.build model: :mazda, color: :red, make: 'Civic', year: 2012
Automobile.build model: :toyota, color: :red, make: 'Corolla', year: 2010
auto = Automobile.build model: :honda, color: :blue, make: 'Civic', year: 2013
Automobile.build model: :mazda, color: :blue, make: 'Accord', year: 2003
Vehicle.search(color: "blue", model: "honda").first.should eq(auto)
Copy link
Member

Choose a reason for hiding this comment

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

This seems like a fine search. It doesn't cover all functionality though.

I might like it if it were the following, where you are more assertive about the results.

Vehicle.search(color: "blue", model: "honda").should eq([auto])

end
end

describe "#count" do
it "should not increment the Vehicle count no matter how many vehicles are created but not built" do
expect{8.times { Vehicle.new }}.to_not change{Vehicle.count}.from(0).to(0)
end
end
end