master
  1describe MovieLibrary do
  2  let(:library) { MovieLibrary.new }
  3  let(:shawshank_redemption) { create_movie(title: "The Shawshank Redemption", studio: Studio::CastleRock, year_published: 1994) }
  4  let(:chasing_amy) { create_movie(title: "Chasing Amy", studio: Studio::MiramaxFilms, year_published: 1997) }
  5  let(:man_on_fire) { create_movie(title: "Man on Fire", studio: Studio::RegencyEnterprises, year_published: 2004) }
  6  let(:toy_story) { create_movie(title: "Toy Story", studio: Studio::Pixar, year_published: 1995) }
  7  let(:up) { create_movie(title: "Up", studio: Studio::Pixar, year_published: 2006) }
  8  let(:cars) { create_movie(title: "Cars", studio: Studio::Pixar, year_published: 2009) }
  9  let(:monsters_inc) { create_movie(title: "Monsters Inc.", studio: Studio::Pixar, year_published: 2001) }
 10  let(:fantasia) { create_movie(title: "Fantasia", studio: Studio::Disney, year_published: 1940) }
 11  let(:dumbo) { create_movie(title: "Dumbo", studio: Studio::Disney, year_published: 1941) }
 12  let(:pinocchio) { create_movie(title: "Pinocchio", studio: Studio::Disney, year_published: 1940) }
 13  let(:all_movies) { [shawshank_redemption, chasing_amy, man_on_fire, toy_story, up, cars, monsters_inc, fantasia, dumbo, pinocchio] }
 14
 15  def create_movie(details)
 16    Movie.new(details)
 17  end
 18
 19  context "when adding a movie to the library" do
 20    xit "increases the total number of movies in the library" do
 21      library.add(shawshank_redemption)
 22      library.add(chasing_amy)
 23      expect(library.total_count).to eql(2)
 24    end
 25
 26    xit "does not allow duplicate movies into the library" do
 27      library.add(man_on_fire)
 28      library.add(man_on_fire)
 29      expect(library.total_count).to eql( 1)
 30    end
 31
 32    xit 'cannot add two movies that have the same title (logically the same)' do
 33      library.add(create_movie(:title => 'Old School'))
 34      library.add(create_movie(:title => 'Old School'))
 35      expect(library.total_count).to eql( 1)
 36    end
 37  end
 38
 39  context 'Searching for movies' do
 40    before :each do
 41      all_movies.each { |x| library.add(x) }
 42    end
 43
 44    xit 'Can find all pixar movies' do
 45      results = library.find_all_movies_by_pixar
 46      expect(results.count).to eql(4)
 47      expect(results).to include(toy_story)
 48      expect(results).to include(up)
 49      expect(results).to include(cars)
 50      expect(results).to include(monsters_inc)
 51    end
 52
 53    xit 'Can find all movies published by pixar or disney' do
 54      results = library.find_all_movies_by_pixar_or_disney
 55      expect(results.count).to eql(7)
 56      expect(results).to include(toy_story)
 57      expect(results).to include(up)
 58      expect(results).to include(cars)
 59      expect(results).to include(monsters_inc)
 60      expect(results).to include(fantasia)
 61      expect(results).to include(dumbo)
 62      expect(results).to include(pinocchio)
 63    end
 64
 65    xit 'Can find all movies not published by pixar' do
 66      results = library.find_all_movies_not_published_by_pixar
 67      expect(results.length).to eql(6)
 68      expect(results).to include(fantasia)
 69      expect(results).to include(dumbo)
 70      expect(results).to include(pinocchio)
 71      expect(results).to include(shawshank_redemption)
 72      expect(results).to include(chasing_amy)
 73      expect(results).to include(man_on_fire)
 74    end
 75
 76    xit 'Can find all movies released after 2004' do
 77      results = library.find_all_movies_published_after_2004
 78      expect(results.length).to eql(2)
 79      expect(results).to include(up)
 80      expect(results).to include(cars)
 81    end
 82
 83    xit 'Can find all movies released between 1982 and 2003 - Inclusive' do
 84      results = library.find_all_movies_between_1982_and_2003
 85      expect(results.length).to eql(4)
 86      expect(results).to include(shawshank_redemption)
 87      expect(results).to include(chasing_amy)
 88      expect(results).to include(toy_story)
 89      expect(results).to include(monsters_inc)
 90    end
 91  end
 92
 93  context 'Sorting movies' do
 94    before :each do
 95      all_movies.each { |x| library.add(x) }
 96    end
 97
 98    xit 'Sorts all movies by descending title' do
 99      expected_order = [ cars, chasing_amy, dumbo, fantasia, man_on_fire, monsters_inc, pinocchio, shawshank_redemption, toy_story, up]
100      results = library.sort_movies_by_title_descending
101      expect(results).to eql(expected_order)
102    end
103
104    xit 'Sorts all movies by ascending title' do
105      expected_order = [up, toy_story, shawshank_redemption, pinocchio, monsters_inc, man_on_fire, fantasia, dumbo, chasing_amy, cars]
106      results = library.sort_movies_by_title_ascending
107      expect(results).to eql( expected_order)
108    end
109
110    xit 'Sorts all movies by descending release date' do
111      expected_order = [cars, up, man_on_fire, monsters_inc, chasing_amy, toy_story, shawshank_redemption, dumbo, fantasia, pinocchio ]
112      results = library.sort_movies_by_descending_release_date
113      expect(results).to eql( expected_order )
114    end
115
116    xit 'Sorts all movies by ascending release date' do
117      expected_order = [pinocchio, fantasia, dumbo, shawshank_redemption, toy_story, chasing_amy, monsters_inc, man_on_fire, up, cars]
118      results = library.sort_movies_by_ascending_release_date
119      expect(results).to eql( expected_order )
120    end
121
122    xit 'Sorts all movies by preferred studios and release date ascending' do
123      #rankings: Pixar, Disney, CastleRock, MiramaxFilms, RegenceyEnterprises
124      expected_order = [ toy_story, monsters_inc, up, cars, fantasia, pinocchio, dumbo, shawshank_redemption, chasing_amy, man_on_fire]
125      results = library.sort_movies_by_preferred_studios_and_release_date_ascending
126      expect(results).to eql( expected_order )
127    end
128  end
129
130  context "equality" do
131    xit "is not equal" do
132      blah = create_movie(title: 'blah')
133      huh = create_movie(title: 'huh')
134      expect(blah).to eql( huh )
135    end
136
137    xit "is equal" do
138      huh1 = create_movie(title: 'huh')
139      huh2 = create_movie(title: 'huh')
140      expect(huh1).to eql( huh2 )
141    end
142  end
143end