Commit 6e7ea55
Changed files (3)
lib
lib/studio.rb
@@ -0,0 +1,7 @@
+module Studio
+ CastleRock = Object.new
+ MiramaxFilms = Object.new
+ RegencyEnterprises = Object.new
+ Pixar = Object.new
+ Disney = Object.new
+end
spec/movie_library_spec.rb
@@ -1,12 +1,27 @@
require "spec_helper"
describe MovieLibrary do
- context "when adding a movie to the library" do
- 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") }
+ let(:library) { MovieLibrary.new }
+ let(:shawshank_redemption) { create_movie(title: "The Shawshank Redemption", studio: Studio::CastleRock, year_published: 1994) }
+ let(:chasing_amy) { create_movie(title: "Chasing Amy", studio: Studio::MiramaxFilms, year_published: 1997) }
+ let(:man_on_fire) { create_movie(title: "Man on Fire", studio: Studio::RegencyEnterprises, year_published: 2004) }
+
+ let(:toy_story) { create_movie(title: "Toy Story", studio: Studio::Pixar, year_published: 1995) }
+ let(:up) { create_movie(title: "Up", studio: Studio::Pixar, year_published: 2006) }
+ let(:cars) { create_movie(title: "Cars", studio: Studio::Pixar, year_published: 2009) }
+ let(:monsters_inc) { create_movie(title: "Monsters Inc.", studio: Studio::Pixar, year_published: 2001) }
+
+ let(:fantasia) { create_movie(title: "Fantasia", studio: Studio::Disney, year_published: 1940) }
+ let(:dumbo) { create_movie(title: "Dumbo", studio: Studio::Disney, year_published: 1941) }
+ let(:pinocchio) { create_movie(title: "Pinoccio", studio: Studio::Disney, year_published: 1940) }
+
+ let(:all_movies) { [shawshank_redemption, chasing_amy, man_on_fire, toy_story, up, cars, monsters_inc, fantasia, dumbo, pinocchio] }
+
+ def create_movie(details)
+ Movie.new(details)
+ end
+ context "when adding a movie to the library" do
it "should increase the total number of movies in the library" do
library.add(shawshank_redemption)
library.add(chasing_amy)
@@ -20,23 +35,64 @@ describe MovieLibrary do
end
it 'cannot add two movies that have the same title (logically the same)' do
+ library.add(create_movie(:title => 'Old School'))
+ library.add(create_movie(:title => 'Old School'))
+ library.total_count.should == 1
end
end
context 'Searching for movies' do
+ before :each do
+ all_movies.each { |x| library.add(x) }
+ end
+
it 'Can find all pixar movies' do
+ results = library.find_all_movies_by_pixar
+ results.count.should == 4
+ results.should include(toy_story)
+ results.should include(up)
+ results.should include(cars)
+ results.should include(monsters_inc)
end
it 'Can find all movies published by pixar or disney' do
+ results = library.find_all_movies_by_pixar_or_disney
+ results.count.should == 7
+ results.should include(toy_story)
+ results.should include(up)
+ results.should include(cars)
+ results.should include(monsters_inc)
+ results.should include(fantasia)
+ results.should include(dumbo)
+ results.should include(pinocchio)
end
it 'Can find all movies not published by pixar' do
+ results = library.find_all_movies_not_published_by_pixar
+ results.length.should == 6
+ results.should include(fantasia)
+ results.should include(dumbo)
+ results.should include(pinocchio)
+ results.should include(shawshank_redemption)
+ results.should include(chasing_amy)
+ results.should include(man_on_fire)
end
it 'Can find all movies released after 2004' do
+ results = library.find_all_movies_published_after_2004
+ results.length.should == 2
+ results.should include(up)
+ results.should include(cars)
end
it 'Can find all movies released between 1982 and 2003 - Inclusive' do
+ results = library.find_all_movies_between_1982_and_2003
+ results.length.should == 5
+ results.should include(up)
+ results.should include(shawshank_redemption)
+ results.should include(chasing_amy)
+ results.should include(toy_story)
+ results.should include(monsters_inc)
end
end
spec/spec_helper.rb
@@ -1,4 +1,5 @@
require "rspec"
require "movie_library"
require "movie"
+require "studio"