diff options
| author | Stephen Peasley <stephenpeasley@hotmail.com> | 2013-09-25 19:23:24 -0600 |
|---|---|---|
| committer | Stephen Peasley <stephenpeasley@hotmail.com> | 2013-09-25 19:23:24 -0600 |
| commit | c66bc6a180c864a6012021caef650c2659f49bfc (patch) | |
| tree | 907c719c7416430b4786c9cefb380ca794cb4fc5 | |
| parent | e8a87d03353f5b53b5a6f8d6c31f79ca5856e414 (diff) | |
movie library built and ready to rock and roll
| -rw-r--r-- | readme.md | 2 | ||||
| -rw-r--r-- | spec/lesson_one/popquiz_spec.rb | 38 | ||||
| -rw-r--r-- | spec/lesson_three/lesson_spec.rb | 25 | ||||
| -rw-r--r-- | spec/lesson_three/movie_library_spec.rb | 49 |
4 files changed, 108 insertions, 6 deletions
@@ -12,11 +12,11 @@ * named parameters * symbols * hashes -* object references # lession three * review +* object references * arrays * iterators * enumerable diff --git a/spec/lesson_one/popquiz_spec.rb b/spec/lesson_one/popquiz_spec.rb index 2d039e6..979fe30 100644 --- a/spec/lesson_one/popquiz_spec.rb +++ b/spec/lesson_one/popquiz_spec.rb @@ -3,14 +3,24 @@ require "spec_helper" class CarWash def initialize(name = "Unknown Name", address = "Unknown Address") @name = name - @address = address + @address = address end def description "#{@name} is located at #{@address}" end + def self.wash(car) - @car = car - "Your #{@car} is clean." + @carr = car + @@car = car + "Your #{@@car} is clean." + end + + def self.last_car_washed + @carr + end + + def last_car_scrubbed + CarWash.instance_variable_get("@carr") end end @@ -18,10 +28,11 @@ class Drink attr_reader :name attr_accessor :color attr_accessor :rating + def initialize(name) @name = name - @color = color - @rating = rating + # @color = color() + # @rating = rating() end end @@ -39,6 +50,18 @@ describe 'pop quiz 1' do washed_car = CarWash.wash(car) washed_car.should == "Your #{car} is clean." end + + it "can access a class variable" do + car = "Toyota" + CarWash.wash(car) + CarWash.last_car_washed.should == car + end + + it "should return the last car washed at a specific car wash" do + car = "Jeep" + CarWash.wash(car) + CarWash.new.last_car_scrubbed.should == car + end end context :attr_ do @@ -58,6 +81,11 @@ describe 'pop quiz 1' do drink.rating=5 drink.rating.should == 5 end + + it "should have a default colour" do + drink = Drink.new("tea") + drink.color.should == nil + end end end diff --git a/spec/lesson_three/lesson_spec.rb b/spec/lesson_three/lesson_spec.rb new file mode 100644 index 0000000..131784e --- /dev/null +++ b/spec/lesson_three/lesson_spec.rb @@ -0,0 +1,25 @@ +require 'spec_helper' + +class Kid + attr_accessor :iq + + def initialize(iq) + @iq = iq + end +end + +class School + def educate(who) + who.iq *= 2 + end +end + +describe "object references" do + it "passes by reference" do + kid = Kid.new(50) + school = School.new + + school.educate(kid) + kid.iq.should == 100 + end +end diff --git a/spec/lesson_three/movie_library_spec.rb b/spec/lesson_three/movie_library_spec.rb new file mode 100644 index 0000000..47254e4 --- /dev/null +++ b/spec/lesson_three/movie_library_spec.rb @@ -0,0 +1,49 @@ +require "spec_helper" + +class Movie + def initialize(name) + @name = name + end +end + + +class MovieLibrary + attr_accessor :total_count + def initialize(total_count = 0) + @total_count = total_count + @array_of_movies = [] + end + + def add(movie) + if !@array_of_movies.include? movie + @array_of_movies.push movie + @total_count+=1 + end + end +end + + +describe MovieLibrary do + context "when adding a movie to the library" do + it "should increase the total number of movies in the library" do + library = MovieLibrary.new + shawshank_redemption = Movie.new("The Shawshank Redemption") + chasing_amy = Movie.new("Chasing Amy") + + library.add(shawshank_redemption) + library.add(chasing_amy) + library.total_count.should == 2 + end + + it "should not allow duplicate movies into the library" do + library = MovieLibrary.new + man_on_fire = Movie.new("Man on Fire") + library.add(man_on_fire) + library.add(man_on_fire) + library.total_count.should == 1 + end + end + + + +end
\ No newline at end of file |
