Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Deduplicate code in tests for missing source

  • Loading branch information...
commit b5e0a7509fb7108b42725b59249b856699c65dd2 1 parent dfc72f1
@presidentbeef authored
Showing with 22 additions and 38 deletions.
  1. +22 −38 test/rubygems/test_gem_commands_install_command.rb
View
60 test/rubygems/test_gem_commands_install_command.rb
@@ -401,50 +401,38 @@ def test_execute_conservative
#but the other contains only specs*.gz and latest_specs*.gz,
#no individual specs or gems
def test_execute_one_failing_gem_source
- util_setup_fake_fetcher
- util_setup_spec_fetcher
-
- new_repo = "http://gems2.example.com"
- Gem.sources << new_repo
-
- specs = Gem::Specification.map { |spec|
- [spec.name, spec.version, spec.original_platform]
- }
- specs_dump_gz = StringIO.new
- Zlib::GzipWriter.wrap specs_dump_gz do |io|
- Marshal.dump specs, io
- end
+ assert_failing_server do |specs, bad_repo|
+ specs_dump_gz = StringIO.new
+ Zlib::GzipWriter.wrap specs_dump_gz do |io|
+ Marshal.dump specs, io
+ end
- @fetcher.data["#{@gem_repo}gems/#{@a2.file_name}"] =
+ @fetcher.data["#{@gem_repo}gems/#{@a2.file_name}"] =
read_binary(@a2.cache_file)
- @fetcher.data["#{new_repo}/specs.#{@marshal_version}.gz"] =
+ @fetcher.data["#{bad_repo}/specs.#{@marshal_version}.gz"] =
specs_dump_gz.string
- @fetcher.data["#{new_repo}/latest_specs.#{@marshal_version}.gz"] =
+ @fetcher.data["#{bad_repo}/latest_specs.#{@marshal_version}.gz"] =
specs_dump_gz.string
+ end
+ end
- @cmd.options[:args] = [@a2.name]
-
- use_ui @ui do
- orig_dir = Dir.pwd
- begin
- Dir.chdir @tempdir
- e = assert_raises Gem::SystemExitException do
- @cmd.execute
- end
- assert_equal 0, e.exit_code
- ensure
- Dir.chdir orig_dir
+ #Check that gem can still be installed even if one of the known sources
+ #is not available
+ def test_execute_one_failing_source
+ assert_failing_server do |specs, bad_repo|
+ #If the source was added, then the specs file should exist locally
+ #Sources cannot be added unless they exist at the time
+ write_file("#{@userhome}/.gem/specs/gems2.example.com%80/latest_specs.4.8") do |file|
+ Marshal.dump specs, file
end
end
-
- assert_equal "1 gem installed\n", @ui.output
- assert_equal "", @ui.error
end
- def test_execute_one_failing_source
+ #Set up gem sources but with one source that is not actually available
+ def assert_failing_server
util_setup_fake_fetcher
util_setup_spec_fetcher
@@ -456,15 +444,11 @@ def test_execute_one_failing_source
[spec.name, spec.version, spec.original_platform]
}
- #If the source was added, then the specs file should exist locally
- #Sources cannot be added unless they exist at the time
- write_file("#{@userhome}/.gem/specs/gems2.example.com%80/latest_specs.4.8") do |file|
- Marshal.dump specs, file
- end
-
@fetcher.data["#{@gem_repo}gems/#{@a2.file_name}"] =
read_binary(@a2.cache_file)
+ yield specs, new_repo
+
@cmd.options[:args] = [@a2.name]
use_ui @ui do
Please sign in to comment.
Something went wrong with that request. Please try again.