From 0827b3372c74626679325181c1235828d3e03443 Mon Sep 17 00:00:00 2001 From: meltar Date: Mon, 8 Apr 2013 19:10:04 -0400 Subject: [PATCH 1/5] Panda complete with TDD --- Gemfile.lock | 2 ++ models/automobile.rb | 38 ++++++++++++++++++++++++++++++++++++++ spec/automobile_spec.rb | 27 +++++++++++++++++++++++++++ 3 files changed, 67 insertions(+) create mode 100644 models/automobile.rb create mode 100644 spec/automobile_spec.rb diff --git a/Gemfile.lock b/Gemfile.lock index 0facad0..72dbdde 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -18,6 +18,7 @@ GEM i18n (0.6.0) multi_json (1.3.4) pg (0.13.2) + pg (0.13.2-x86-mingw32) rake (0.9.2.2) rspec (2.10.0) rspec-core (~> 2.10.0) @@ -31,6 +32,7 @@ GEM PLATFORMS ruby + x86-mingw32 DEPENDENCIES activerecord diff --git a/models/automobile.rb b/models/automobile.rb new file mode 100644 index 0000000..dbadc08 --- /dev/null +++ b/models/automobile.rb @@ -0,0 +1,38 @@ +class Automobile + + def self.number_of_wheels + @wheels = 4 + end + + attr_reader :color, :make, :model, :year + def initialize (hash={}) + @color = hash.fetch(:color) + @make = hash.fetch(:make) + @model = hash.fetch(:model) + @year = hash.fetch(:year) + end + + def update (hash={}) + @color = hash.fetch(:color) + @make = hash.fetch(:make) + @model = hash.fetch(:model) + @year = hash.fetch(:year) + end + + def color + @color + end + + def make + @make + end + + def model + @model + end + + def year + @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..0027667 --- /dev/null +++ b/spec/automobile_spec.rb @@ -0,0 +1,27 @@ +require "rspec" +require_relative "../models/automobile" + +describe Automobile do + + it "should return the number of wheels" do + Automobile.number_of_wheels.should eq(4) + end + + it "should take input to describe the automobile" do + auto = Automobile.new(color: "red", make: "honda", model: "accord", year: "2002") + auto.color.should eq("red") + auto.make.should eq("honda") + auto.model.should eq("accord") + auto.year.should eq("2002") + end + + it "should allow an update to the automobile" do + auto = Automobile.new(color: "silver", make: "toyota", model: "camry", year: "2012") + auto.update(color: "red", make: "honda", model: "accord", year: "2002") + auto.color.should eq("red") + auto.make.should eq("honda") + auto.model.should eq("accord") + auto.year.should eq("2002") + end + +end \ No newline at end of file From eb3370e169917056b2838ed48bb3430175902032 Mon Sep 17 00:00:00 2001 From: meltar Date: Mon, 8 Apr 2013 20:21:20 -0400 Subject: [PATCH 2/5] Tiger complete with TDD! --- block_review.rb | 8 +++++++- config/database.yml.sample | 6 ------ models/automobile.rb | 8 +++++++- spec/automobile_spec.rb | 2 +- 4 files changed, 15 insertions(+), 9 deletions(-) delete mode 100644 config/database.yml.sample diff --git a/block_review.rb b/block_review.rb index fcdefc7..53767c3 100644 --- a/block_review.rb +++ b/block_review.rb @@ -2,6 +2,12 @@ require 'bundler/setup' require_relative 'db/setup' -Dir.glob("./**/*.rb").each {|f| require f} +Dir.glob("./models/*.rb").each {|f| require f} +auto = Automobile.new(color: "blue", make: "Ford", model: "Explorer", year: "2000") + +puts "Example automobile: #{auto.to_s}" +puts "An automobile has #{Automobile.number_of_wheels} tires." +puts "A motorcycle has #{Motorcycle.number_of_wheels} tires." +puts puts "Serenity now!" diff --git a/config/database.yml.sample b/config/database.yml.sample deleted file mode 100644 index 2e5c2a9..0000000 --- a/config/database.yml.sample +++ /dev/null @@ -1,6 +0,0 @@ -host: 'localhost' -adapter: 'postgresql' -database: 'episode5' -username: XXXXXXX -encoding: 'utf8' -pool: 5 diff --git a/models/automobile.rb b/models/automobile.rb index dbadc08..fcd8ce1 100644 --- a/models/automobile.rb +++ b/models/automobile.rb @@ -1,4 +1,6 @@ -class Automobile +require_relative "Vehicle" + +class Automobile < Vehicle def self.number_of_wheels @wheels = 4 @@ -35,4 +37,8 @@ def year @year end + def to_s + "#{year} #{color} #{make} #{model}" + end + end \ No newline at end of file diff --git a/spec/automobile_spec.rb b/spec/automobile_spec.rb index 0027667..f528dcc 100644 --- a/spec/automobile_spec.rb +++ b/spec/automobile_spec.rb @@ -3,7 +3,7 @@ describe Automobile do - it "should return the number of wheels" do + it "should have four wheels" do Automobile.number_of_wheels.should eq(4) end From 195e7d705d313b858a9e3c4f93ca3d9322006876 Mon Sep 17 00:00:00 2001 From: meltar Date: Mon, 8 Apr 2013 20:21:59 -0400 Subject: [PATCH 3/5] Tiger complete with TDD - and all the files needed --- models/motorcycle.rb | 9 +++++++++ models/vehicle.rb | 7 +++++++ spec/motorcycle_spec.rb | 10 ++++++++++ spec/vehicle_spec.rb | 9 +++++++++ 4 files changed, 35 insertions(+) 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/motorcycle.rb b/models/motorcycle.rb new file mode 100644 index 0000000..7565ddb --- /dev/null +++ b/models/motorcycle.rb @@ -0,0 +1,9 @@ +require_relative "Vehicle" + +class Motorcycle < Vehicle + + def self.number_of_wheels + @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..4216a1a --- /dev/null +++ b/models/vehicle.rb @@ -0,0 +1,7 @@ +class Vehicle + + def self.number_of_wheels + @wheels = nil + 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..cfea09d --- /dev/null +++ b/spec/motorcycle_spec.rb @@ -0,0 +1,10 @@ +require "rspec" +require_relative "../models/motorcycle" + +describe Motorcycle do + + it "should have two wheels" do + Motorcycle.number_of_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..03d621b --- /dev/null +++ b/spec/vehicle_spec.rb @@ -0,0 +1,9 @@ +require "rspec" +require_relative "../models/vehicle" + +describe Vehicle do + + it "should have four wheels" do + Vehicle.number_of_wheels.should eq(nil) + end +end \ No newline at end of file From 09c89856a23273f27652549faa076fb0b9c4da8f Mon Sep 17 00:00:00 2001 From: meltar Date: Mon, 8 Apr 2013 22:30:30 -0400 Subject: [PATCH 4/5] Eagle complete with TDD and some refactoring/improvements --- block_review.rb | 12 ++++++++-- models/automobile.rb | 35 ---------------------------- models/vehicle.rb | 51 +++++++++++++++++++++++++++++++++++++++++ spec/automobile_spec.rb | 17 -------------- spec/vehicle_spec.rb | 43 ++++++++++++++++++++++++++++++++++ 5 files changed, 104 insertions(+), 54 deletions(-) diff --git a/block_review.rb b/block_review.rb index 53767c3..490de22 100644 --- a/block_review.rb +++ b/block_review.rb @@ -4,10 +4,18 @@ require_relative 'db/setup' Dir.glob("./models/*.rb").each {|f| require f} -auto = Automobile.new(color: "blue", make: "Ford", model: "Explorer", year: "2000") +auto1 = Automobile.new(color: "white", make: "Ford", model: "Explorer", year: "2000") +auto2 = Automobile.new(color: "blue", make: "Honda", model: "Accord", year: "2009") +auto3 = Automobile.new(color: "blue", make: "Honda", model: "Accord", year: "2011") -puts "Example automobile: #{auto.to_s}" puts "An automobile has #{Automobile.number_of_wheels} tires." puts "A motorcycle has #{Motorcycle.number_of_wheels} tires." puts +puts "Auto 1: #{auto1.to_s}" +puts "Auto 2: #{auto2.to_s}" +puts "Auto 3: #{auto3.to_s}" +puts +puts "All vehicles: #{Vehicle.Vehicles.inspect}" +puts "All blue Honda Accords: #{Vehicle.get_favorite_combo}" +puts puts "Serenity now!" diff --git a/models/automobile.rb b/models/automobile.rb index fcd8ce1..8176d85 100644 --- a/models/automobile.rb +++ b/models/automobile.rb @@ -6,39 +6,4 @@ def self.number_of_wheels @wheels = 4 end - attr_reader :color, :make, :model, :year - def initialize (hash={}) - @color = hash.fetch(:color) - @make = hash.fetch(:make) - @model = hash.fetch(:model) - @year = hash.fetch(:year) - end - - def update (hash={}) - @color = hash.fetch(:color) - @make = hash.fetch(:make) - @model = hash.fetch(:model) - @year = hash.fetch(:year) - end - - def color - @color - end - - def make - @make - end - - def model - @model - end - - def year - @year - end - - def to_s - "#{year} #{color} #{make} #{model}" - end - end \ No newline at end of file diff --git a/models/vehicle.rb b/models/vehicle.rb index 4216a1a..828832c 100644 --- a/models/vehicle.rb +++ b/models/vehicle.rb @@ -1,7 +1,58 @@ class Vehicle + @@Vehicles = [] + + def self.get_favorite_combo + veh = @@Vehicles.select { |i| i.color == "blue" && + i.make == "Honda" && i.model == "Accord" } + end + + def self.reset + @@Vehicles = [] + end + def self.number_of_wheels @wheels = nil end + def self.Vehicles + @@Vehicles + end + + attr_reader :color, :make, :model, :year + def initialize (hash={}) + @@Vehicles << self + @color = hash.fetch(:color) + @make = hash.fetch(:make) + @model = hash.fetch(:model) + @year = hash.fetch(:year) + end + + def update (hash={}) + @color = hash.fetch(:color) + @make = hash.fetch(:make) + @model = hash.fetch(:model) + @year = hash.fetch(:year) + end + + def color + @color + end + + def make + @make + end + + def model + @model + end + + def year + @year + end + + def to_s + "#{year} #{color} #{make} #{model}" + end + end \ No newline at end of file diff --git a/spec/automobile_spec.rb b/spec/automobile_spec.rb index f528dcc..673c3e0 100644 --- a/spec/automobile_spec.rb +++ b/spec/automobile_spec.rb @@ -7,21 +7,4 @@ Automobile.number_of_wheels.should eq(4) end - it "should take input to describe the automobile" do - auto = Automobile.new(color: "red", make: "honda", model: "accord", year: "2002") - auto.color.should eq("red") - auto.make.should eq("honda") - auto.model.should eq("accord") - auto.year.should eq("2002") - end - - it "should allow an update to the automobile" do - auto = Automobile.new(color: "silver", make: "toyota", model: "camry", year: "2012") - auto.update(color: "red", make: "honda", model: "accord", year: "2002") - auto.color.should eq("red") - auto.make.should eq("honda") - auto.model.should eq("accord") - auto.year.should eq("2002") - end - end \ No newline at end of file diff --git a/spec/vehicle_spec.rb b/spec/vehicle_spec.rb index 03d621b..e7517a1 100644 --- a/spec/vehicle_spec.rb +++ b/spec/vehicle_spec.rb @@ -3,7 +3,50 @@ describe Vehicle do + before(:each) do + Vehicle.reset + end + it "should have four wheels" do Vehicle.number_of_wheels.should eq(nil) end + + it "class should keep track of the vehicles made" do + Vehicle.Vehicles.should_not be(nil) + Vehicle.Vehicles.count.should eq(0) + veh = Vehicle.new(color: "white", make: "Honda", model: "Accord", year: "2002") + Vehicle.Vehicles.count.should eq(1) + end + + + it "should take input to describe the automobile" do + auto = Vehicle.new(color: "black", make: "Honda", model: "Accord", year: "2002") + auto.color.should eq("black") + auto.make.should eq("Honda") + auto.model.should eq("Accord") + auto.year.should eq("2002") + end + + it "should allow an update to the automobile" do + auto = Vehicle.new(color: "silver", make: "Toyota", model: "Camry", year: "2012") + auto.update(color: "red", make: "Honda", model: "Accord", year: "2002") + auto.color.should eq("red") + auto.make.should eq("Honda") + auto.model.should eq("Accord") + auto.year.should eq("2002") + end + + it "should filter the vehicles list to only show blue Honda Accords" do + auto1 = Vehicle.new(color: "blue", make: "Honda", model: "Accord", year: "2002") + auto2 = Vehicle.new(color: "blue", make: "Honda", model: "Accord", year: "2005") + auto3 = Vehicle.new(color: "silver", make: "Toyota", model: "Camry", year: "2012") + results = Vehicle.get_favorite_combo + results.count.should eq(2) + end + + it "should allow the class to be reset" do + auto = Vehicle.new(color: "silver", make: "Toyota", model: "Camry", year: "2012") + Vehicle.reset + Vehicle.Vehicles.count.should eq(0) + end end \ No newline at end of file From b89dc17973e7d20ab96bb3a6f62362bb08631adf Mon Sep 17 00:00:00 2001 From: meltar Date: Sun, 14 Apr 2013 02:18:31 -0400 Subject: [PATCH 5/5] changed Vehicles to vehicles and used the Vehicle attr_reader variables --- block_review.rb | 2 +- models/vehicle.rb | 28 ++++++---------------------- spec/vehicle_spec.rb | 8 ++++---- 3 files changed, 11 insertions(+), 27 deletions(-) diff --git a/block_review.rb b/block_review.rb index 490de22..21f0c67 100644 --- a/block_review.rb +++ b/block_review.rb @@ -15,7 +15,7 @@ puts "Auto 2: #{auto2.to_s}" puts "Auto 3: #{auto3.to_s}" puts -puts "All vehicles: #{Vehicle.Vehicles.inspect}" +puts "All vehicles: #{Vehicle.vehicles.inspect}" puts "All blue Honda Accords: #{Vehicle.get_favorite_combo}" puts puts "Serenity now!" diff --git a/models/vehicle.rb b/models/vehicle.rb index 828832c..744b3d0 100644 --- a/models/vehicle.rb +++ b/models/vehicle.rb @@ -1,27 +1,27 @@ class Vehicle - @@Vehicles = [] + @@vehicles = [] def self.get_favorite_combo - veh = @@Vehicles.select { |i| i.color == "blue" && + veh = @@vehicles.select { |i| i.color == "blue" && i.make == "Honda" && i.model == "Accord" } end def self.reset - @@Vehicles = [] + @@vehicles = [] end def self.number_of_wheels @wheels = nil end - def self.Vehicles - @@Vehicles + def self.vehicles + @@vehicles end attr_reader :color, :make, :model, :year def initialize (hash={}) - @@Vehicles << self + @@vehicles << self @color = hash.fetch(:color) @make = hash.fetch(:make) @model = hash.fetch(:model) @@ -34,22 +34,6 @@ def update (hash={}) @model = hash.fetch(:model) @year = hash.fetch(:year) end - - def color - @color - end - - def make - @make - end - - def model - @model - end - - def year - @year - end def to_s "#{year} #{color} #{make} #{model}" diff --git a/spec/vehicle_spec.rb b/spec/vehicle_spec.rb index e7517a1..4ac2909 100644 --- a/spec/vehicle_spec.rb +++ b/spec/vehicle_spec.rb @@ -12,10 +12,10 @@ end it "class should keep track of the vehicles made" do - Vehicle.Vehicles.should_not be(nil) - Vehicle.Vehicles.count.should eq(0) + Vehicle.vehicles.should_not be(nil) + Vehicle.vehicles.count.should eq(0) veh = Vehicle.new(color: "white", make: "Honda", model: "Accord", year: "2002") - Vehicle.Vehicles.count.should eq(1) + Vehicle.vehicles.count.should eq(1) end @@ -47,6 +47,6 @@ it "should allow the class to be reset" do auto = Vehicle.new(color: "silver", make: "Toyota", model: "Camry", year: "2012") Vehicle.reset - Vehicle.Vehicles.count.should eq(0) + Vehicle.vehicles.count.should eq(0) end end \ No newline at end of file