Commit e28e123

mo khan <mo@mokhan.ca>
2015-11-20 04:06:49
add movie library tests.
1 parent 867b141
lib/movie.rb
@@ -0,0 +1,18 @@
+class Movie
+  def initialize(title:,  studio: Studio::Unknown, year_published: DateTime.now.year)
+  end
+end
+
+class MovieLibrary
+  def add(movie)
+  end
+end
+
+class Studio
+  CastleRock = Object.new
+  Disney = Object.new
+  MiramaxFilms = Object.new
+  Pixar = Object.new
+  RegencyEnterprises = Object.new
+  Unknown = Object.new
+end
spec/movie_library_spec.rb
@@ -0,0 +1,146 @@
+describe MovieLibrary do
+  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: "Pinocchio", 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
+    xit "should increase the total number of movies in the library" do
+      library.add(shawshank_redemption)
+      library.add(chasing_amy)
+      expect(library.total_count).to eql(2)
+    end
+
+    xit "should not allow duplicate movies into the library" do
+      library.add(man_on_fire)
+      library.add(man_on_fire)
+      expect(library.total_count).to eql( 1)
+    end
+
+    xit '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'))
+      expect(library.total_count).to eql( 1)
+    end
+  end
+
+  context 'Searching for movies' do
+    before :each do
+      all_movies.each { |x| library.add(x) }
+    end
+
+    xit 'Can find all pixar movies' do
+      results = library.find_all_movies_by_pixar
+      results.count.should == 4
+      expect(results).to include(toy_story)
+      expect(results).to include(up)
+      expect(results).to include(cars)
+      expect(results).to include(monsters_inc)
+    end
+
+    xit 'Can find all movies published by pixar or disney' do
+      results = library.find_all_movies_by_pixar_or_disney
+      results.count.should == 7
+      expect(results).to include(toy_story)
+      expect(results).to include(up)
+      expect(results).to include(cars)
+      expect(results).to include(monsters_inc)
+      expect(results).to include(fantasia)
+      expect(results).to include(dumbo)
+      expect(results).to include(pinocchio)
+    end
+
+    xit 'Can find all movies not published by pixar' do
+      results = library.find_all_movies_not_published_by_pixar
+      results.length.should == 6
+      expect(results).to include(fantasia)
+      expect(results).to include(dumbo)
+      expect(results).to include(pinocchio)
+      expect(results).to include(shawshank_redemption)
+      expect(results).to include(chasing_amy)
+      expect(results).to include(man_on_fire)
+    end
+
+    xit 'Can find all movies released after 2004' do
+      results = library.find_all_movies_published_after_2004
+      results.length.should == 2
+      expect(results).to include(up)
+      expect(results).to include(cars)
+    end
+
+    xit 'Can find all movies released between 1982 and 2003 - Inclusive' do
+      results = library.find_all_movies_between_1982_and_2003
+      results.length.should == 4
+      expect(results).to include(shawshank_redemption)
+      expect(results).to include(chasing_amy)
+      expect(results).to include(toy_story)
+      expect(results).to include(monsters_inc)
+    end
+  end
+
+  context 'Sorting movies' do
+    before :each do
+      all_movies.each { |x| library.add(x) }
+    end
+
+    xit 'Sorts all movies by descending title' do
+      expected_order = [ cars, chasing_amy, dumbo, fantasia, man_on_fire, monsters_inc, pinocchio, shawshank_redemption, toy_story, up]
+      results = library.sort_movies_by_title_descending
+      expect(results).to eql(expected_order)
+    end
+
+    xit 'Sorts all movies by ascending title' do
+      expected_order = [up, toy_story, shawshank_redemption, pinocchio, monsters_inc, man_on_fire, fantasia, dumbo, chasing_amy, cars]
+      results = library.sort_movies_by_title_ascending
+      expect(results).to eql( expected_order)
+    end
+
+    xit 'Sorts all movies by descending release date' do
+      expected_order = [cars, up, man_on_fire, monsters_inc, chasing_amy, toy_story, shawshank_redemption, dumbo, fantasia, pinocchio ]
+      results = library.sort_movies_by_descending_release_date
+      expect(results).to eql( expected_order )
+    end
+
+    xit 'Sorts all movies by ascending release date' do
+      expected_order = [pinocchio, fantasia, dumbo, shawshank_redemption, toy_story, chasing_amy, monsters_inc, man_on_fire, up, cars]
+      results = library.sort_movies_by_ascending_release_date
+      expect(results).to eql( expected_order )
+    end
+
+    xit 'Sorts all movies by preferred studios and release date ascending' do
+      #rankings: Pixar, Disney, CastleRock, MiramaxFilms, RegenceyEnterprises
+      expected_order = [ toy_story, monsters_inc, up, cars, fantasia, pinocchio, dumbo, shawshank_redemption, chasing_amy, man_on_fire]
+      results = library.sort_movies_by_preferred_studios_and_release_date_ascending
+      expect(results).to eql( expected_order )
+    end
+  end
+
+  context "equality" do
+    xit "should not equal" do
+      blah = create_movie(title: 'blah')
+      huh = create_movie(title: 'huh')
+      expect(blah).to eql( huh )
+    end
+
+    xit "should equal" do
+      huh1 = create_movie(title: 'huh')
+      huh2 = create_movie(title: 'huh')
+      expect(huh1).to eql( huh2 )
+    end
+  end
+end
spec/spec_helper.rb
@@ -1,3 +1,7 @@
+$LOAD_PATH.unshift('lib')
+Dir["lib/*.rb"].each { |file| require File.basename(file) }
+
+
 RSpec.configure do |config|
   config.expect_with :rspec do |expectations|
     expectations.include_chain_clauses_in_custom_matcher_descriptions = true