Skip to content
This repository has been archived by the owner on Apr 2, 2021. It is now read-only.

Commit

Permalink
Add test case demonstrating update_index failure
Browse files Browse the repository at this point in the history
Extend test_gem_indexer to better reflect system state in update_index.
  • Loading branch information
jfoy committed Aug 25, 2012
1 parent 6bb445f commit c848416
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 17 deletions.
5 changes: 5 additions & 0 deletions lib/rubygems/test_case.rb
Expand Up @@ -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+.

Expand Down
50 changes: 33 additions & 17 deletions test/rubygems/test_gem_indexer.rb
Expand Up @@ -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
Expand All @@ -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)
Expand Down

0 comments on commit c848416

Please sign in to comment.