Permalink
Browse files

Make test suite run without a valid API key

For TravisCI
  • Loading branch information...
1 parent 49cc449 commit e4f850e8a6ce2cd4ceccd992eef8d88dfe343ad6 Irio Irineu Musskopf Junior committed Dec 6, 2012
Showing with 21 additions and 19 deletions.
  1. +0 −2 .gitignore
  2. +1 −0 test/setup/tmdb_api_key.txt
  3. +1 −1 test/test_helper.rb
  4. +8 −5 test/unit/test_direct_require.rb
  5. +11 −11 test/unit/tmdb_cast_test.rb
View
2 .gitignore
@@ -1,6 +1,4 @@
*.gem
-test/setup/tmdb_api_key.txt
.rvmrc
.rbenv-version
.DS_Store
-
View
1 test/setup/tmdb_api_key.txt
@@ -0,0 +1 @@
+PUT_YOUR_KEY_IN_TMDB_API_KEY_TXT_FILE
View
2 test/test_helper.rb
@@ -11,7 +11,7 @@
require_files = []
require_files << File.join(File.dirname(__FILE__), '..', 'lib', 'ruby-tmdb3.rb')
-require_files.concat Dir[File.join(File.dirname(__FILE__), 'setup', '*.rb')]
+require_files.concat(Dir[File.join(File.dirname(__FILE__), 'setup', '*.rb')])
require_files.each do |file|
require File.expand_path(file)
View
13 test/unit/test_direct_require.rb
@@ -1,4 +1,5 @@
-require "test/unit"
+require 'test/unit'
+require 'mocha/setup'
require_files = []
require_files << File.join(File.dirname(__FILE__), "..", "..", "lib", "ruby-tmdb3.rb")
@@ -9,17 +10,19 @@
end
class DirectRequireTest < Test::Unit::TestCase
-
+
test "TmdbMovie should not raise exception when directly required without using rubygems" do
+ Tmdb.stubs(:api_call).returns([])
assert_nothing_raised do
TmdbMovie.find(:id => 187)
end
end
-
+
test "TmdbCast should not raise exception when directly required without using rubygems" do
+ Tmdb.stubs(:api_call).returns([])
assert_nothing_raised do
TmdbCast.find(:id => 287)
end
end
-
-end
+
+end
View
22 test/unit/tmdb_cast_test.rb
@@ -10,25 +10,25 @@ def setup
movie = TmdbCast.find(:name => "item_not_found")
assert_equal [], movie
end
-
+
test "cast data should be able to be dumped and re-loaded" do
assert_nothing_raised do
cast = TmdbCast.find(:id => 287)
TmdbCast.new(cast.raw_data)
end
end
-
+
test "find by id should return full cast data" do
cast = TmdbCast.find(:id => 287)
assert_cast_methodized(cast, 287)
end
-
+
test "two cast objects with same data should be equal" do
cast1 = TmdbCast.find(:id => 287, :limit => 1)
cast2 = TmdbCast.find(:id => 287, :limit => 1)
assert_equal cast1, cast2
end
-
+
test "find by name should return full cast data when :expand_results = true" do
cast = TmdbCast.find(:name => "Brad Pitt", :expand_results => true)
cast = cast.first if cast.class == Array
@@ -44,36 +44,36 @@ def setup
test "find by id should return a single cast member" do
assert_kind_of OpenStruct, TmdbCast.find(:id => 287)
end
-
+
test "find by name should return an array of cast members" do
cast_members = TmdbCast.find(:name => "vince")
assert_kind_of Array, cast_members
cast_members.each do |actor|
assert_kind_of OpenStruct, actor
end
end
-
+
test "should raise error if limit is smaller than 1" do
[0, -1, -100].each do |limit|
assert_raise ArgumentError do
TmdbCast.find(:name => "vince", :limit => limit)
end
end
end
-
+
test "should raise error if limit is not an integer" do
[1.001, "1.2", "hello", [1,2,3], {:test => "1"}].each do |limit|
assert_raise ArgumentError do
TmdbCast.find(:name => "vince", :limit => limit)
end
end
end
-
+
test "should only return a single item if limit=1" do
actor = TmdbCast.find(:name => "Vince", :limit => 1)
assert_kind_of OpenStruct, actor
end
-
+
test "should return X items if limit=X" do
(2..5).each do |x|
actors = TmdbCast.find(:name => "Vince", :limit => x)
@@ -107,7 +107,7 @@ def setup
end
private
-
+
def assert_cast_methodized(actor, cast_id)
@cast_data = Tmdb.api_call("person", {:id => cast_id.to_s}, Tmdb.default_language)
assert_equal @cast_data["adult"], actor.adult
@@ -123,4 +123,4 @@ def assert_cast_methodized(actor, cast_id)
assert_equal @cast_data["profile_path"], actor.profile_path
end
-end
+end

0 comments on commit e4f850e

Please sign in to comment.