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 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/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/ep6/automobile.rb b/lib/ep6/automobile.rb new file mode 100644 index 0000000..0e8fe2c --- /dev/null +++ b/lib/ep6/automobile.rb @@ -0,0 +1,32 @@ +class Automobile < Vehicle + attr_accessor :color + attr_reader :make, :model, :year + + def initialize(features = {}) + defaults = { + :color => 'black', + :make => 'ford', + :model => 'taurus', + :year => '2012' + } + features = defaults.merge(features) + + @color = features[:color] + @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) + 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..240e86a --- /dev/null +++ b/lib/ep6/motorcycle.rb @@ -0,0 +1,11 @@ +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 new file mode 100644 index 0000000..f3f6a64 --- /dev/null +++ b/lib/ep6/vehicle.rb @@ -0,0 +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/models/.gitkeep b/models/.gitkeep deleted file mode 100644 index e69de29..0000000 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/spec/.gitkeep b/spec/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/test/test_automobile.rb b/test/test_automobile.rb new file mode 100644 index 0000000..0c7db98 --- /dev/null +++ b/test/test_automobile.rb @@ -0,0 +1,75 @@ +require_relative 'test_helper' + +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 + 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 + + 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 + + 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 new file mode 100644 index 0000000..38770dd --- /dev/null +++ b/test/test_helper.rb @@ -0,0 +1,5 @@ +gem 'minitest' +require 'minitest/spec' +require 'fivemat/minitest/autorun' +require 'redgreen' +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_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 diff --git a/test/test_vehicle.rb b/test/test_vehicle.rb new file mode 100644 index 0000000..1055cff --- /dev/null +++ b/test/test_vehicle.rb @@ -0,0 +1,34 @@ +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 + + 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