Commit 7891ba0
Changed files (4)
spec
lesson_three
lib/movie.rb
@@ -0,0 +1,9 @@
+module Movie
+
+ class Movie
+ def initialize(name)
+ @name = name
+ end
+ end
+
+end
\ No newline at end of file
lib/movielibrary.rb
@@ -0,0 +1,25 @@
+module MovieLibrary
+
+ class MovieLibrary
+ def initialize(movies = [])
+ @movies = movies
+ end
+
+ def add(movie)
+ @movies.push(movie) unless include? movie
+ end
+
+ def total_count
+ @movies.size
+ end
+
+ def include?(movie)
+ match = false
+ @movies.each do |m|
+ match = true if m == movie
+ end
+ match
+ end
+
+ end
+end
\ No newline at end of file
spec/lesson_three/movie_library_spec.rb
@@ -1,41 +1,17 @@
require "spec_helper"
+require "movielibrary"
+require "movie"
-class Movie
- def initialize(name)
- @name = name
- end
-end
-
-class MovieLibrary
- def initialize(movies = [])
- @movies = movies
- end
-
- def add(movie)
- @movies.push(movie) unless include? movie
- end
+describe MovieLibrary do
- def total_count
- @movies.size
- end
+ include MovieLibrary
+ include Movie
- def include?(movie)
- match = false
- @movies.each do |m|
- match = true if m == movie
- end
- match
- 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 = 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)
@@ -43,14 +19,12 @@ describe MovieLibrary do
end
it "should not allow duplicate movies into the library" do
- library = MovieLibrary.new
- man_on_fire = Movie.new("Man on Fire")
+ 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
+end
\ No newline at end of file
spec/review01_spec.rb
@@ -64,6 +64,7 @@ describe "review lesseon 1" do
def accept(visitor)
size = @movies.size
+ i = 0
until i > size
movie = @movies[i]
visitor.visit(movie)
@@ -106,7 +107,7 @@ describe "review lesseon 1" do
end
[1, 2, 4].map do |x|
- return x *x
+ puts x * x
end
end