test/unit/tmdb_test.rb in ruby-tmdb-0.1.2 vs test/unit/tmdb_test.rb in ruby-tmdb-0.1.3
- old
+ new
@@ -1,158 +1,158 @@
-require File.expand_path(File.join(File.dirname(__FILE__), '..', 'test_helper.rb'))
-
-class TmdbTest < Test::Unit::TestCase
-
- def setup
- register_api_url_stubs
- end
-
- test "allows setting of api_key" do
- old_api_key = Tmdb.api_key
- api_key = "test1234567890"
- Tmdb.api_key = api_key
- assert_equal Tmdb.api_key, api_key
- Tmdb.api_key = old_api_key
- end
-
- test "should return base API url" do
- assert_equal "http://api.themoviedb.org/2.1/", Tmdb.base_api_url
- end
-
- test "get url returns a response object" do
- test_response = Tmdb.get_url("http://example.com/")
- assert_equal 200, test_response.code.to_i
- end
-
- test "getting nonexistent URL returns response object" do
- test_response = Tmdb.get_url('http://thisisaurlthatdoesntexist.co.nz')
- assert_equal 404, test_response.code.to_i
- end
-
- test "api_call should raise exception if api_key is not set" do
- old_api_key = Tmdb.api_key
- Tmdb.api_key = ""
- assert_raises ArgumentError do
- Tmdb.api_call('Movie.search', 'Transformers')
- end
- Tmdb.api_key = old_api_key
- end
-
- test "should perform Movie.search API call and return array of results" do
- movies = Tmdb.api_call('Movie.search', 'Transformers')
- assert_kind_of Array, movies
- assert movies.length > 1
- movies.each do |movie|
- assert_kind_of Hash, movie
- ["url", "id", "name"].each do |item|
- assert movie[item]
- end
- end
- end
-
- test "should perform Movie.getInfo API call and return array of results" do
- movies = Tmdb.api_call('Movie.getInfo', 187)
- assert_kind_of Array, movies
- assert movies.length == 1
- movies.each do |movie|
- assert_kind_of Hash, movie
- ["url", "id", "name"].each do |item|
- assert movie[item]
- end
- end
- end
-
- test "should perform Movie.imdbLookup API call and return array of results" do
- movies = Tmdb.api_call('Movie.imdbLookup', "tt0401792")
- assert_kind_of Array, movies
- assert movies.length == 1
- movies.each do |movie|
- assert_kind_of Hash, movie
- ["url", "id", "name"].each do |item|
- assert movie[item]
- end
- end
- end
-
- test "should perform Person.getInfo API call and return array of results" do
- people = Tmdb.api_call('Person.getInfo', 287)
- assert_kind_of Array, people
- assert people.length == 1
- people.each do |person|
- assert_kind_of Hash, person
- ["url", "id", "name"].each do |item|
- assert person[item]
- end
- end
- end
-
- test "should perform Person.search API call and return array of results" do
- people = Tmdb.api_call('Person.search', "vince")
- assert_kind_of Array, people
- assert people.length > 1
- people.each do |person|
- assert_kind_of Hash, person
- ["url", "id", "name"].each do |item|
- assert person[item]
- end
- end
- end
-
- test "failed API call should return nil" do
- movies = Tmdb.api_call('Movie.blarg', 'Transformers')
- assert_kind_of NilClass, movies
- assert_nil movies
- end
-
- test "API call that finds no results should return nil" do
- movies = Tmdb.api_call('Search.empty', 'Transformers')
- assert_kind_of NilClass, movies
- assert_nil movies
- end
-
- test "API call cache should not be changed when data altered in the receiving method" do
- person = Tmdb.api_call('Person.getInfo', 287)[0]
- assert_not_nil person[person.keys[0]]
- person[person.keys[0]] = nil
- person = Tmdb.api_call('Person.getInfo', 287)[0]
- assert_not_nil person[person.keys[0]]
- end
-
- test "data_to_object should create object from nested data structures" do
- test_data = {
- :test1 => [
- 1,2,3,4
- ],
- :test2 => 1
- }
- test_object = Tmdb.data_to_object(test_data)
- assert_nothing_raised do
- assert_equal [1,2,3,4], test_object.test1
- assert_equal 1, test_object.test2
- end
- end
-
- test "data_to_object should include raw_data method that returns original data" do
- test_data = {
- :test1 => [1,2,3]
- }
- test_object = Tmdb.data_to_object(test_data)
- assert_equal test_object.raw_data, test_data
- end
-
- test "data_to_object should convert arrays containing images to nicer format" do
- test_data = {
- "backdrops" => [
- {
- "image" => {
- :test => 1
- }
- }
- ]
- }
- test_object = Tmdb.data_to_object(test_data)
- assert_nothing_raised do
- assert_equal 1, test_object.backdrops[0].test
- end
- end
-
+require File.expand_path(File.join(File.dirname(__FILE__), '..', 'test_helper.rb'))
+
+class TmdbTest < Test::Unit::TestCase
+
+ def setup
+ register_api_url_stubs
+ end
+
+ test "allows setting of api_key" do
+ old_api_key = Tmdb.api_key
+ api_key = "test1234567890"
+ Tmdb.api_key = api_key
+ assert_equal Tmdb.api_key, api_key
+ Tmdb.api_key = old_api_key
+ end
+
+ test "should return base API url" do
+ assert_equal "http://api.themoviedb.org/2.1/", Tmdb.base_api_url
+ end
+
+ test "get url returns a response object" do
+ test_response = Tmdb.get_url("http://example.com/")
+ assert_equal 200, test_response.code.to_i
+ end
+
+ test "getting nonexistent URL returns response object" do
+ test_response = Tmdb.get_url('http://thisisaurlthatdoesntexist.co.nz')
+ assert_equal 404, test_response.code.to_i
+ end
+
+ test "api_call should raise exception if api_key is not set" do
+ old_api_key = Tmdb.api_key
+ Tmdb.api_key = ""
+ assert_raises ArgumentError do
+ Tmdb.api_call('Movie.search', 'Transformers')
+ end
+ Tmdb.api_key = old_api_key
+ end
+
+ test "should perform Movie.search API call and return array of results" do
+ movies = Tmdb.api_call('Movie.search', 'Transformers')
+ assert_kind_of Array, movies
+ assert movies.length > 1
+ movies.each do |movie|
+ assert_kind_of Hash, movie
+ ["url", "id", "name"].each do |item|
+ assert movie[item]
+ end
+ end
+ end
+
+ test "should perform Movie.getInfo API call and return array of results" do
+ movies = Tmdb.api_call('Movie.getInfo', 187)
+ assert_kind_of Array, movies
+ assert movies.length == 1
+ movies.each do |movie|
+ assert_kind_of Hash, movie
+ ["url", "id", "name"].each do |item|
+ assert movie[item]
+ end
+ end
+ end
+
+ test "should perform Movie.imdbLookup API call and return array of results" do
+ movies = Tmdb.api_call('Movie.imdbLookup', "tt0401792")
+ assert_kind_of Array, movies
+ assert movies.length == 1
+ movies.each do |movie|
+ assert_kind_of Hash, movie
+ ["url", "id", "name"].each do |item|
+ assert movie[item]
+ end
+ end
+ end
+
+ test "should perform Person.getInfo API call and return array of results" do
+ people = Tmdb.api_call('Person.getInfo', 287)
+ assert_kind_of Array, people
+ assert people.length == 1
+ people.each do |person|
+ assert_kind_of Hash, person
+ ["url", "id", "name"].each do |item|
+ assert person[item]
+ end
+ end
+ end
+
+ test "should perform Person.search API call and return array of results" do
+ people = Tmdb.api_call('Person.search', "vince")
+ assert_kind_of Array, people
+ assert people.length > 1
+ people.each do |person|
+ assert_kind_of Hash, person
+ ["url", "id", "name"].each do |item|
+ assert person[item]
+ end
+ end
+ end
+
+ test "failed API call should return nil" do
+ movies = Tmdb.api_call('Movie.blarg', 'Transformers')
+ assert_kind_of NilClass, movies
+ assert_nil movies
+ end
+
+ test "API call that finds no results should return nil" do
+ movies = Tmdb.api_call('Search.empty', 'Transformers')
+ assert_kind_of NilClass, movies
+ assert_nil movies
+ end
+
+ test "API call cache should not be changed when data altered in the receiving method" do
+ person = Tmdb.api_call('Person.getInfo', 287)[0]
+ assert_not_nil person[person.keys[0]]
+ person[person.keys[0]] = nil
+ person = Tmdb.api_call('Person.getInfo', 287)[0]
+ assert_not_nil person[person.keys[0]]
+ end
+
+ test "data_to_object should create object from nested data structures" do
+ test_data = {
+ :test1 => [
+ 1,2,3,4
+ ],
+ :test2 => 1
+ }
+ test_object = Tmdb.data_to_object(test_data)
+ assert_nothing_raised do
+ assert_equal [1,2,3,4], test_object.test1
+ assert_equal 1, test_object.test2
+ end
+ end
+
+ test "data_to_object should include raw_data method that returns original data" do
+ test_data = {
+ :test1 => [1,2,3]
+ }
+ test_object = Tmdb.data_to_object(test_data)
+ assert_equal test_object.raw_data, test_data
+ end
+
+ test "data_to_object should convert arrays containing images to nicer format" do
+ test_data = {
+ "backdrops" => [
+ {
+ "image" => {
+ :test => 1
+ }
+ }
+ ]
+ }
+ test_object = Tmdb.data_to_object(test_data)
+ assert_nothing_raised do
+ assert_equal 1, test_object.backdrops[0].test
+ end
+ end
+
end
\ No newline at end of file