Skip to content

Commit

Permalink
Warn when updating the specs cache fails. Fixes #300
Browse files Browse the repository at this point in the history
  • Loading branch information
evanphx committed Mar 21, 2012
1 parent 1137ed5 commit 4bed18a
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
8 changes: 6 additions & 2 deletions lib/rubygems/spec_fetcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -255,8 +255,12 @@ def load_specs(source_uri, file)
loaded = false

if File.exist? local_file then
spec_dump =
@fetcher.fetch_path(spec_path, File.mtime(local_file)) rescue nil
begin
spec_dump =
@fetcher.fetch_path(spec_path, File.mtime(local_file))
rescue Gem::RemoteFetcher::FetchError => e
alert_warning "Error fetching data: #{e.message}"
end

loaded = true if spec_dump

Expand Down
32 changes: 32 additions & 0 deletions test/rubygems/test_gem_commands_install_command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,38 @@ def test_execute_nonexistent
assert_match(/ould not find a valid gem 'nonexistent'/, @ui.error)
end

def test_execute_bad_source
util_setup_fake_fetcher
util_setup_spec_fetcher

# This is needed because we need to exercise the cache path
# within SpecFetcher
path = File.join Gem.user_home, '.gem', 'specs', "not-there.nothing%80",
"latest_specs.4.8"

FileUtils.mkdir_p File.dirname(path)

File.open path, "w" do |f|
f.write Marshal.dump([])
end

Gem.sources.replace ["http://not-there.nothing"]

@cmd.options[:args] = %w[nonexistent]

use_ui @ui do
e = assert_raises Gem::SystemExitException do
@cmd.execute
end
assert_equal 2, e.exit_code
end

errs = @ui.error.split("\n")

assert_match(/WARNING: Error fetching data/, errs.shift)
assert_match(/ould not find a valid gem 'nonexistent'/, errs.shift)
end

def test_execute_nonexistent_with_hint
misspelled = "nonexistent_with_hint"
correctly_spelled = "non_existent_with_hint"
Expand Down

0 comments on commit 4bed18a

Please sign in to comment.