From b0720ae75f513f27f5402cf6545a0282a37565d7 Mon Sep 17 00:00:00 2001 From: Michael Vezzani Date: Tue, 28 Jan 2014 12:43:49 -0500 Subject: [PATCH 1/4] Panda level requirements complete with rspec tests. Added .rspec file to enable color in terminal. --- .rspec | 1 + models/automobile.rb | 22 ++++++++++++++++++++ spec/automobile_spec.rb | 45 +++++++++++++++++++++++++++++++++++++++++ spec/spec_helper.rb | 2 ++ 4 files changed, 70 insertions(+) create mode 100644 .rspec create mode 100644 models/automobile.rb create mode 100644 spec/automobile_spec.rb create mode 100644 spec/spec_helper.rb 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..c988cfc --- /dev/null +++ b/models/automobile.rb @@ -0,0 +1,22 @@ +class Automobile + + attr_reader :color, :make, :model, :year + + def initialize(color, make, model, year) + @color = color + @make = make + @model = model + @year = year + end + + def self.number_of_wheels + 4 + 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/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/spec_helper.rb b/spec/spec_helper.rb new file mode 100644 index 0000000..0fb6f82 --- /dev/null +++ b/spec/spec_helper.rb @@ -0,0 +1,2 @@ +require 'rspec' +require_relative '../models/automobile' \ No newline at end of file From bd7833a9f42253603b1d2cf6136a4e67bc0ec3bf Mon Sep 17 00:00:00 2001 From: Michael Vezzani Date: Tue, 28 Jan 2014 13:25:37 -0500 Subject: [PATCH 2/4] Finish Tiger level requirements, using TDD all along the way. --- models/automobile.rb | 8 +++----- models/motorcycle.rb | 9 +++++++++ models/vehicle.rb | 7 +++++++ spec/motorcycle_spec.rb | 13 +++++++++++++ spec/spec_helper.rb | 4 +++- spec/vehicle_spec.rb | 5 +++++ 6 files changed, 40 insertions(+), 6 deletions(-) create mode 100644 models/motorcycle.rb create mode 100644 models/vehicle.rb create mode 100644 spec/motorcycle_spec.rb create mode 100644 spec/vehicle_spec.rb diff --git a/models/automobile.rb b/models/automobile.rb index c988cfc..ec38f36 100644 --- a/models/automobile.rb +++ b/models/automobile.rb @@ -1,4 +1,6 @@ -class Automobile +require_relative 'Vehicle' + +class Automobile < Vehicle attr_reader :color, :make, :model, :year @@ -9,10 +11,6 @@ def initialize(color, make, model, year) @year = year end - def self.number_of_wheels - 4 - end - def update(args) @color = args.fetch(:color) if args[:color] @make = args.fetch(:make) if args[:make] 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..380f6c7 --- /dev/null +++ b/models/vehicle.rb @@ -0,0 +1,7 @@ +class Vehicle + + def self.number_of_wheels + 4 + 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 index 0fb6f82..4401797 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,2 +1,4 @@ require 'rspec' -require_relative '../models/automobile' \ No newline at end of file +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..bd8be97 --- /dev/null +++ b/spec/vehicle_spec.rb @@ -0,0 +1,5 @@ +require 'spec_helper' + +describe Vehicle do + +end \ No newline at end of file From 7f111f6be7e5beeae4551ef19bc79bc93e15cf12 Mon Sep 17 00:00:00 2001 From: Michael Vezzani Date: Tue, 28 Jan 2014 13:27:45 -0500 Subject: [PATCH 3/4] Fail test for tracking number of vehicles made. Unsure of where to go from here. --- models/vehicle.rb | 6 ++++++ spec/vehicle_spec.rb | 3 +++ 2 files changed, 9 insertions(+) diff --git a/models/vehicle.rb b/models/vehicle.rb index 380f6c7..d633a06 100644 --- a/models/vehicle.rb +++ b/models/vehicle.rb @@ -1,5 +1,11 @@ class Vehicle + @@vehicles_made ||= 0 + + def initialize + @@vehicles_made += 1 + end + def self.number_of_wheels 4 end diff --git a/spec/vehicle_spec.rb b/spec/vehicle_spec.rb index bd8be97..f7510ea 100644 --- a/spec/vehicle_spec.rb +++ b/spec/vehicle_spec.rb @@ -2,4 +2,7 @@ describe Vehicle do + it "tracks the number of vehicles created" do + Motorcycle.new.should change{@@vehicles_made}.by(1) + end end \ No newline at end of file From b148545f0f3446a1e6da6b6e6b610cb4e3d26398 Mon Sep 17 00:00:00 2001 From: Michael Vezzani Date: Tue, 28 Jan 2014 17:40:41 -0500 Subject: [PATCH 4/4] Unsure of how to test for multiple vehicles created. --- models/vehicle.rb | 12 ++++++++---- spec/vehicle_spec.rb | 8 ++++++-- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/models/vehicle.rb b/models/vehicle.rb index d633a06..afb440a 100644 --- a/models/vehicle.rb +++ b/models/vehicle.rb @@ -2,12 +2,16 @@ class Vehicle @@vehicles_made ||= 0 - def initialize - @@vehicles_made += 1 - end - 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/vehicle_spec.rb b/spec/vehicle_spec.rb index f7510ea..aea9d43 100644 --- a/spec/vehicle_spec.rb +++ b/spec/vehicle_spec.rb @@ -2,7 +2,11 @@ describe Vehicle do - it "tracks the number of vehicles created" do - Motorcycle.new.should change{@@vehicles_made}.by(1) + 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