pwd=Dir.pwd Dir.chdir("../../") require "IMDB.rb" Dir.chdir(pwd) require 'test/unit' require "pp" class IMDB def load_page unless @page_html begin File.open("#{@movie_name}.hpr","r"){|x| @page_html = x.read } rescue Exception => e raise "We do not have a test file for #{@movie_name} with the name of #{@movie_name}.hpr @ #{Dir.pwd}" end end doc = Hpricot(@page_html) end end #class Test::Unit::TestCase class IMDBTest < Test::Unit::TestCase def setup @office_space = IMDB.new("office_space") @hpd = IMDB.new("high_plains_drifter") @pi = IMDB.new("PI") end def test_class_title_search #assert(IMDB.title_search("office space")=={"Titles (Exact Matches)"=>["Office Space"], "Titles (Partial Matches)"=>["'Office Space': Out of the Office"], "Popular Titles"=>["Office Space"], "Titles (Approx Matches)"=>["Spice Girls: One Hour of Girl Power"]}) end def test_title assert_equal(@office_space.title.downcase.strip,"office space") assert_equal(@hpd.title.downcase.strip,"high plains drifter") assert_equal(@pi.title.downcase.strip,"pi") end def test_poster_link assert_equal(@pi.poster_link,"http://ia.imdb.com/media/imdb/01/I/39/46/45m.jpg") end def test_actors actors= {"Paul Brinegar"=>"Lutie Naylor", "Geoffrey Lewis"=>"Stacey Bridges, Outlaw", "Marianna Hill"=>"Callie Travers", "John Hillerman"=>"Bootmaker", "Scott Walker"=>"Bill Borders, Outlaw", "Stefan Gierasch"=>"Mayor Jason Hobart", "Mitch Ryan"=>"Dave Drake (as Mitchell Ryan)", "Robert Donner"=>"Preacher", "Clint Eastwood"=>"The Stranger", "Billy Curtis"=>"Mordecai", "Richard Bull"=>"Asa Goodwin", "Ted Hartley"=>"Lewis Belding", "Jack Ging"=>"Morgan Allen", "Verna Bloom"=>"Sarah Belding", "Walter Barnes"=>"Sheriff Sam Shaw"} assert_equal(@hpd.actors,actors) assert_equal(@hpd.cast,actors) end def test_rating rating = "Rated R for language and some disturbing images." assert_equal(@pi.rating,rating) assert_equal(@pi.mpaa,rating) assert_equal(@pi.ratings,rating) end def test_aka assert_equal(@office_space.aka,"Cubiculos de la oficina (USA: Spanish title)") #there is no AKA for high plains dirfter so it should be a blank string assert_equal(@hpd.aka,"") assert_equal(@hpd.also_known_as,"") end def test_aspect assert_equal(@pi.aspect_ratio,"1.66 : 1") assert_equal(@hpd.aspect,"2.35 : 1") end def test_awards assert_equal(@office_space.awards,"2 nominations") assert_equal(@hpd.awards,"") end def test_certs certs ={"UK"=>"15", "Ireland"=>"15", "Chile"=>"TE", "Australia"=>"M", "Argentina"=>"Atp", "Iceland"=>"L", "Sweden"=>"Btl", "Portugal"=>"M/12", "Spain"=>"T", "USA"=>"R", "Finland"=>"S", "France"=>"U", "Peru"=>"PT", "Canada"=>"AA", "Norway"=>"7", "Germany"=>"12", "Netherlands"=>"AL"} assert_equal(@office_space.certification,certs) assert_equal(@office_space.certifications,certs) assert_equal(@office_space.certs,certs) end def test_color assert_equal(@hpd.color,"Color") assert_equal(@pi.color,"Black and White") end def test_company assert_equal(@office_space.company,"Twentieth Century-Fox Film Corporation") end def test_country assert_equal(@hpd.country,"USA") end def test_date assert_equal(@pi.release_date.to_s,"1998-07-10") assert_equal(@office_space.date.to_s,"1999-02-19") assert(@office_space.date.class.to_s=="Date") end def test_directors assert_equal(@pi.director,["Darren Aronofsky"]) assert_equal(@pi.directors,["Darren Aronofsky"]) end def test_genre assert_equal(@pi.genre,["Thriller", "Sci-Fi"]) assert_equal(@pi.genres,["Thriller", "Sci-Fi"]) end def test_keywords assert_equal(@office_space.keywords,["Hypnosis", "Post\240It", "Kung\240Fu", "Cult\240Comedy", "Arson"]) end def test_lang assert_equal(@pi.language,"English") end def test_plots plot = "A gunfighting stranger comes to the small settlement of Lago and is hired to bring the townsfolk together in an attempt to hold off three outlaws who are on their way." plot_key = ["Flashback\240Sequence", "Murder", "Savior", "Small\240Town", "Sheriff"] plot_out = "A gunfighting stranger comes to the small settlement of Lago and is hired to bring the townsfolk together in an attempt to hold off three outlaws who are on their way." assert_equal(@hpd.plot,plot) assert_equal(@hpd.plot_keywords,plot_key) assert_equal(@hpd.plot_outline,plot_out) end def test_runtime assert_equal(@pi.runtime,"84 min") end def test_tagline assert_equal(@office_space.tagline,"Work Sucks.") end def test_user_comments assert_equal(@pi.user_comments,"The best no-budget movie you'll ever see") assert_equal(@office_space.user_comments,"Whaaaaaat's happening?") assert_equal(@hpd.user_comments,"An entertaining and well thought out western") end def test_writers assert_equal(@office_space.writer,["Mike Judge"]) assert_equal(@office_space.writers,["Mike Judge"]) end def test_xml pi_xml = "Pamela HartMarcy DawsonAri HandelKabbala ScholarTom TumminelloEphraimStanley HermanMoustacheless ManAjay NaiduFarroukhSamia ShoaibDeviMark MargolisSol RobesonJoanne GordonMrs. OvadiaEspher Lao NievesJenna's MomKristyn Mae-Anne LaoJennaBen ShenkmanLenny MeyerClint MansellPhotographerStephen PearlmanRabbi CohenSean GulletteMaximillian CohenLauren FoxJenny Robeson84 minA paranoid mathematician searches for a key number that will unlock the universal patterns found in nature.Darren AronofskyDarren Aronofsky,Sean GullettePi 1998-07-10Rated R for language and some disturbing images.The best no-budget movie you'll ever seefaith in chaosA paranoid mathematician searches for a key number that will unlock the universal patterns found in nature.ThrillerSci-Fi" assert_equal(@pi.to_xml,pi_xml) end def test_html @pi.to_html end end