From ffd02fbe7a10778bea09ee42e302d162a24699a5 Mon Sep 17 00:00:00 2001 From: Peter Aronoff Date: Fri, 11 May 2012 10:07:34 -0400 Subject: [PATCH 1/9] Delete non-relevant stuff --- config/database.yml.sample | 6 ------ db/seed.rb | 1 - db/setup.rb | 15 --------------- models/.gitkeep | 0 spec/.gitkeep | 0 5 files changed, 22 deletions(-) delete mode 100644 config/database.yml.sample delete mode 100644 db/seed.rb delete mode 100644 db/setup.rb delete mode 100644 models/.gitkeep delete mode 100644 spec/.gitkeep 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/db/seed.rb b/db/seed.rb deleted file mode 100644 index 1abe902..0000000 --- a/db/seed.rb +++ /dev/null @@ -1 +0,0 @@ -# Cleaning Out diff --git a/db/setup.rb b/db/setup.rb deleted file mode 100644 index 0e80690..0000000 --- a/db/setup.rb +++ /dev/null @@ -1,15 +0,0 @@ -require 'pg' -require 'active_record' -require 'yaml' - -connection_details = YAML::load(File.open('config/database.yml')) - -# Setup out connection details -ActiveRecord::Base.establish_connection(connection_details.merge({'database'=> 'postgres', 'schema_search_path'=> 'public'})) -# create the 'tv' database -ActiveRecord::Base.connection.drop_database (connection_details.fetch('database')) rescue nil -ActiveRecord::Base.connection.create_database(connection_details.fetch('database')) rescue nil -# connect to it -ActiveRecord::Base.establish_connection(connection_details) -# Migrate all the things -ActiveRecord::Migrator.migrate("db/migrate/") diff --git a/models/.gitkeep b/models/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/spec/.gitkeep b/spec/.gitkeep deleted file mode 100644 index e69de29..0000000 From 130b982885b7a93af076680126c2740c6a61330c Mon Sep 17 00:00:00 2001 From: Peter Aronoff Date: Fri, 11 May 2012 11:54:10 -0400 Subject: [PATCH 2/9] Change gem dependencies --- Gemfile | 7 +++---- Gemfile.lock | 38 ++++++++------------------------------ 2 files changed, 11 insertions(+), 34 deletions(-) diff --git a/Gemfile b/Gemfile index 5ac1d52..f392214 100644 --- a/Gemfile +++ b/Gemfile @@ -1,7 +1,6 @@ source 'http://rubygems.org' gem 'rake' -gem 'rspec' -gem 'activesupport' -gem 'activerecord' -gem 'pg' +gem 'minitest' +gem 'mynyml-redgreen' +gem 'fivemat' diff --git a/Gemfile.lock b/Gemfile.lock index 0facad0..628131b 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,40 +1,18 @@ GEM remote: http://rubygems.org/ specs: - activemodel (3.2.3) - activesupport (= 3.2.3) - builder (~> 3.0.0) - activerecord (3.2.3) - activemodel (= 3.2.3) - activesupport (= 3.2.3) - arel (~> 3.0.2) - tzinfo (~> 0.3.29) - activesupport (3.2.3) - i18n (~> 0.6) - multi_json (~> 1.0) - arel (3.0.2) - builder (3.0.0) - diff-lcs (1.1.3) - i18n (0.6.0) - multi_json (1.3.4) - pg (0.13.2) + fivemat (1.0.0) + minitest (3.0.0) + mynyml-redgreen (0.7.1) + term-ansicolor (>= 1.0.4) rake (0.9.2.2) - rspec (2.10.0) - rspec-core (~> 2.10.0) - rspec-expectations (~> 2.10.0) - rspec-mocks (~> 2.10.0) - rspec-core (2.10.0) - rspec-expectations (2.10.0) - diff-lcs (~> 1.1.3) - rspec-mocks (2.10.1) - tzinfo (0.3.33) + term-ansicolor (1.0.7) PLATFORMS ruby DEPENDENCIES - activerecord - activesupport - pg + fivemat + minitest + mynyml-redgreen rake - rspec From f33c4e3d90c0bb8d9637182c1a11b693194f4cc1 Mon Sep 17 00:00:00 2001 From: Peter Aronoff Date: Fri, 11 May 2012 11:55:01 -0400 Subject: [PATCH 3/9] Switch to MiniTest::Spec. Test sanity --- rakefile.rb | 16 +++++++--------- test/test_helper.rb | 4 ++++ test/test_sanity.rb | 9 +++++++++ 3 files changed, 20 insertions(+), 9 deletions(-) create mode 100644 test/test_helper.rb create mode 100644 test/test_sanity.rb diff --git a/rakefile.rb b/rakefile.rb index a547a71..0195b18 100644 --- a/rakefile.rb +++ b/rakefile.rb @@ -1,13 +1,11 @@ -require "rubygems" -require "bundler/setup" +require 'bundler/setup' -require 'rspec/core/rake_task' +require 'rake/testtask' -desc 'Default: run specs.' -task :default => :spec +desc 'Default: run tests.' +task :default => :test -desc "Run specs" -RSpec::Core::RakeTask.new do |t| - t.pattern = "**/*_spec.rb" # don't need this, it's default. - # Put spec opts in a file named .rspec in root +desc "Run tests" +Rake::TestTask.new do |t| + t.pattern = 'test/test_*.rb' end diff --git a/test/test_helper.rb b/test/test_helper.rb new file mode 100644 index 0000000..a7711d3 --- /dev/null +++ b/test/test_helper.rb @@ -0,0 +1,4 @@ +gem 'minitest' +require 'minitest/spec' +require 'fivemat/minitest/autorun' +require 'redgreen' diff --git a/test/test_sanity.rb b/test/test_sanity.rb new file mode 100644 index 0000000..6c0b286 --- /dev/null +++ b/test/test_sanity.rb @@ -0,0 +1,9 @@ +describe 'sanity' do + it 'is minimally capable' do + true.must_be :==, true + end + + it 'must know true from false' do + true.wont_be :==, false + end +end From 2c942ed339add58b7beddf2606b7434919952980 Mon Sep 17 00:00:00 2001 From: Peter Aronoff Date: Fri, 11 May 2012 14:37:44 -0400 Subject: [PATCH 4/9] Begin panda assignment --- lib/panda.rb | 22 ++++++++++++++++++++++ test/test_panda.rb | 21 +++++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 lib/panda.rb create mode 100644 test/test_panda.rb diff --git a/lib/panda.rb b/lib/panda.rb new file mode 100644 index 0000000..305a519 --- /dev/null +++ b/lib/panda.rb @@ -0,0 +1,22 @@ +class Automobile + attr_accessor :color, :make, :model, :year + + def self.wheels + 4 + end + + def initialize(features) + defaults = { + :color => 'black', + :make => 'ford', + :model => 'taurus', + :year => '2012' + } + features.merge!(defaults) + + @color = features[:color] + @make = features[:make] + @model = features[:model] + @year = features[:year] + end +end diff --git a/test/test_panda.rb b/test/test_panda.rb new file mode 100644 index 0000000..06d8879 --- /dev/null +++ b/test/test_panda.rb @@ -0,0 +1,21 @@ +require_relative 'test_helper' + +describe "Automobile class" do + it "should exist" do + Automobile.must_be_kind_of Class + end + + it 'should have a class method that returns the number of wheels' do + Automobile.must_respond_to :wheels + Automobile.wheels.must_equal 4 + end + + it 'should have default features when initialized with an empty hash' do + car = Automobile.new({}) + + car.color.must_equal 'black' + car.make.must_equal 'ford' + car.model.must_equal 'taurus' + car.year.must_equal '2012' + end +end From 360311e9bbad281efa0c36d27fe722ced7a733aa Mon Sep 17 00:00:00 2001 From: Peter Aronoff Date: Sat, 12 May 2012 08:18:32 -0400 Subject: [PATCH 5/9] Get requires right --- test/test_helper.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/test/test_helper.rb b/test/test_helper.rb index a7711d3..72985d7 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -2,3 +2,4 @@ require 'minitest/spec' require 'fivemat/minitest/autorun' require 'redgreen' +require_relative '../lib/panda' From 8dc347d021e9ff7a416d59f269f300fe6f0b4a61 Mon Sep 17 00:00:00 2001 From: Peter Aronoff Date: Sat, 12 May 2012 15:15:34 -0400 Subject: [PATCH 6/9] Better file names --- lib/{panda.rb => automobile.rb} | 0 test/{test_panda.rb => test_automobile.rb} | 0 test/test_helper.rb | 2 +- 3 files changed, 1 insertion(+), 1 deletion(-) rename lib/{panda.rb => automobile.rb} (100%) rename test/{test_panda.rb => test_automobile.rb} (100%) diff --git a/lib/panda.rb b/lib/automobile.rb similarity index 100% rename from lib/panda.rb rename to lib/automobile.rb diff --git a/test/test_panda.rb b/test/test_automobile.rb similarity index 100% rename from test/test_panda.rb rename to test/test_automobile.rb diff --git a/test/test_helper.rb b/test/test_helper.rb index 72985d7..a8ef253 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -2,4 +2,4 @@ require 'minitest/spec' require 'fivemat/minitest/autorun' require 'redgreen' -require_relative '../lib/panda' +require_relative '../lib/automobile' From 699d06387dfcb37368882040ab57d9d7da5cfcbb Mon Sep 17 00:00:00 2001 From: Peter Aronoff Date: Sat, 12 May 2012 15:46:39 -0400 Subject: [PATCH 7/9] Panda level done --- lib/automobile.rb | 7 ++++--- test/test_automobile.rb | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 3 deletions(-) diff --git a/lib/automobile.rb b/lib/automobile.rb index 305a519..60a7ec2 100644 --- a/lib/automobile.rb +++ b/lib/automobile.rb @@ -1,18 +1,19 @@ class Automobile - attr_accessor :color, :make, :model, :year + attr_accessor :color + attr_reader :make, :model, :year def self.wheels 4 end - def initialize(features) + def initialize(features = {}) defaults = { :color => 'black', :make => 'ford', :model => 'taurus', :year => '2012' } - features.merge!(defaults) + features = defaults.merge(features) @color = features[:color] @make = features[:make] diff --git a/test/test_automobile.rb b/test/test_automobile.rb index 06d8879..846d2b0 100644 --- a/test/test_automobile.rb +++ b/test/test_automobile.rb @@ -18,4 +18,40 @@ car.model.must_equal 'taurus' car.year.must_equal '2012' end + + it 'should override defaults when given various values' do + white_car = Automobile.new({:color => 'white'}) + mercedes = Automobile.new({:make => 'mercedes'}) + charger = Automobile.new({:model => 'charger'}) + classic = Automobile.new({:year => '1968'}) + + white_car.color.must_equal 'white' + mercedes.make.must_equal 'mercedes' + charger.model.must_equal 'charger' + classic.year.must_equal '1968' + end + + it 'should accept multiple values in any order' do + old_charger = Automobile.new({:year => '1968', :model => 'charger'}) + new_mercedes = Automobile.new({ + :model => 'SE', + :make => 'mercedes', + :color => 'red', + :year => '2010' + }) + + old_charger.model.must_equal 'charger' + old_charger.year.must_equal '1968' + + new_mercedes.color.must_equal 'red' + new_mercedes.year.must_equal '2010' + end + + it 'should be able to change its color' do + car = Automobile.new + car.color.must_equal 'black' + + car.color = 'white' + car.color.must_equal 'white' + end end From 5c883c8565460acdf647dc661e9c797280fe1949 Mon Sep 17 00:00:00 2001 From: Peter Aronoff Date: Sat, 12 May 2012 20:50:12 -0400 Subject: [PATCH 8/9] Tiger assignment done --- lib/ep6.rb | 3 +++ lib/{ => ep6}/automobile.rb | 15 ++++++++++----- lib/ep6/motorcycle.rb | 5 +++++ lib/ep6/vehicle.rb | 5 +++++ test/test_automobile.rb | 22 ++++++++++++++++++++-- test/test_helper.rb | 2 +- test/test_motorcycle.rb | 16 ++++++++++++++++ test/test_vehicle.rb | 12 ++++++++++++ 8 files changed, 72 insertions(+), 8 deletions(-) create mode 100644 lib/ep6.rb rename lib/{ => ep6}/automobile.rb (65%) create mode 100644 lib/ep6/motorcycle.rb create mode 100644 lib/ep6/vehicle.rb create mode 100644 test/test_motorcycle.rb create mode 100644 test/test_vehicle.rb diff --git a/lib/ep6.rb b/lib/ep6.rb new file mode 100644 index 0000000..b385706 --- /dev/null +++ b/lib/ep6.rb @@ -0,0 +1,3 @@ +require_relative 'ep6/vehicle' +require_relative 'ep6/automobile' +require_relative 'ep6/motorcycle' diff --git a/lib/automobile.rb b/lib/ep6/automobile.rb similarity index 65% rename from lib/automobile.rb rename to lib/ep6/automobile.rb index 60a7ec2..8615b3a 100644 --- a/lib/automobile.rb +++ b/lib/ep6/automobile.rb @@ -1,11 +1,7 @@ -class Automobile +class Automobile < Vehicle attr_accessor :color attr_reader :make, :model, :year - def self.wheels - 4 - end - def initialize(features = {}) defaults = { :color => 'black', @@ -20,4 +16,13 @@ def initialize(features = {}) @model = features[:model] @year = features[:year] end + + def ==(other) + if @color == other.color && @make == other.make && + @model == other.model && @year == other.year + return true + else + return false + end + end end diff --git a/lib/ep6/motorcycle.rb b/lib/ep6/motorcycle.rb new file mode 100644 index 0000000..151c76c --- /dev/null +++ b/lib/ep6/motorcycle.rb @@ -0,0 +1,5 @@ +class Motorcycle < Vehicle + def self.wheels + 2 + end +end diff --git a/lib/ep6/vehicle.rb b/lib/ep6/vehicle.rb new file mode 100644 index 0000000..d96df64 --- /dev/null +++ b/lib/ep6/vehicle.rb @@ -0,0 +1,5 @@ +class Vehicle + def self.wheels + 4 + end +end diff --git a/test/test_automobile.rb b/test/test_automobile.rb index 846d2b0..0c7db98 100644 --- a/test/test_automobile.rb +++ b/test/test_automobile.rb @@ -1,10 +1,14 @@ require_relative 'test_helper' -describe "Automobile class" do - it "should exist" do +describe 'Automobile class' do + it 'should exist' do Automobile.must_be_kind_of Class end + it 'should inherit from Vehicle' do + Automobile.superclass.must_equal Vehicle + end + it 'should have a class method that returns the number of wheels' do Automobile.must_respond_to :wheels Automobile.wheels.must_equal 4 @@ -54,4 +58,18 @@ car.color = 'white' car.color.must_equal 'white' end + + it 'should be able to compare two cars' do + chevy = Automobile.new({ + :color => 'red', + :make => 'chevy', + :model => 'impala', + :year => 1972 + }) + ford = Automobile.new + chevy_copy = chevy.dup + + chevy.wont_equal ford + chevy.must_equal chevy_copy + end end diff --git a/test/test_helper.rb b/test/test_helper.rb index a8ef253..38770dd 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -2,4 +2,4 @@ require 'minitest/spec' require 'fivemat/minitest/autorun' require 'redgreen' -require_relative '../lib/automobile' +require_relative '../lib/ep6' diff --git a/test/test_motorcycle.rb b/test/test_motorcycle.rb new file mode 100644 index 0000000..79e463e --- /dev/null +++ b/test/test_motorcycle.rb @@ -0,0 +1,16 @@ +require_relative 'test_helper' + +describe 'Motorcycle class' do + it 'should exist' do + Motorcycle.must_be_kind_of Class + end + + it 'should inherit from Vehicle' do + Motorcycle.superclass.must_equal Vehicle + end + + it 'should have a class method that returns the number of wheels' do + Motorcycle.must_respond_to :wheels + Motorcycle.wheels.must_equal 2 + end +end diff --git a/test/test_vehicle.rb b/test/test_vehicle.rb new file mode 100644 index 0000000..a835777 --- /dev/null +++ b/test/test_vehicle.rb @@ -0,0 +1,12 @@ +require_relative 'test_helper' + +describe 'Vehicle class' do + it 'should exist' do + Vehicle.must_be_kind_of Class + end + + it 'should have a class method that returns the number of wheels' do + Vehicle.must_respond_to :wheels + Vehicle.wheels.must_equal 4 + end +end From 5700ceeb755249203c7ae8e21a507dd9b4d012f6 Mon Sep 17 00:00:00 2001 From: Peter Aronoff Date: Sun, 13 May 2012 20:05:52 -0400 Subject: [PATCH 9/9] Eagle version --- lib/ep6/automobile.rb | 4 ++++ lib/ep6/motorcycle.rb | 6 ++++++ lib/ep6/vehicle.rb | 19 +++++++++++++++++++ test/test_vehicle.rb | 22 ++++++++++++++++++++++ 4 files changed, 51 insertions(+) diff --git a/lib/ep6/automobile.rb b/lib/ep6/automobile.rb index 8615b3a..0e8fe2c 100644 --- a/lib/ep6/automobile.rb +++ b/lib/ep6/automobile.rb @@ -15,6 +15,10 @@ def initialize(features = {}) @make = features[:make] @model = features[:model] @year = features[:year] + + # Now add the new instance to the @all_vehicles array via Vehicle's + # initialize method. + super() end def ==(other) diff --git a/lib/ep6/motorcycle.rb b/lib/ep6/motorcycle.rb index 151c76c..240e86a 100644 --- a/lib/ep6/motorcycle.rb +++ b/lib/ep6/motorcycle.rb @@ -2,4 +2,10 @@ class Motorcycle < Vehicle def self.wheels 2 end + + def initialize + # Add the new instance to the @all_vehicles array via Vehicle's + # initialize method. + super() + end end diff --git a/lib/ep6/vehicle.rb b/lib/ep6/vehicle.rb index d96df64..f3f6a64 100644 --- a/lib/ep6/vehicle.rb +++ b/lib/ep6/vehicle.rb @@ -1,5 +1,24 @@ class Vehicle + extend Enumerable + + @all_vehicles = [] + + # create read/write methods for @all_vehicles + class << self + attr_accessor :all_vehicles + end + + def initialize + Vehicle.all_vehicles.push self + end + def self.wheels 4 end + + def self.each + @all_vehicles.each do |vehicle| + yield vehicle + end + end end diff --git a/test/test_vehicle.rb b/test/test_vehicle.rb index a835777..1055cff 100644 --- a/test/test_vehicle.rb +++ b/test/test_vehicle.rb @@ -9,4 +9,26 @@ Vehicle.must_respond_to :wheels Vehicle.wheels.must_equal 4 end + + describe 'class instance variable and enumerability' do + before do + # I don't think this should be necessary, but it is. Why? + Vehicle.all_vehicles = [] + end + + it 'should store all the vehicles as they are made' do + car = Automobile.new + motorcycle = Motorcycle.new + vehicle = Vehicle.new + + Vehicle.all_vehicles.count.must_equal 3 + end + + it 'should include enumerable methods' do + Vehicle.must_respond_to :each + Vehicle.must_respond_to :select + Vehicle.must_respond_to :map + Vehicle.must_respond_to :partition + end + end end