Commit 7ad3e1e

mo khan <mo@mokhan.ca>
2013-10-11 02:46:21
tidy up the movie library spec.
1 parent 0628512
lib/movie.rb
@@ -1,9 +1,5 @@
-module Movie
-  
-  class Movie
-    def initialize(name)
-      @name = name
-    end
+class Movie
+  def initialize(name)
+    @name = name
   end
-  
-end
\ No newline at end of file
+end
lib/movie_library.rb
@@ -1,58 +1,59 @@
 require 'helpers'
 
-  class MovieLibrary  
-    include Helpers
-        
-    def initialize(movies = [])
-      @movies = movies
-    end
+class MovieLibrary
+  include Helpers
 
-    def add(movie)
-      @movies.push(movie) unless include?(movie)
-    end    
+  def initialize(movies = [])
+    @movies = movies
+  end
 
-    def total_count
-      @movies.size
-    end
-    
-    def each
-      # @movies.count.times do |n|
-      #   yield @movies[n]
-      # end
-      
-      # n = 0
-      # loop do
-      #   current = @movies[n]
-      #   puts current
-      #   return unless current
-      #   yield current
-      #   n += 1
-      # end
-      
-      # for x in @movies
-      #   yield x
-      # end
-
-      # i = 0
-      # current = @movies[i]
-      # while current do
-      #   yield current
-      #   current = @movies[i]
-      #   i+=1
-      # end
-      
-      # i = 0
-      #   until i == @movies.count do
-      #     yield @movies[i]
-      #     i +=1
-      #   end
-      #       
-      i =0
-      yield @movies[i]; i+=1 until @movies.count==i
-      #      
-
-      # puts "blah" while true
-      
-      
+  def add(movie)
+    @movies.push(movie) unless include?(movie)
+  end    
+
+  def total_count
+    @movies.size
+  end
+
+  def each
+    # @movies.count.times do |n|
+    #   yield @movies[n]
+    # end
+
+    # n = 0
+    # loop do
+    #   current = @movies[n]
+    #   puts current
+    #   return unless current
+    #   yield current
+    #   n += 1
+    # end
+
+    # for x in @movies
+    #   yield x
+    # end
+
+    # i = 0
+    # current = @movies[i]
+    # while current do
+    #   yield current
+    #   current = @movies[i]
+    #   i+=1
+    # end
+
+    # i = 0
+    #   until i == @movies.count do
+    #     yield @movies[i]
+    #     i +=1
+    #   end
+    #       
+    #i =0
+    #yield @movies[i]; i+=1 until @movies.count==i
+    #      
+
+    # puts "blah" while true
+    @movies.each do |movie|
+      yield movie
     end
-  end
\ No newline at end of file
+  end
+end
spec/movie_library_spec.rb
@@ -1,32 +1,22 @@
 require "spec_helper"
 
 describe MovieLibrary do
-  
-  # include MovieLibrary
-  # include Movie
-  
   context "when adding a movie to the library" do
-    it "should tell me what the load path is" do
-      puts $:
-    end
-    
+    let(:library) { MovieLibrary.new }
+    let(:shawshank_redemption) { Movie.new("The Shawshank Redemption") }
+    let(:chasing_amy) { Movie.new("Chasing Amy") }
+    let(:man_on_fire) { Movie.new("Man on Fire") }
+
     it "should increase the total number of movies in the library" do
-      library = MovieLibrary::MovieLibrary.new
-      shawshank_redemption = Movie::Movie.new("The Shawshank Redemption")
-      chasing_amy = Movie::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::MovieLibrary.new
-      man_on_fire = Movie::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
+end