Skip to content
Browse files

Add test case demonstrating update_index failure

Extend test_gem_indexer to better reflect system state in update_index.
  • Loading branch information...
1 parent 6bb445f commit c84841632abd88a9db8648730c01e056c7bfaea5 @jfoy jfoy committed Aug 24, 2012
Showing with 38 additions and 17 deletions.
  1. +5 −0 lib/rubygems/test_case.rb
  2. +33 −17 test/rubygems/test_gem_indexer.rb
View
5 lib/rubygems/test_case.rb
@@ -417,6 +417,11 @@ def util_build_gem(spec)
end
end
+ def util_remove_gem(spec)
+ FileUtils.rm_rf spec.cache_file
+ FileUtils.rm_rf spec.spec_file
+ end
+
##
# Removes all installed gems from +@gemhome+.
View
50 test/rubygems/test_gem_indexer.rb
@@ -494,6 +494,20 @@ def test_generate_index_prerelease_specs
prerelease_specs
end
+ ##
+ # Emulate the starting state of Gem::Specification in a live environment,
+ # where it will carry the list of system gems
+ def with_system_gems
+ Gem::Specification.reset
+
+ sys_gem = quick_spec 'systemgem', '1.0'
+ util_build_gem sys_gem
+ Gem::Specification.add_spec sys_gem
+ yield
+ util_remove_gem sys_gem
+ end
+
+
def test_update_index
use_ui @ui do
@indexer.generate_index
@@ -518,30 +532,32 @@ def test_update_index
FileUtils.mv @d2_1.cache_file, gems
FileUtils.mv @d2_1_a.cache_file, gems
- use_ui @ui do
- @indexer.update_index
- end
+ with_system_gems do
+ use_ui @ui do
+ @indexer.update_index
+ end
- assert_indexed marshal_quickdir, "#{File.basename(@d2_1.spec_file)}.rz"
+ assert_indexed marshal_quickdir, "#{File.basename(@d2_1.spec_file)}.rz"
- specs_index = Marshal.load Gem.read_binary(@indexer.dest_specs_index)
+ specs_index = Marshal.load Gem.read_binary(@indexer.dest_specs_index)
- assert_includes specs_index, @d2_1_tuple
- refute_includes specs_index, @d2_1_a_tuple
+ assert_includes specs_index, @d2_1_tuple
+ refute_includes specs_index, @d2_1_a_tuple
- latest_specs_index = Marshal.load \
- Gem.read_binary(@indexer.dest_latest_specs_index)
+ latest_specs_index = Marshal.load \
+ Gem.read_binary(@indexer.dest_latest_specs_index)
- assert_includes latest_specs_index, @d2_1_tuple
- assert_includes latest_specs_index,
- [@d2_0.name, @d2_0.version, @d2_0.original_platform]
- refute_includes latest_specs_index, @d2_1_a_tuple
+ assert_includes latest_specs_index, @d2_1_tuple
+ assert_includes latest_specs_index,
+ [@d2_0.name, @d2_0.version, @d2_0.original_platform]
+ refute_includes latest_specs_index, @d2_1_a_tuple
- pre_specs_index = Marshal.load \
- Gem.read_binary(@indexer.dest_prerelease_specs_index)
+ pre_specs_index = Marshal.load \
+ Gem.read_binary(@indexer.dest_prerelease_specs_index)
- assert_includes pre_specs_index, @d2_1_a_tuple
- refute_includes pre_specs_index, @d2_1_tuple
+ assert_includes pre_specs_index, @d2_1_a_tuple
+ refute_includes pre_specs_index, @d2_1_tuple
+ end
end
def assert_indexed(dir, name)

0 comments on commit c848416

Please sign in to comment.
Something went wrong with that request. Please try again.