How to use end method of Gem Package

Best Vcr_ruby code snippet using Gem.end

test_gem.rb

Source:test_gem.rb Github

copy

Full Screen

...8require 'rbconfig'9# TODO: push this up to test_case.rb once battle tested10$LOAD_PATH.map! do |path|11 path.dup.untaint12end13class TestGem < Gem::TestCase14 RUBY_INSTALL_NAME = RbConfig::CONFIG['RUBY_INSTALL_NAME']15 PLUGINS_LOADED = [] # rubocop:disable Style/MutableConstant16 def setup17 super18 PLUGINS_LOADED.clear19 common_installer_setup20 ENV.delete 'RUBYGEMS_GEMDEPS'21 @additional = %w[a b].map { |d| File.join @tempdir, d }22 util_remove_interrupt_command23 end24 def test_self_finish_resolve25 save_loaded_features do26 a1 = util_spec "a", "1", "b" => "> 0"27 b1 = util_spec "b", "1", "c" => ">= 1"28 b2 = util_spec "b", "2", "c" => ">= 2"29 c1 = util_spec "c", "1"30 c2 = util_spec "c", "2"31 install_specs c1, c2, b1, b2, a132 a1.activate33 assert_equal %w(a-1), loaded_spec_names34 assert_equal ["b (> 0)"], unresolved_names35 Gem.finish_resolve36 assert_equal %w(a-1 b-2 c-2), loaded_spec_names37 assert_equal [], unresolved_names38 end39 end40 def test_self_finish_resolve_wtf41 save_loaded_features do42 a1 = util_spec "a", "1", "b" => "> 0", "d" => "> 0" # this43 b1 = util_spec "b", "1", { "c" => ">= 1" }, "lib/b.rb" # this44 b2 = util_spec "b", "2", { "c" => ">= 2" }, "lib/b.rb"45 c1 = util_spec "c", "1" # this46 c2 = util_spec "c", "2"47 d1 = util_spec "d", "1", { "c" => "< 2" }, "lib/d.rb"48 d2 = util_spec "d", "2", { "c" => "< 2" }, "lib/d.rb" # this49 install_specs c1, c2, b1, b2, d1, d2, a150 a1.activate51 assert_equal %w(a-1), loaded_spec_names52 assert_equal ["b (> 0)", "d (> 0)"], unresolved_names53 Gem.finish_resolve54 assert_equal %w(a-1 b-1 c-1 d-2), loaded_spec_names55 assert_equal [], unresolved_names56 end57 end58 def test_self_finish_resolve_respects_loaded_specs59 save_loaded_features do60 a1 = util_spec "a", "1", "b" => "> 0"61 b1 = util_spec "b", "1", "c" => ">= 1"62 b2 = util_spec "b", "2", "c" => ">= 2"63 c1 = util_spec "c", "1"64 c2 = util_spec "c", "2"65 install_specs c1, c2, b1, b2, a166 a1.activate67 c1.activate68 assert_equal %w(a-1 c-1), loaded_spec_names69 assert_equal ["b (> 0)"], unresolved_names70 Gem.finish_resolve71 assert_equal %w(a-1 b-1 c-1), loaded_spec_names72 assert_equal [], unresolved_names73 end74 end75 def test_self_install76 spec_fetcher do |f|77 f.gem 'a', 178 f.spec 'a', 279 end80 gemhome2 = "#{@gemhome}2"81 installed = Gem.install 'a', '= 1', :install_dir => gemhome282 assert_equal %w[a-1], installed.map { |spec| spec.full_name }83 assert_path_exists File.join(gemhome2, 'gems', 'a-1')84 end85 def test_self_install_in_rescue86 spec_fetcher do |f|87 f.gem 'a', 188 f.spec 'a', 289 end90 gemhome2 = "#{@gemhome}2"91 installed =92 begin93 raise 'Error'94 rescue StandardError95 Gem.install 'a', '= 1', :install_dir => gemhome296 end97 assert_equal %w[a-1], installed.map { |spec| spec.full_name }98 end99 def test_self_install_permissions100 assert_self_install_permissions101 end102 def test_self_install_permissions_umask_0103 umask = File.umask(0)104 assert_self_install_permissions105 ensure106 File.umask(umask)107 end108 def test_self_install_permissions_umask_077109 umask = File.umask(077)110 assert_self_install_permissions111 ensure112 File.umask(umask)113 end114 def assert_self_install_permissions115 mask = /mingw|mswin/ =~ RUBY_PLATFORM ? 0700 : 0777116 options = {117 :dir_mode => 0500,118 :prog_mode => 0510,119 :data_mode => 0640,120 :wrappers => true,121 }122 Dir.chdir @tempdir do123 Dir.mkdir 'bin'124 File.open 'bin/foo.cmd', 'w' do |fp|125 fp.chmod(0755)126 fp.puts 'p'127 end128 Dir.mkdir 'data'129 File.open 'data/foo.txt', 'w' do |fp|130 fp.puts 'blah'131 end132 spec_fetcher do |f|133 f.gem 'foo', 1 do |s|134 s.executables = ['foo.cmd']135 s.files = %w[bin/foo.cmd data/foo.txt]136 end137 end138 Gem.install 'foo', Gem::Requirement.default, options139 end140 prog_mode = (options[:prog_mode] & mask).to_s(8)141 dir_mode = (options[:dir_mode] & mask).to_s(8)142 data_mode = (options[:data_mode] & mask).to_s(8)143 expected = {144 "bin/#{RUBY_INSTALL_NAME.sub('ruby', 'foo.cmd')}" => prog_mode,145 'gems/foo-1' => dir_mode,146 'gems/foo-1/bin' => dir_mode,147 'gems/foo-1/data' => dir_mode,148 'gems/foo-1/bin/foo.cmd' => prog_mode,149 'gems/foo-1/data/foo.txt' => data_mode,150 }151 result = {}152 Dir.chdir @gemhome do153 expected.each_key do |n|154 result[n] = (File.stat(n).mode & mask).to_s(8)155 end156 end157 assert_equal(expected, result)158 ensure159 File.chmod(0755, *Dir.glob(@gemhome+'/gems/**/').map {|path| path.untaint})160 end161 def test_require_missing162 save_loaded_features do163 assert_raises ::LoadError do164 require "q"165 end166 end167 end168 def test_require_does_not_glob169 save_loaded_features do170 a1 = util_spec "a", "1", nil, "lib/a1.rb"171 install_specs a1172 assert_raises ::LoadError do173 require "a*"174 end175 assert_equal [], loaded_spec_names176 end177 end178 def test_self_bin_path_active179 a1 = util_spec 'a', '1' do |s|180 s.executables = ['exec']181 end182 util_spec 'a', '2' do |s|183 s.executables = ['exec']184 end185 a1.activate186 assert_match 'a-1/bin/exec', Gem.bin_path('a', 'exec', '>= 0')187 end188 def test_self_bin_path_picking_newest189 a1 = util_spec 'a', '1' do |s|190 s.executables = ['exec']191 end192 a2 = util_spec 'a', '2' do |s|193 s.executables = ['exec']194 end195 install_specs a1, a2196 assert_match 'a-2/bin/exec', Gem.bin_path('a', 'exec', '>= 0')197 end198 def test_activate_bin_path_resolves_eagerly199 a1 = util_spec 'a', '1' do |s|200 s.executables = ['exec']201 s.add_dependency 'b'202 end203 b1 = util_spec 'b', '1' do |s|204 s.add_dependency 'c', '2'205 end206 b2 = util_spec 'b', '2' do |s|207 s.add_dependency 'c', '1'208 end209 c1 = util_spec 'c', '1'210 c2 = util_spec 'c', '2'211 install_specs c1, c2, b1, b2, a1212 Gem.activate_bin_path("a", "exec", ">= 0")213 # If we didn't eagerly resolve, this would activate c-2 and then the214 # finish_resolve would cause a conflict215 gem 'c'216 Gem.finish_resolve217 assert_equal %w(a-1 b-2 c-1), loaded_spec_names218 end219 def test_activate_bin_path_gives_proper_error_for_bundler220 bundler = util_spec 'bundler', '2' do |s|221 s.executables = ['bundle']222 end223 install_specs bundler224 File.open("Gemfile.lock", "w") do |f|225 f.write <<-L.gsub(/ {8}/, "")226 GEM227 remote: https://rubygems.org/228 specs:229 PLATFORMS230 ruby231 DEPENDENCIES232 BUNDLED WITH233 9999234 L235 end236 File.open("Gemfile", "w") { |f| f.puts('source "https://rubygems.org"') }237 e = assert_raises Gem::GemNotFoundException do238 load Gem.activate_bin_path("bundler", "bundle", ">= 0.a")239 end240 assert_includes e.message, "Could not find 'bundler' (9999) required by your #{File.expand_path("Gemfile.lock")}."241 assert_includes e.message, "To update to the latest version installed on your system, run `bundle update --bundler`."242 assert_includes e.message, "To install the missing version, run `gem install bundler:9999`"243 refute_includes e.message, "can't find gem bundler (>= 0.a) with executable bundle"244 end245 def test_self_bin_path_no_exec_name246 e = assert_raises ArgumentError do247 Gem.bin_path 'a'248 end249 assert_equal 'you must supply exec_name', e.message250 end251 def test_self_bin_path_bin_name252 install_specs util_exec_gem253 assert_equal @abin_path, Gem.bin_path('a', 'abin')254 end255 def test_self_bin_path_bin_name_version256 install_specs util_exec_gem257 assert_equal @abin_path, Gem.bin_path('a', 'abin', '4')258 end259 def test_self_bin_path_nonexistent_binfile260 util_spec 'a', '2' do |s|261 s.executables = ['exec']262 end263 assert_raises(Gem::GemNotFoundException) do264 Gem.bin_path('a', 'other', '2')265 end266 end267 def test_self_bin_path_no_bin_file268 util_spec 'a', '1'269 assert_raises(ArgumentError) do270 Gem.bin_path('a', nil, '1')271 end272 end273 def test_self_bin_path_not_found274 assert_raises(Gem::GemNotFoundException) do275 Gem.bin_path('non-existent', 'blah')276 end277 end278 def test_self_bin_path_bin_file_gone_in_latest279 install_specs util_exec_gem280 spec = util_spec 'a', '10' do |s|281 s.executables = []282 end283 install_specs spec284 # Should not find a-10's non-abin (bug)285 assert_equal @abin_path, Gem.bin_path('a', 'abin')286 end287 def test_self_bindir288 assert_equal File.join(@gemhome, 'bin'), Gem.bindir289 assert_equal File.join(@gemhome, 'bin'), Gem.bindir(Gem.dir)290 assert_equal File.join(@gemhome, 'bin'), Gem.bindir(Pathname.new(Gem.dir))291 end292 def test_self_bindir_default_dir293 default = Gem.default_dir294 assert_equal Gem.default_bindir, Gem.bindir(default)295 end296 def test_self_clear_paths297 assert_match(/gemhome$/, Gem.dir)298 assert_match(/gemhome$/, Gem.path.first)299 Gem.clear_paths300 assert_nil Gem::Specification.send(:class_variable_get, :@@all)301 end302 def test_self_configuration303 expected = Gem::ConfigFile.new []304 Gem.configuration = nil305 assert_equal expected, Gem.configuration306 end307 def test_self_datadir308 foo = nil309 Dir.chdir @tempdir do310 FileUtils.mkdir_p 'data'311 File.open File.join('data', 'foo.txt'), 'w' do |fp|312 fp.puts 'blah'313 end314 foo = util_spec 'foo' do |s| s.files = %w[data/foo.txt] end315 install_gem foo316 end317 gem 'foo'318 expected = File.join @gemhome, 'gems', foo.full_name, 'data', 'foo'319 assert_equal expected, Gem::Specification.find_by_name("foo").datadir320 end321 def test_self_datadir_nonexistent_package322 assert_raises(Gem::MissingSpecError) do323 Gem::Specification.find_by_name("xyzzy").datadir324 end325 end326 def test_self_default_exec_format327 ruby_install_name 'ruby' do328 assert_equal '%s', Gem.default_exec_format329 end330 end331 def test_self_default_exec_format_18332 ruby_install_name 'ruby18' do333 assert_equal '%s18', Gem.default_exec_format334 end335 end336 def test_self_default_exec_format_jruby337 ruby_install_name 'jruby' do338 assert_equal 'j%s', Gem.default_exec_format339 end340 end341 def test_default_path342 orig_vendordir = RbConfig::CONFIG['vendordir']343 RbConfig::CONFIG['vendordir'] = File.join @tempdir, 'vendor'344 FileUtils.rm_rf Gem.user_home345 expected = [Gem.default_dir]346 assert_equal expected, Gem.default_path347 ensure348 RbConfig::CONFIG['vendordir'] = orig_vendordir349 end350 def test_default_path_missing_vendor351 orig_vendordir = RbConfig::CONFIG['vendordir']352 RbConfig::CONFIG.delete 'vendordir'353 FileUtils.rm_rf Gem.user_home354 expected = [Gem.default_dir]355 assert_equal expected, Gem.default_path356 ensure357 RbConfig::CONFIG['vendordir'] = orig_vendordir358 end359 def test_default_path_user_home360 orig_vendordir = RbConfig::CONFIG['vendordir']361 RbConfig::CONFIG['vendordir'] = File.join @tempdir, 'vendor'362 expected = [Gem.user_dir, Gem.default_dir]363 assert_equal expected, Gem.default_path364 ensure365 RbConfig::CONFIG['vendordir'] = orig_vendordir366 end367 def test_default_path_vendor_dir368 orig_vendordir = RbConfig::CONFIG['vendordir']369 RbConfig::CONFIG['vendordir'] = File.join @tempdir, 'vendor'370 FileUtils.mkdir_p Gem.vendor_dir371 FileUtils.rm_rf Gem.user_home372 expected = [Gem.default_dir, Gem.vendor_dir]373 assert_equal expected, Gem.default_path374 ensure375 RbConfig::CONFIG['vendordir'] = orig_vendordir376 end377 def test_self_default_sources378 assert_equal %w[https://rubygems.org/], Gem.default_sources379 end380 def test_self_use_gemdeps381 rubygems_gemdeps, ENV['RUBYGEMS_GEMDEPS'] = ENV['RUBYGEMS_GEMDEPS'], '-'382 FileUtils.mkdir_p 'detect/a/b'383 FileUtils.mkdir_p 'detect/a/Isolate'384 FileUtils.touch 'detect/Isolate'385 begin386 Dir.chdir 'detect/a/b'387 assert_equal add_bundler_full_name([]), Gem.use_gemdeps.map(&:full_name)388 ensure389 Dir.chdir @tempdir390 end391 ensure392 ENV['RUBYGEMS_GEMDEPS'] = rubygems_gemdeps393 end394 def test_self_dir395 assert_equal @gemhome, Gem.dir396 end397 def test_self_ensure_gem_directories398 FileUtils.rm_r @gemhome399 Gem.use_paths @gemhome400 Gem.ensure_gem_subdirectories @gemhome401 assert_path_exists File.join @gemhome, 'build_info'402 assert_path_exists File.join @gemhome, 'cache'403 assert_path_exists File.join @gemhome, 'doc'404 assert_path_exists File.join @gemhome, 'extensions'405 assert_path_exists File.join @gemhome, 'gems'406 assert_path_exists File.join @gemhome, 'specifications'407 end408 def test_self_ensure_gem_directories_permissions409 FileUtils.rm_r @gemhome410 Gem.use_paths @gemhome411 Gem.ensure_gem_subdirectories @gemhome, 0750412 assert File.directory? File.join(@gemhome, "cache")413 assert_equal 0750, File::Stat.new(@gemhome).mode & 0777414 assert_equal 0750, File::Stat.new(File.join(@gemhome, "cache")).mode & 0777415 end unless win_platform?416 def test_self_ensure_gem_directories_safe_permissions417 FileUtils.rm_r @gemhome418 Gem.use_paths @gemhome419 old_umask = File.umask420 File.umask 0421 Gem.ensure_gem_subdirectories @gemhome422 assert_equal 0, File::Stat.new(@gemhome).mode & 002423 assert_equal 0, File::Stat.new(File.join(@gemhome, "cache")).mode & 002424 ensure425 File.umask old_umask426 end unless win_platform?427 def test_self_ensure_gem_directories_missing_parents428 gemdir = File.join @tempdir, 'a/b/c/gemdir'429 FileUtils.rm_rf File.join(@tempdir, 'a') rescue nil430 refute File.exist?(File.join(@tempdir, 'a')),431 "manually remove #{File.join @tempdir, 'a'}, tests are broken"432 Gem.use_paths gemdir433 Gem.ensure_gem_subdirectories gemdir434 assert File.directory?(util_cache_dir)435 end436 unless win_platform? || Process.uid.zero? # only for FS that support write protection437 def test_self_ensure_gem_directories_write_protected438 gemdir = File.join @tempdir, "egd"439 FileUtils.rm_r gemdir rescue nil440 refute File.exist?(gemdir), "manually remove #{gemdir}, tests are broken"441 FileUtils.mkdir_p gemdir442 FileUtils.chmod 0400, gemdir443 Gem.use_paths gemdir444 Gem.ensure_gem_subdirectories gemdir445 refute File.exist?(util_cache_dir)446 ensure447 FileUtils.chmod 0600, gemdir448 end449 def test_self_ensure_gem_directories_write_protected_parents450 parent = File.join(@tempdir, "egd")451 gemdir = "#{parent}/a/b/c"452 FileUtils.rm_r parent rescue nil453 refute File.exist?(parent), "manually remove #{parent}, tests are broken"454 FileUtils.mkdir_p parent455 FileUtils.chmod 0400, parent456 Gem.use_paths(gemdir)457 Gem.ensure_gem_subdirectories gemdir458 refute File.exist? File.join(gemdir, "gems")459 ensure460 FileUtils.chmod 0600, parent461 end462 end463 def test_self_extension_dir_shared464 enable_shared 'yes' do465 assert_equal Gem.ruby_api_version, Gem.extension_api_version466 end467 end468 def test_self_extension_dir_static469 enable_shared 'no' do470 assert_equal "#{Gem.ruby_api_version}-static", Gem.extension_api_version471 end472 end473 def test_self_find_files474 cwd = File.expand_path("test/rubygems", @@project_dir)475 $LOAD_PATH.unshift cwd476 discover_path = File.join 'lib', 'sff', 'discover.rb'477 foo1, foo2 = %w(1 2).map { |version|478 spec = quick_gem 'sff', version do |s|479 s.files << discover_path480 end481 write_file(File.join 'gems', spec.full_name, discover_path) do |fp|482 fp.puts "# #{spec.full_name}"483 end484 spec485 }486 Gem.refresh487 expected = [488 File.expand_path('test/rubygems/sff/discover.rb', @@project_dir),489 File.join(foo2.full_gem_path, discover_path),490 File.join(foo1.full_gem_path, discover_path),491 ]492 assert_equal expected, Gem.find_files('sff/discover')493 assert_equal expected, Gem.find_files('sff/**.rb'), '[ruby-core:31730]'494 ensure495 assert_equal cwd, $LOAD_PATH.shift496 end497 def test_self_find_files_with_gemfile498 cwd = File.expand_path("test/rubygems", @@project_dir)499 actual_load_path = $LOAD_PATH.unshift(cwd).dup500 discover_path = File.join 'lib', 'sff', 'discover.rb'501 foo1, _ = %w(1 2).map { |version|502 spec = quick_gem 'sff', version do |s|503 s.files << discover_path504 end505 write_file(File.join 'gems', spec.full_name, discover_path) do |fp|506 fp.puts "# #{spec.full_name}"507 end508 spec509 }510 Gem.refresh511 write_file(File.join Dir.pwd, 'Gemfile') do |fp|512 fp.puts "source 'https://rubygems.org'"513 fp.puts "gem '#{foo1.name}', '#{foo1.version}'"514 end515 Gem.use_gemdeps(File.join Dir.pwd, 'Gemfile')516 expected = [517 File.expand_path('test/rubygems/sff/discover.rb', @@project_dir),518 File.join(foo1.full_gem_path, discover_path)519 ].sort520 assert_equal expected, Gem.find_files('sff/discover').sort521 assert_equal expected, Gem.find_files('sff/**.rb').sort, '[ruby-core:31730]'522 ensure523 assert_equal cwd, actual_load_path.shift524 end525 def test_self_find_latest_files526 cwd = File.expand_path("test/rubygems", @@project_dir)527 $LOAD_PATH.unshift cwd528 discover_path = File.join 'lib', 'sff', 'discover.rb'529 _, foo2 = %w(1 2).map { |version|530 spec = quick_gem 'sff', version do |s|531 s.files << discover_path532 end533 write_file(File.join 'gems', spec.full_name, discover_path) do |fp|534 fp.puts "# #{spec.full_name}"535 end536 spec537 }538 Gem.refresh539 expected = [540 File.expand_path('test/rubygems/sff/discover.rb', @@project_dir),541 File.join(foo2.full_gem_path, discover_path),542 ]543 assert_equal expected, Gem.find_latest_files('sff/discover')544 assert_equal expected, Gem.find_latest_files('sff/**.rb'), '[ruby-core:31730]'545 ensure546 assert_equal cwd, $LOAD_PATH.shift547 end548 def test_self_latest_spec_for549 gems = spec_fetcher do |fetcher|550 fetcher.spec 'a', 1551 fetcher.spec 'a', '3.a'552 fetcher.spec 'a', 2553 end554 spec = Gem.latest_spec_for 'a'555 assert_equal gems['a-2'], spec556 end557 def test_self_latest_rubygems_version558 spec_fetcher do |fetcher|559 fetcher.spec 'rubygems-update', '1.8.23'560 fetcher.spec 'rubygems-update', '1.8.24'561 fetcher.spec 'rubygems-update', '2.0.0.preview3'562 end563 version = Gem.latest_rubygems_version564 assert_equal Gem::Version.new('1.8.24'), version565 end566 def test_self_latest_version_for567 spec_fetcher do |fetcher|568 fetcher.spec 'a', 1569 fetcher.spec 'a', 2570 fetcher.spec 'a', '3.a'571 end572 version = Gem.latest_version_for 'a'573 assert_equal Gem::Version.new(2), version574 end575 def test_self_loaded_specs576 foo = util_spec 'foo'577 install_gem foo578 foo.activate579 assert_equal true, Gem.loaded_specs.keys.include?('foo')580 end581 def util_path582 ENV.delete "GEM_HOME"583 ENV.delete "GEM_PATH"584 end585 def test_self_path586 assert_equal [Gem.dir], Gem.path587 end588 def test_self_path_default589 util_path590 if defined?(APPLE_GEM_HOME)591 orig_APPLE_GEM_HOME = APPLE_GEM_HOME592 Object.send :remove_const, :APPLE_GEM_HOME593 end594 Gem.instance_variable_set :@paths, nil595 assert_equal [Gem.default_path, Gem.dir].flatten.uniq, Gem.path596 ensure597 Object.const_set :APPLE_GEM_HOME, orig_APPLE_GEM_HOME if orig_APPLE_GEM_HOME598 end599 unless win_platform?600 def test_self_path_APPLE_GEM_HOME601 util_path602 Gem.clear_paths603 apple_gem_home = File.join @tempdir, 'apple_gem_home'604 old, $-w = $-w, nil605 Object.const_set :APPLE_GEM_HOME, apple_gem_home606 $-w = old607 assert_includes Gem.path, apple_gem_home608 ensure609 Object.send :remove_const, :APPLE_GEM_HOME610 end611 def test_self_path_APPLE_GEM_HOME_GEM_PATH612 Gem.clear_paths613 ENV['GEM_PATH'] = @gemhome614 apple_gem_home = File.join @tempdir, 'apple_gem_home'615 Gem.const_set :APPLE_GEM_HOME, apple_gem_home616 refute Gem.path.include?(apple_gem_home)617 ensure618 Gem.send :remove_const, :APPLE_GEM_HOME619 end620 end621 def test_self_path_ENV_PATH622 path_count = Gem.path.size623 Gem.clear_paths624 ENV['GEM_PATH'] = @additional.join(File::PATH_SEPARATOR)625 assert_equal @additional, Gem.path[0,2]626 assert_equal path_count + @additional.size, Gem.path.size,627 "extra path components: #{Gem.path[2..-1].inspect}"628 assert_equal Gem.dir, Gem.path.last629 end630 def test_self_path_duplicate631 Gem.clear_paths632 util_ensure_gem_dirs633 dirs = @additional + [@gemhome] + [File.join(@tempdir, 'a')]634 ENV['GEM_HOME'] = @gemhome635 ENV['GEM_PATH'] = dirs.join File::PATH_SEPARATOR636 assert_equal @gemhome, Gem.dir637 paths = [Gem.dir]638 assert_equal @additional + paths, Gem.path639 end640 def test_self_path_overlap641 Gem.clear_paths642 util_ensure_gem_dirs643 ENV['GEM_HOME'] = @gemhome644 ENV['GEM_PATH'] = @additional.join(File::PATH_SEPARATOR)645 assert_equal @gemhome, Gem.dir646 paths = [Gem.dir]647 assert_equal @additional + paths, Gem.path648 end649 def test_self_platforms650 assert_equal [Gem::Platform::RUBY, Gem::Platform.local], Gem.platforms651 end652 def test_self_prefix653 assert_equal @@project_dir, Gem.prefix654 end655 def test_self_prefix_libdir656 orig_libdir = RbConfig::CONFIG['libdir']657 RbConfig::CONFIG['libdir'] = @@project_dir658 assert_nil Gem.prefix659 ensure660 RbConfig::CONFIG['libdir'] = orig_libdir661 end662 def test_self_prefix_sitelibdir663 orig_sitelibdir = RbConfig::CONFIG['sitelibdir']664 RbConfig::CONFIG['sitelibdir'] = @@project_dir665 assert_nil Gem.prefix666 ensure667 RbConfig::CONFIG['sitelibdir'] = orig_sitelibdir668 end669 def test_self_read_binary670 File.open 'test', 'w' do |io|671 io.write "\xCF\x80"672 end673 assert_equal ["\xCF", "\x80"], Gem.read_binary('test').chars.to_a674 skip 'chmod not supported' if Gem.win_platform?675 begin676 File.chmod 0444, 'test'677 assert_equal ["\xCF", "\x80"], Gem.read_binary('test').chars.to_a678 ensure679 File.chmod 0644, 'test'680 end681 end682 def test_self_refresh683 util_make_gems684 a1_spec = @a1.spec_file685 moved_path = File.join @tempdir, File.basename(a1_spec)686 FileUtils.mv a1_spec, moved_path687 Gem.refresh688 refute_includes Gem::Specification.all_names, @a1.full_name689 FileUtils.mv moved_path, a1_spec690 Gem.refresh691 assert_includes Gem::Specification.all_names, @a1.full_name692 end693 def test_self_refresh_keeps_loaded_specs_activated694 util_make_gems695 a1_spec = @a1.spec_file696 moved_path = File.join @tempdir, File.basename(a1_spec)697 FileUtils.mv a1_spec, moved_path698 Gem.refresh699 s = Gem::Specification.first700 s.activate701 Gem.refresh702 Gem::Specification.each{|spec| assert spec.activated? if spec == s}703 Gem.loaded_specs.delete(s)704 Gem.refresh705 end706 def test_self_ruby_escaping_spaces_in_path707 orig_ruby = Gem.ruby708 orig_bindir = RbConfig::CONFIG['bindir']709 orig_ruby_install_name = RbConfig::CONFIG['ruby_install_name']710 orig_exe_ext = RbConfig::CONFIG['EXEEXT']711 RbConfig::CONFIG['bindir'] = "C:/Ruby 1.8/bin"712 RbConfig::CONFIG['ruby_install_name'] = "ruby"713 RbConfig::CONFIG['EXEEXT'] = ".exe"714 Gem.instance_variable_set("@ruby", nil)715 assert_equal "\"C:/Ruby 1.8/bin/ruby.exe\"", Gem.ruby716 ensure717 Gem.instance_variable_set("@ruby", orig_ruby)718 RbConfig::CONFIG['bindir'] = orig_bindir719 RbConfig::CONFIG['ruby_install_name'] = orig_ruby_install_name720 RbConfig::CONFIG['EXEEXT'] = orig_exe_ext721 end722 def test_self_ruby_path_without_spaces723 orig_ruby = Gem.ruby724 orig_bindir = RbConfig::CONFIG['bindir']725 orig_ruby_install_name = RbConfig::CONFIG['ruby_install_name']726 orig_exe_ext = RbConfig::CONFIG['EXEEXT']727 RbConfig::CONFIG['bindir'] = "C:/Ruby18/bin"728 RbConfig::CONFIG['ruby_install_name'] = "ruby"729 RbConfig::CONFIG['EXEEXT'] = ".exe"730 Gem.instance_variable_set("@ruby", nil)731 assert_equal "C:/Ruby18/bin/ruby.exe", Gem.ruby732 ensure733 Gem.instance_variable_set("@ruby", orig_ruby)734 RbConfig::CONFIG['bindir'] = orig_bindir735 RbConfig::CONFIG['ruby_install_name'] = orig_ruby_install_name736 RbConfig::CONFIG['EXEEXT'] = orig_exe_ext737 end738 def test_self_ruby_api_version739 orig_ruby_version, RbConfig::CONFIG['ruby_version'] = RbConfig::CONFIG['ruby_version'], '1.2.3'740 Gem.instance_variable_set :@ruby_api_version, nil741 assert_equal '1.2.3', Gem.ruby_api_version742 ensure743 Gem.instance_variable_set :@ruby_api_version, nil744 RbConfig::CONFIG['ruby_version'] = orig_ruby_version745 end746 def test_self_env_requirement747 ENV["GEM_REQUIREMENT_FOO"] = '>= 1.2.3'748 ENV["GEM_REQUIREMENT_BAR"] = '1.2.3'749 ENV["GEM_REQUIREMENT_BAZ"] = 'abcd'750 assert_equal Gem::Requirement.create('>= 1.2.3'), Gem.env_requirement('foo')751 assert_equal Gem::Requirement.create('1.2.3'), Gem.env_requirement('bAr')752 assert_raises(Gem::Requirement::BadRequirementError) { Gem.env_requirement('baz') }753 assert_equal Gem::Requirement.default, Gem.env_requirement('qux')754 end755 def test_self_ruby_version_with_patchlevel_less_ancient_rubies756 util_set_RUBY_VERSION '1.8.5'757 assert_equal Gem::Version.new('1.8.5'), Gem.ruby_version758 ensure759 util_restore_RUBY_VERSION760 end761 def test_self_ruby_version_with_release762 util_set_RUBY_VERSION '1.8.6', 287763 assert_equal Gem::Version.new('1.8.6.287'), Gem.ruby_version764 ensure765 util_restore_RUBY_VERSION766 end767 def test_self_ruby_version_with_non_mri_implementations768 util_set_RUBY_VERSION '2.5.0', 0, 60928, 'jruby 9.2.0.0 (2.5.0) 2018-05-24 81156a8 OpenJDK 64-Bit Server VM 25.171-b11 on 1.8.0_171-8u171-b11-0ubuntu0.16.04.1-b11 [linux-x86_64]'769 assert_equal Gem::Version.new('2.5.0'), Gem.ruby_version770 ensure771 util_restore_RUBY_VERSION772 end773 def test_self_ruby_version_with_prerelease774 util_set_RUBY_VERSION '2.6.0', -1, 63539, 'ruby 2.6.0preview2 (2018-05-31 trunk 63539) [x86_64-linux]'775 assert_equal Gem::Version.new('2.6.0.preview2'), Gem.ruby_version776 ensure777 util_restore_RUBY_VERSION778 end779 def test_self_ruby_version_with_non_mri_implementations_with_mri_prerelase_compatibility780 util_set_RUBY_VERSION '2.6.0', -1, 63539, 'weirdjruby 9.2.0.0 (2.6.0preview2) 2018-05-24 81156a8 OpenJDK 64-Bit Server VM 25.171-b11 on 1.8.0_171-8u171-b11-0ubuntu0.16.04.1-b11 [linux-x86_64]', 'weirdjruby', '9.2.0.0'781 assert_equal Gem::Version.new('2.6.0.preview2'), Gem.ruby_version782 ensure783 util_restore_RUBY_VERSION784 end785 def test_self_ruby_version_with_trunk786 util_set_RUBY_VERSION '1.9.2', -1, 23493, 'ruby 1.9.2dev (2009-05-20 trunk 23493) [x86_64-linux]'787 assert_equal Gem::Version.new('1.9.2.dev'), Gem.ruby_version788 ensure789 util_restore_RUBY_VERSION790 end791 def test_self_rubygems_version792 assert_equal Gem::Version.new(Gem::VERSION), Gem.rubygems_version793 end794 def test_self_paths_eq795 other = File.join @tempdir, 'other'796 path = [@userhome, other].join File::PATH_SEPARATOR797 #798 # FIXME remove after fixing test_case799 #800 ENV["GEM_HOME"] = @gemhome801 Gem.paths = { "GEM_PATH" => path }802 assert_equal [@userhome, other, @gemhome], Gem.path803 end804 def test_self_paths_eq_nonexistent_home805 ENV['GEM_HOME'] = @gemhome806 Gem.clear_paths807 other = File.join @tempdir, 'other'808 ENV['HOME'] = other809 Gem.paths = { "GEM_PATH" => other }810 assert_equal [other, @gemhome], Gem.path811 end812 def test_self_post_build813 assert_equal 1, Gem.post_build_hooks.length814 Gem.post_build do |installer| end815 assert_equal 2, Gem.post_build_hooks.length816 end817 def test_self_post_install818 assert_equal 1, Gem.post_install_hooks.length819 Gem.post_install do |installer| end820 assert_equal 2, Gem.post_install_hooks.length821 end822 def test_self_done_installing823 assert_empty Gem.done_installing_hooks824 Gem.done_installing do |gems| end825 assert_equal 1, Gem.done_installing_hooks.length826 end827 def test_self_post_reset828 assert_empty Gem.post_reset_hooks829 Gem.post_reset { }830 assert_equal 1, Gem.post_reset_hooks.length831 end832 def test_self_post_uninstall833 assert_equal 1, Gem.post_uninstall_hooks.length834 Gem.post_uninstall do |installer| end835 assert_equal 2, Gem.post_uninstall_hooks.length836 end837 def test_self_pre_install838 assert_equal 1, Gem.pre_install_hooks.length839 Gem.pre_install do |installer| end840 assert_equal 2, Gem.pre_install_hooks.length841 end842 def test_self_pre_reset843 assert_empty Gem.pre_reset_hooks844 Gem.pre_reset { }845 assert_equal 1, Gem.pre_reset_hooks.length846 end847 def test_self_pre_uninstall848 assert_equal 1, Gem.pre_uninstall_hooks.length849 Gem.pre_uninstall do |installer| end850 assert_equal 2, Gem.pre_uninstall_hooks.length851 end852 def test_self_sources853 assert_equal %w[http://gems.example.com/], Gem.sources854 Gem.sources = nil855 Gem.configuration.sources = %w[http://test.example.com/]856 assert_equal %w[http://test.example.com/], Gem.sources857 end858 def test_try_activate_returns_true_for_activated_specs859 b = util_spec 'b', '1.0' do |spec|860 spec.files << 'lib/b.rb'861 end862 install_specs b863 assert Gem.try_activate('b'), 'try_activate should return true'864 assert Gem.try_activate('b'), 'try_activate should still return true'865 end866 def test_spec_order_is_consistent867 b1 = util_spec 'b', '1.0'868 b2 = util_spec 'b', '2.0'869 b3 = util_spec 'b', '3.0'870 install_specs b1, b2, b3871 specs1 = Gem::Specification.stubs.find_all { |s| s.name == 'b' }872 Gem::Specification.reset873 specs2 = Gem::Specification.stubs_for('b')874 assert_equal specs1.map(&:version), specs2.map(&:version)875 end876 def test_self_try_activate_missing_dep877 b = util_spec 'b', '1.0'878 a = util_spec 'a', '1.0', 'b' => '>= 1.0'879 install_specs b, a880 uninstall_gem b881 a_file = File.join a.gem_dir, 'lib', 'a_file.rb'882 write_file a_file do |io|883 io.puts '# a_file.rb'884 end885 e = assert_raises Gem::MissingSpecError do886 Gem.try_activate 'a_file'887 end888 assert_match %r%Could not find 'b' %, e.message889 end890 def test_self_try_activate_missing_prerelease891 b = util_spec 'b', '1.0rc1'892 a = util_spec 'a', '1.0rc1', 'b' => '1.0rc1'893 install_specs b, a894 uninstall_gem b895 a_file = File.join a.gem_dir, 'lib', 'a_file.rb'896 write_file a_file do |io|897 io.puts '# a_file.rb'898 end899 e = assert_raises Gem::MissingSpecError do900 Gem.try_activate 'a_file'901 end902 assert_match %r%Could not find 'b' \(= 1.0rc1\)%, e.message903 end904 def test_self_try_activate_missing_extensions905 spec = util_spec 'ext', '1' do |s|906 s.extensions = %w[ext/extconf.rb]907 s.mark_version908 s.installed_by_version = v('2.2')909 end910 # write the spec without install to simulate a failed install911 write_file spec.spec_file do |io|912 io.write spec.to_ruby_for_cache913 end914 _, err = capture_io do915 refute Gem.try_activate 'nonexistent'916 end917 expected = "Ignoring ext-1 because its extensions are not built. " +918 "Try: gem pristine ext --version 1\n"919 assert_equal expected, err920 end921 def test_self_use_paths_with_nils922 orig_home = ENV.delete 'GEM_HOME'923 orig_path = ENV.delete 'GEM_PATH'924 Gem.use_paths nil, nil925 assert_equal Gem.default_dir, Gem.paths.home926 path = (Gem.default_path + [Gem.paths.home]).uniq927 assert_equal path, Gem.paths.path928 ensure929 ENV['GEM_HOME'] = orig_home930 ENV['GEM_PATH'] = orig_path931 end932 def test_setting_paths_does_not_warn_about_unknown_keys933 stdout, stderr = capture_io do934 Gem.paths = { 'foo' => [],935 'bar' => Object.new,936 'GEM_HOME' => Gem.paths.home,937 'GEM_PATH' => 'foo' }938 end939 assert_equal ['foo', Gem.paths.home], Gem.paths.path940 assert_equal '', stderr941 assert_equal '', stdout942 end943 def test_setting_paths_does_not_mutate_parameter_object944 Gem.paths = { 'GEM_HOME' => Gem.paths.home,945 'GEM_PATH' => 'foo' }.freeze946 assert_equal ['foo', Gem.paths.home], Gem.paths.path947 end948 def test_deprecated_paths=949 stdout, stderr = capture_io do950 Gem.paths = { 'GEM_HOME' => Gem.paths.home,951 'GEM_PATH' => [Gem.paths.home, 'foo'] }952 end953 assert_equal [Gem.paths.home, 'foo'], Gem.paths.path954 assert_match(/Array values in the parameter to `Gem.paths=` are deprecated.\nPlease use a String or nil/m, stderr)955 assert_equal '', stdout956 end957 def test_self_use_paths958 util_ensure_gem_dirs959 Gem.use_paths @gemhome, @additional960 assert_equal @gemhome, Gem.dir961 assert_equal @additional + [Gem.dir], Gem.path962 end963 def test_self_user_dir964 parts = [@userhome, '.gem', Gem.ruby_engine]965 parts << RbConfig::CONFIG['ruby_version'] unless RbConfig::CONFIG['ruby_version'].empty?966 assert_equal File.join(parts), Gem.user_dir967 end968 def test_self_user_home969 if ENV['HOME']970 assert_equal ENV['HOME'], Gem.user_home971 else972 assert true, 'count this test'973 end974 end975 def test_self_needs976 util_clear_gems977 a = util_spec "a", "1"978 b = util_spec "b", "1", "c" => nil979 c = util_spec "c", "2"980 install_specs a, c, b981 Gem.needs do |r|982 r.gem "a"983 r.gem "b", "= 1"984 end985 activated = Gem::Specification.map { |x| x.full_name }986 assert_equal %w!a-1 b-1 c-2!, activated.sort987 end988 def test_self_needs_picks_up_unresolved_deps989 save_loaded_features do990 util_clear_gems991 a = util_spec "a", "1"992 b = util_spec "b", "1", "c" => nil993 c = util_spec "c", "2"994 d = util_spec "d", "1", {'e' => '= 1'}, "lib/d.rb"995 e = util_spec "e", "1"996 install_specs a, c, b, e, d997 Gem.needs do |r|998 r.gem "a"999 r.gem "b", "= 1"1000 require 'd'1001 end1002 assert_equal %w!a-1 b-1 c-2 d-1 e-1!, loaded_spec_names1003 end1004 end1005 def test_self_gunzip1006 input = "\x1F\x8B\b\0\xED\xA3\x1AQ\0\x03\xCBH" +1007 "\xCD\xC9\xC9\a\0\x86\xA6\x106\x05\0\0\0"1008 output = Gem::Util.gunzip input1009 assert_equal 'hello', output1010 assert_equal Encoding::BINARY, output.encoding1011 end1012 def test_self_gzip1013 input = 'hello'1014 output = Gem::Util.gzip input1015 zipped = StringIO.new output1016 assert_equal 'hello', Zlib::GzipReader.new(zipped).read1017 assert_equal Encoding::BINARY, output.encoding1018 end1019 def test_self_vendor_dir1020 expected =1021 File.join RbConfig::CONFIG['vendordir'], 'gems',1022 RbConfig::CONFIG['ruby_version']1023 assert_equal expected, Gem.vendor_dir1024 end1025 def test_self_vendor_dir_ENV_GEM_VENDOR1026 ENV['GEM_VENDOR'] = File.join @tempdir, 'vendor', 'gems'1027 assert_equal ENV['GEM_VENDOR'], Gem.vendor_dir1028 refute Gem.vendor_dir.frozen?1029 end1030 def test_self_vendor_dir_missing1031 orig_vendordir = RbConfig::CONFIG['vendordir']1032 RbConfig::CONFIG.delete 'vendordir'1033 assert_nil Gem.vendor_dir1034 ensure1035 RbConfig::CONFIG['vendordir'] = orig_vendordir1036 end1037 def test_load_plugins1038 plugin_path = File.join "lib", "rubygems_plugin.rb"1039 Dir.chdir @tempdir do1040 FileUtils.mkdir_p 'lib'1041 File.open plugin_path, "w" do |fp|1042 fp.puts "class TestGem; PLUGINS_LOADED << 'plugin'; end"1043 end1044 foo1 = util_spec 'foo', '1' do |s|1045 s.files << plugin_path1046 end1047 install_gem foo11048 foo2 = util_spec 'foo', '2' do |s|1049 s.files << plugin_path1050 end1051 install_gem foo21052 end1053 Gem.searcher = nil1054 Gem::Specification.reset1055 gem 'foo'1056 Gem.load_plugins1057 assert_equal %w[plugin], PLUGINS_LOADED1058 end1059 def test_load_env_plugins1060 with_plugin('load') { Gem.load_env_plugins }1061 assert_equal :loaded, TEST_PLUGIN_LOAD rescue nil1062 util_remove_interrupt_command1063 # Should attempt to cause a StandardError1064 with_plugin('standarderror') { Gem.load_env_plugins }1065 assert_equal :loaded, TEST_PLUGIN_STANDARDERROR rescue nil1066 util_remove_interrupt_command1067 # Should attempt to cause an Exception1068 with_plugin('exception') { Gem.load_env_plugins }1069 assert_equal :loaded, TEST_PLUGIN_EXCEPTION rescue nil1070 end1071 def test_gem_path_ordering1072 refute_equal Gem.dir, Gem.user_dir1073 write_file File.join(@tempdir, 'lib', "g.rb") { |fp| fp.puts "" }1074 write_file File.join(@tempdir, 'lib', 'm.rb') { |fp| fp.puts "" }1075 g = util_spec 'g', '1', nil, "lib/g.rb"1076 m = util_spec 'm', '1', nil, "lib/m.rb"1077 install_gem g, :install_dir => Gem.dir1078 m0 = install_gem m, :install_dir => Gem.dir1079 m1 = install_gem m, :install_dir => Gem.user_dir1080 assert_equal m0.gem_dir, File.join(Gem.dir, "gems", "m-1")1081 assert_equal m1.gem_dir, File.join(Gem.user_dir, "gems", "m-1")1082 tests = [1083 [:dir0, [ Gem.dir, Gem.user_dir], m0],1084 [:dir1, [ Gem.user_dir, Gem.dir], m1]1085 ]1086 tests.each do |_name, _paths, expected|1087 Gem.use_paths _paths.first, _paths1088 Gem::Specification.reset1089 Gem.searcher = nil1090 assert_equal Gem::Dependency.new('m','1').to_specs,1091 Gem::Dependency.new('m','1').to_specs.sort1092 assert_equal \1093 [expected.gem_dir],1094 Gem::Dependency.new('m','1').to_specs.map(&:gem_dir).sort,1095 "Wrong specs for #{_name}"1096 spec = Gem::Dependency.new('m','1').to_spec1097 assert_equal \1098 File.join(_paths.first, "gems", "m-1"),1099 spec.gem_dir,1100 "Wrong spec before require for #{_name}"1101 refute spec.activated?, "dependency already activated for #{_name}"1102 gem "m"1103 spec = Gem::Dependency.new('m','1').to_spec1104 assert spec.activated?, "dependency not activated for #{_name}"1105 assert_equal \1106 File.join(_paths.first, "gems", "m-1"),1107 spec.gem_dir,1108 "Wrong spec after require for #{_name}"1109 spec.instance_variable_set :@activated, false1110 Gem.loaded_specs.delete(spec.name)1111 $:.delete(File.join(spec.gem_dir, "lib"))1112 end1113 end1114 def test_gem_path_ordering_short1115 write_file File.join(@tempdir, 'lib', "g.rb") { |fp| fp.puts "" }1116 write_file File.join(@tempdir, 'lib', 'm.rb') { |fp| fp.puts "" }1117 g = util_spec 'g', '1', nil, "lib/g.rb"1118 m = util_spec 'm', '1', nil, "lib/m.rb"1119 install_gem g, :install_dir => Gem.dir1120 install_gem m, :install_dir => Gem.dir1121 install_gem m, :install_dir => Gem.user_dir1122 Gem.use_paths Gem.dir, [ Gem.dir, Gem.user_dir]1123 assert_equal \1124 File.join(Gem.dir, "gems", "m-1"),1125 Gem::Dependency.new('m','1').to_spec.gem_dir,1126 "Wrong spec selected"1127 end1128 def test_auto_activation_of_specific_gemdeps_file1129 util_clear_gems1130 a = util_spec "a", "1", nil, "lib/a.rb"1131 b = util_spec "b", "1", nil, "lib/b.rb"1132 c = util_spec "c", "1", nil, "lib/c.rb"1133 install_specs a, b, c1134 path = File.join @tempdir, "gem.deps.rb"1135 File.open path, "w" do |f|1136 f.puts "gem 'a'"1137 f.puts "gem 'b'"1138 f.puts "gem 'c'"1139 end1140 ENV['RUBYGEMS_GEMDEPS'] = path1141 Gem.use_gemdeps1142 assert_equal add_bundler_full_name(%W(a-1 b-1 c-1)), loaded_spec_names1143 end1144 def test_auto_activation_of_used_gemdeps_file1145 util_clear_gems1146 a = util_spec "a", "1", nil, "lib/a.rb"1147 b = util_spec "b", "1", nil, "lib/b.rb"1148 c = util_spec "c", "1", nil, "lib/c.rb"1149 install_specs a, b, c1150 path = File.join @tempdir, "gem.deps.rb"1151 File.open path, "w" do |f|1152 f.puts "gem 'a'"1153 f.puts "gem 'b'"1154 f.puts "gem 'c'"1155 end1156 ENV['RUBYGEMS_GEMDEPS'] = "-"1157 expected_specs = [a, b, (Gem::USE_BUNDLER_FOR_GEMDEPS || nil) && util_spec("bundler", Bundler::VERSION), c].compact1158 assert_equal expected_specs, Gem.use_gemdeps.sort_by { |s| s.name }1159 end1160 LIB_PATH = File.expand_path "../../../lib".dup.untaint, __FILE__.dup.untaint1161 if Gem::USE_BUNDLER_FOR_GEMDEPS1162 BUNDLER_LIB_PATH = File.expand_path $LOAD_PATH.find {|lp| File.file?(File.join(lp, "bundler.rb")) }.dup.untaint1163 BUNDLER_FULL_NAME = "bundler-#{Bundler::VERSION}".freeze1164 end1165 def add_bundler_full_name(names)1166 return names unless Gem::USE_BUNDLER_FOR_GEMDEPS1167 names << BUNDLER_FULL_NAME1168 names.sort!1169 names1170 end1171 def test_looks_for_gemdeps_files_automatically_on_start1172 util_clear_gems1173 a = util_spec "a", "1", nil, "lib/a.rb"1174 b = util_spec "b", "1", nil, "lib/b.rb"1175 c = util_spec "c", "1", nil, "lib/c.rb"1176 install_specs a, b, c1177 path = File.join(@tempdir, "gd-tmp")1178 install_gem a, :install_dir => path1179 install_gem b, :install_dir => path1180 install_gem c, :install_dir => path1181 ENV['GEM_PATH'] = path1182 ENV['RUBYGEMS_GEMDEPS'] = "-"1183 path = File.join @tempdir, "gem.deps.rb"1184 cmd = [Gem.ruby.dup.untaint, "-I#{LIB_PATH.untaint}",1185 "-I#{BUNDLER_LIB_PATH.untaint}", "-rrubygems"]1186 cmd << "-eputs Gem.loaded_specs.values.map(&:full_name).sort"1187 File.open path, "w" do |f|1188 f.puts "gem 'a'"1189 end1190 out0 = IO.popen(cmd, &:read).split(/\n/)1191 File.open path, "a" do |f|1192 f.puts "gem 'b'"1193 f.puts "gem 'c'"1194 end1195 out = IO.popen(cmd, &:read).split(/\n/)1196 assert_equal ["b-1", "c-1"], out - out01197 end if Gem::USE_BUNDLER_FOR_GEMDEPS1198 def test_looks_for_gemdeps_files_automatically_on_start_in_parent_dir1199 util_clear_gems1200 a = util_spec "a", "1", nil, "lib/a.rb"1201 b = util_spec "b", "1", nil, "lib/b.rb"1202 c = util_spec "c", "1", nil, "lib/c.rb"1203 install_specs a, b, c1204 path = File.join(@tempdir, "gd-tmp")1205 install_gem a, :install_dir => path1206 install_gem b, :install_dir => path1207 install_gem c, :install_dir => path1208 ENV['GEM_PATH'] = path1209 ENV['RUBYGEMS_GEMDEPS'] = "-"1210 Dir.mkdir "sub1"1211 path = File.join @tempdir, "gem.deps.rb"1212 cmd = [Gem.ruby.dup.untaint, "-Csub1", "-I#{LIB_PATH.untaint}",1213 "-I#{BUNDLER_LIB_PATH.untaint}", "-rrubygems"]1214 cmd << "-eputs Gem.loaded_specs.values.map(&:full_name).sort"1215 File.open path, "w" do |f|1216 f.puts "gem 'a'"1217 end1218 out0 = IO.popen(cmd, &:read).split(/\n/)1219 File.open path, "a" do |f|1220 f.puts "gem 'b'"1221 f.puts "gem 'c'"1222 end1223 out = IO.popen(cmd, &:read).split(/\n/)1224 Dir.rmdir "sub1"1225 assert_equal ["b-1", "c-1"], out - out01226 end if Gem::USE_BUNDLER_FOR_GEMDEPS1227 def test_register_default_spec1228 Gem.clear_default_specs1229 old_style = Gem::Specification.new do |spec|1230 spec.files = ["foo.rb", "bar.rb"]1231 end1232 Gem.register_default_spec old_style1233 assert_equal old_style, Gem.find_unresolved_default_spec("foo.rb")1234 assert_equal old_style, Gem.find_unresolved_default_spec("bar.rb")1235 assert_nil Gem.find_unresolved_default_spec("baz.rb")1236 Gem.clear_default_specs1237 new_style = Gem::Specification.new do |spec|1238 spec.files = ["lib/foo.rb", "ext/bar.rb", "bin/exec", "README"]1239 spec.require_paths = ["lib", "ext"]1240 end1241 Gem.register_default_spec new_style1242 assert_equal new_style, Gem.find_unresolved_default_spec("foo.rb")1243 assert_equal new_style, Gem.find_unresolved_default_spec("bar.rb")1244 assert_nil Gem.find_unresolved_default_spec("exec")1245 assert_nil Gem.find_unresolved_default_spec("README")1246 end1247 def test_default_gems_use_full_paths1248 begin1249 if defined?(RUBY_ENGINE)1250 engine = RUBY_ENGINE1251 Object.send :remove_const, :RUBY_ENGINE1252 end1253 Object.const_set :RUBY_ENGINE, 'ruby'1254 refute Gem.default_gems_use_full_paths?1255 ensure1256 Object.send :remove_const, :RUBY_ENGINE1257 Object.const_set :RUBY_ENGINE, engine if engine1258 end1259 begin1260 if defined?(RUBY_ENGINE)1261 engine = RUBY_ENGINE1262 Object.send :remove_const, :RUBY_ENGINE1263 end1264 Object.const_set :RUBY_ENGINE, 'jruby'1265 assert Gem.default_gems_use_full_paths?1266 ensure1267 Object.send :remove_const, :RUBY_ENGINE1268 Object.const_set :RUBY_ENGINE, engine if engine1269 end1270 end1271 def test_use_gemdeps1272 gem_deps_file = 'gem.deps.rb'.untaint1273 spec = util_spec 'a', 11274 install_specs spec1275 spec = Gem::Specification.find { |s| s == spec }1276 refute spec.activated?1277 File.open gem_deps_file, 'w' do |io|1278 io.write 'gem "a"'1279 end1280 assert_nil Gem.gemdeps1281 Gem.use_gemdeps gem_deps_file1282 assert_equal add_bundler_full_name(%W(a-1)), loaded_spec_names1283 refute_nil Gem.gemdeps1284 end1285 def test_use_gemdeps_ENV1286 rubygems_gemdeps, ENV['RUBYGEMS_GEMDEPS'] = ENV['RUBYGEMS_GEMDEPS'], nil1287 spec = util_spec 'a', 11288 refute spec.activated?1289 File.open 'gem.deps.rb', 'w' do |io|1290 io.write 'gem "a"'1291 end1292 Gem.use_gemdeps1293 refute spec.activated?1294 ensure1295 ENV['RUBYGEMS_GEMDEPS'] = rubygems_gemdeps1296 end1297 def test_use_gemdeps_argument_missing1298 e = assert_raises ArgumentError do1299 Gem.use_gemdeps 'gem.deps.rb'1300 end1301 assert_equal 'Unable to find gem dependencies file at gem.deps.rb',1302 e.message1303 end1304 def test_use_gemdeps_argument_missing_match_ENV1305 rubygems_gemdeps, ENV['RUBYGEMS_GEMDEPS'] =1306 ENV['RUBYGEMS_GEMDEPS'], 'gem.deps.rb'1307 e = assert_raises ArgumentError do1308 Gem.use_gemdeps 'gem.deps.rb'1309 end1310 assert_equal 'Unable to find gem dependencies file at gem.deps.rb',1311 e.message1312 ensure1313 ENV['RUBYGEMS_GEMDEPS'] = rubygems_gemdeps1314 end1315 def test_use_gemdeps_automatic1316 rubygems_gemdeps, ENV['RUBYGEMS_GEMDEPS'] = ENV['RUBYGEMS_GEMDEPS'], '-'1317 spec = util_spec 'a', 11318 install_specs spec1319 spec = Gem::Specification.find { |s| s == spec }1320 refute spec.activated?1321 File.open 'Gemfile', 'w' do |io|1322 io.write 'gem "a"'1323 end1324 Gem.use_gemdeps1325 assert_equal add_bundler_full_name(%W(a-1)), loaded_spec_names1326 ensure1327 ENV['RUBYGEMS_GEMDEPS'] = rubygems_gemdeps1328 end1329 def test_use_gemdeps_automatic_missing1330 rubygems_gemdeps, ENV['RUBYGEMS_GEMDEPS'] = ENV['RUBYGEMS_GEMDEPS'], '-'1331 Gem.use_gemdeps1332 assert true # count1333 ensure1334 ENV['RUBYGEMS_GEMDEPS'] = rubygems_gemdeps1335 end1336 def test_use_gemdeps_disabled1337 rubygems_gemdeps, ENV['RUBYGEMS_GEMDEPS'] = ENV['RUBYGEMS_GEMDEPS'], ''1338 spec = util_spec 'a', 11339 refute spec.activated?1340 File.open 'gem.deps.rb', 'w' do |io|1341 io.write 'gem "a"'1342 end1343 Gem.use_gemdeps1344 refute spec.activated?1345 ensure1346 ENV['RUBYGEMS_GEMDEPS'] = rubygems_gemdeps1347 end1348 def test_use_gemdeps_missing_gem1349 rubygems_gemdeps, ENV['RUBYGEMS_GEMDEPS'] = ENV['RUBYGEMS_GEMDEPS'], 'x'1350 File.open 'x', 'w' do |io|1351 io.write 'gem "a"'1352 end1353 platform = Bundler::GemHelpers.generic_local_platform1354 if platform == Gem::Platform::RUBY1355 platform = ''1356 else1357 platform = " #{platform}"1358 end1359 expected =1360 if Gem::USE_BUNDLER_FOR_GEMDEPS1361 <<-EXPECTED1362Could not find gem 'a#{platform}' in any of the gem sources listed in your Gemfile.1363You may need to `gem install -g` to install missing gems1364 EXPECTED1365 else1366 <<-EXPECTED1367Unable to resolve dependency: user requested 'a (>= 0)'1368You may need to `gem install -g` to install missing gems1369 EXPECTED1370 end1371 assert_output nil, expected do1372 Gem.use_gemdeps1373 end1374 ensure1375 ENV['RUBYGEMS_GEMDEPS'] = rubygems_gemdeps1376 end if Gem::USE_BUNDLER_FOR_GEMDEPS1377 def test_use_gemdeps_specific1378 rubygems_gemdeps, ENV['RUBYGEMS_GEMDEPS'] = ENV['RUBYGEMS_GEMDEPS'], 'x'1379 spec = util_spec 'a', 11380 install_specs spec1381 spec = Gem::Specification.find { |s| s == spec }1382 refute spec.activated?1383 File.open 'x', 'w' do |io|1384 io.write 'gem "a"'1385 end1386 Gem.use_gemdeps1387 assert_equal add_bundler_full_name(%W(a-1)), loaded_spec_names1388 ensure1389 ENV['RUBYGEMS_GEMDEPS'] = rubygems_gemdeps1390 end1391 def test_operating_system_defaults1392 operating_system_defaults = Gem.operating_system_defaults1393 assert operating_system_defaults != nil1394 assert operating_system_defaults.is_a? Hash1395 end1396 def test_platform_defaults1397 platform_defaults = Gem.platform_defaults1398 assert platform_defaults != nil1399 assert platform_defaults.is_a? Hash1400 end1401 def ruby_install_name(name)1402 orig_RUBY_INSTALL_NAME = RbConfig::CONFIG['ruby_install_name']1403 RbConfig::CONFIG['ruby_install_name'] = name1404 yield1405 ensure1406 if orig_RUBY_INSTALL_NAME1407 RbConfig::CONFIG['ruby_install_name'] = orig_RUBY_INSTALL_NAME1408 else1409 RbConfig::CONFIG.delete 'ruby_install_name'1410 end1411 end1412 def with_plugin(path)1413 test_plugin_path = File.expand_path("test/rubygems/plugin/#{path}",1414 @@project_dir)1415 # A single test plugin should get loaded once only, in order to preserve1416 # sane test semantics.1417 refute_includes $LOAD_PATH, test_plugin_path1418 $LOAD_PATH.unshift test_plugin_path1419 capture_io do1420 yield1421 end1422 ensure1423 $LOAD_PATH.delete test_plugin_path1424 end1425 def util_ensure_gem_dirs1426 Gem.ensure_gem_subdirectories @gemhome1427 #1428 # FIXME what does this solve precisely? -ebh1429 #1430 @additional.each do |dir|1431 Gem.ensure_gem_subdirectories @gemhome1432 end1433 end1434 def util_exec_gem1435 spec, _ = util_spec 'a', '4' do |s|1436 s.executables = ['exec', 'abin']1437 end1438 @exec_path = File.join spec.full_gem_path, spec.bindir, 'exec'1439 @abin_path = File.join spec.full_gem_path, spec.bindir, 'abin'1440 spec1441 end1442 def util_remove_interrupt_command1443 Gem::Commands.send :remove_const, :InterruptCommand if1444 Gem::Commands.const_defined? :InterruptCommand1445 end1446 def util_cache_dir1447 File.join Gem.dir, "cache"1448 end1449end...

Full Screen

Full Screen

newgem_spec.rb

Source:newgem_spec.rb Github

copy

Full Screen

2RSpec.describe "bundle gem" do3 def reset!4 super5 global_config "BUNDLE_GEM__MIT" => "false", "BUNDLE_GEM__TEST" => "false", "BUNDLE_GEM__COC" => "false"6 end7 def remove_push_guard(gem_name)8 # Remove exception that prevents public pushes on older RubyGems versions9 if Gem::Version.new(Gem::VERSION) < Gem::Version.new("2.0")10 path = "#{gem_name}/#{gem_name}.gemspec"11 content = File.read(path).sub(/raise "RubyGems 2\.0 or newer.*/, "")12 File.open(path, "w") {|f| f.write(content) }13 end14 end15 def execute_bundle_gem(gem_name, flag = "", to_remove_push_guard = true)16 bundle! "gem #{gem_name} #{flag}"17 remove_push_guard(gem_name) if to_remove_push_guard18 # reset gemspec cache for each test because of commit 3d4163a19 Bundler.clear_gemspec_cache20 end21 def gem_skeleton_assertions(gem_name)22 expect(bundled_app("#{gem_name}/#{gem_name}.gemspec")).to exist23 expect(bundled_app("#{gem_name}/README.md")).to exist24 expect(bundled_app("#{gem_name}/Gemfile")).to exist25 expect(bundled_app("#{gem_name}/Rakefile")).to exist26 expect(bundled_app("#{gem_name}/lib/test/gem.rb")).to exist27 expect(bundled_app("#{gem_name}/lib/test/gem/version.rb")).to exist28 end29 before do30 git_config_content = <<-EOF31 [user]32 name = "Bundler User"33 email = user@example.com34 [github]35 user = bundleuser36 EOF37 @git_config_location = ENV["GIT_CONFIG"]38 path = "#{File.expand_path(tmp, File.dirname(__FILE__))}/test_git_config.txt"39 File.open(path, "w") {|f| f.write(git_config_content) }40 ENV["GIT_CONFIG"] = path41 end42 after do43 FileUtils.rm(ENV["GIT_CONFIG"]) if File.exist?(ENV["GIT_CONFIG"])44 ENV["GIT_CONFIG"] = @git_config_location45 end46 shared_examples_for "git config is present" do47 context "git config user.{name,email} present" do48 it "sets gemspec author to git user.name if available" do49 expect(generated_gem.gemspec.authors.first).to eq("Bundler User")50 end51 it "sets gemspec email to git user.email if available" do52 expect(generated_gem.gemspec.email.first).to eq("user@example.com")53 end54 end55 end56 shared_examples_for "git config is absent" do57 it "sets gemspec author to default message if git user.name is not set or empty" do58 expect(generated_gem.gemspec.authors.first).to eq("TODO: Write your name")59 end60 it "sets gemspec email to default message if git user.email is not set or empty" do61 expect(generated_gem.gemspec.email.first).to eq("TODO: Write your email address")62 end63 end64 shared_examples_for "--mit flag" do65 before do66 execute_bundle_gem(gem_name, "--mit")67 end68 it "generates a gem skeleton with MIT license" do69 gem_skeleton_assertions(gem_name)70 expect(bundled_app("test-gem/LICENSE.txt")).to exist71 skel = Bundler::GemHelper.new(bundled_app(gem_name).to_s)72 expect(skel.gemspec.license).to eq("MIT")73 end74 end75 shared_examples_for "--no-mit flag" do76 before do77 execute_bundle_gem(gem_name, "--no-mit")78 end79 it "generates a gem skeleton without MIT license" do80 gem_skeleton_assertions(gem_name)81 expect(bundled_app("test-gem/LICENSE.txt")).to_not exist82 end83 end84 shared_examples_for "--coc flag" do85 before do86 execute_bundle_gem(gem_name, "--coc", false)87 end88 it "generates a gem skeleton with MIT license" do89 gem_skeleton_assertions(gem_name)90 expect(bundled_app("test-gem/CODE_OF_CONDUCT.md")).to exist91 end92 describe "README additions" do93 it "generates the README with a section for the Code of Conduct" do94 expect(bundled_app("test-gem/README.md").read).to include("## Code of Conduct")95 expect(bundled_app("test-gem/README.md").read).to include("https://github.com/bundleuser/#{gem_name}/blob/master/CODE_OF_CONDUCT.md")96 end97 end98 end99 shared_examples_for "--no-coc flag" do100 before do101 execute_bundle_gem(gem_name, "--no-coc", false)102 end103 it "generates a gem skeleton without Code of Conduct" do104 gem_skeleton_assertions(gem_name)105 expect(bundled_app("test-gem/CODE_OF_CONDUCT.md")).to_not exist106 end107 describe "README additions" do108 it "generates the README without a section for the Code of Conduct" do109 expect(bundled_app("test-gem/README.md").read).not_to include("## Code of Conduct")110 expect(bundled_app("test-gem/README.md").read).not_to include("https://github.com/bundleuser/#{gem_name}/blob/master/CODE_OF_CONDUCT.md")111 end112 end113 end114 context "README.md" do115 let(:gem_name) { "test_gem" }116 let(:generated_gem) { Bundler::GemHelper.new(bundled_app(gem_name).to_s) }117 context "git config github.user present" do118 before do119 execute_bundle_gem(gem_name)120 end121 it "contribute URL set to git username" do122 expect(bundled_app("test_gem/README.md").read).not_to include("[USERNAME]")123 expect(bundled_app("test_gem/README.md").read).to include("github.com/bundleuser")124 end125 end126 context "git config github.user is absent" do127 before do128 sys_exec("git config --unset github.user")129 reset!130 in_app_root131 bundle "gem #{gem_name}"132 remove_push_guard(gem_name)133 end134 it "contribute URL set to [USERNAME]" do135 expect(bundled_app("test_gem/README.md").read).to include("[USERNAME]")136 expect(bundled_app("test_gem/README.md").read).not_to include("github.com/bundleuser")137 end138 end139 end140 it "creates a new git repository" do141 in_app_root142 bundle "gem test_gem"143 expect(bundled_app("test_gem/.git")).to exist144 end145 context "when git is not available" do146 let(:gem_name) { "test_gem" }147 # This spec cannot have `git` available in the test env148 before do149 load_paths = [lib, spec]150 load_path_str = "-I#{load_paths.join(File::PATH_SEPARATOR)}"151 sys_exec "PATH=\"\" #{Gem.ruby} #{load_path_str} #{bindir.join("bundle")} gem #{gem_name}"152 end153 it "creates the gem without the need for git" do154 expect(bundled_app("#{gem_name}/README.md")).to exist155 end156 it "doesn't create a git repo" do157 expect(bundled_app("#{gem_name}/.git")).to_not exist158 end159 it "doesn't create a .gitignore file" do160 expect(bundled_app("#{gem_name}/.gitignore")).to_not exist161 end162 end163 it "generates a valid gemspec" do164 in_app_root165 bundle! "gem newgem --bin"166 process_file(bundled_app("newgem", "newgem.gemspec")) do |line|167 # Simulate replacing TODOs with real values168 case line169 when /spec\.metadata\["(?:allowed_push_host|homepage_uri|source_code_uri|changelog_uri)"\]/, /spec\.homepage/170 line.gsub(/\=.*$/, "= 'http://example.org'")171 when /spec\.summary/172 line.gsub(/\=.*$/, "= %q{A short summary of my new gem.}")173 when /spec\.description/174 line.gsub(/\=.*$/, "= %q{A longer description of my new gem.}")175 # Remove exception that prevents public pushes on older RubyGems versions176 when /raise "RubyGems 2.0 or newer/177 line.gsub(/.*/, "") if Gem::Version.new(Gem::VERSION) < Gem::Version.new("2.0")178 else179 line180 end181 end182 Dir.chdir(bundled_app("newgem")) do183 gems = ["rake-10.0.2", :bundler]184 # for Ruby core repository, Ruby 2.6+ has bundler as standard library.185 gems.delete(:bundler) if ruby_core?186 system_gems gems, :path => :bundle_path187 bundle! "exec rake build"188 end189 expect(last_command.stdboth).not_to include("ERROR")190 end191 context "gem naming with relative paths" do192 before do193 reset!194 in_app_root195 end196 it "resolves ." do197 create_temporary_dir("tmp")198 bundle "gem ."199 expect(bundled_app("tmp/lib/tmp.rb")).to exist200 end201 it "resolves .." do202 create_temporary_dir("temp/empty_dir")203 bundle "gem .."204 expect(bundled_app("temp/lib/temp.rb")).to exist205 end206 it "resolves relative directory" do207 create_temporary_dir("tmp/empty/tmp")208 bundle "gem ../../empty"209 expect(bundled_app("tmp/empty/lib/empty.rb")).to exist210 end211 def create_temporary_dir(dir)212 FileUtils.mkdir_p(dir)213 Dir.chdir(dir)214 end215 end216 context "gem naming with underscore" do217 let(:gem_name) { "test_gem" }218 before do219 execute_bundle_gem(gem_name)220 end221 let(:generated_gem) { Bundler::GemHelper.new(bundled_app(gem_name).to_s) }222 it "generates a gem skeleton" do223 expect(bundled_app("test_gem/test_gem.gemspec")).to exist224 expect(bundled_app("test_gem/Gemfile")).to exist225 expect(bundled_app("test_gem/Rakefile")).to exist226 expect(bundled_app("test_gem/lib/test_gem.rb")).to exist227 expect(bundled_app("test_gem/lib/test_gem/version.rb")).to exist228 expect(bundled_app("test_gem/.gitignore")).to exist229 expect(bundled_app("test_gem/bin/setup")).to exist230 expect(bundled_app("test_gem/bin/console")).to exist231 expect(bundled_app("test_gem/bin/setup")).to be_executable232 expect(bundled_app("test_gem/bin/console")).to be_executable233 end234 it "starts with version 0.1.0" do235 expect(bundled_app("test_gem/lib/test_gem/version.rb").read).to match(/VERSION = "0.1.0"/)236 end237 it "does not nest constants" do238 expect(bundled_app("test_gem/lib/test_gem/version.rb").read).to match(/module TestGem/)239 expect(bundled_app("test_gem/lib/test_gem.rb").read).to match(/module TestGem/)240 end241 it_should_behave_like "git config is present"242 context "git config user.{name,email} is not set" do243 before do244 `git config --unset user.name`245 `git config --unset user.email`246 reset!247 in_app_root248 bundle "gem #{gem_name}"249 remove_push_guard(gem_name)250 end251 it_should_behave_like "git config is absent"252 end253 it "sets gemspec metadata['allowed_push_host']", :rubygems => "2.0" do254 expect(generated_gem.gemspec.metadata["allowed_push_host"]).255 to match(/mygemserver\.com/)256 end257 it "requires the version file" do258 expect(bundled_app("test_gem/lib/test_gem.rb").read).to match(%r{require "test_gem/version"})259 end260 it "creates a base error class" do261 expect(bundled_app("test_gem/lib/test_gem.rb").read).to match(/class Error < StandardError; end$/)262 end263 it "runs rake without problems" do264 system_gems ["rake-10.0.2"]265 rakefile = strip_whitespace <<-RAKEFILE266 task :default do267 puts 'SUCCESS'268 end269 RAKEFILE270 File.open(bundled_app("test_gem/Rakefile"), "w") do |file|271 file.puts rakefile272 end273 Dir.chdir(bundled_app(gem_name)) do274 sys_exec(rake)275 expect(out).to include("SUCCESS")276 end277 end278 context "--exe parameter set" do279 before do280 reset!281 in_app_root282 bundle "gem #{gem_name} --exe"283 end284 it "builds exe skeleton" do285 expect(bundled_app("test_gem/exe/test_gem")).to exist286 end287 it "requires 'test-gem'" do288 expect(bundled_app("test_gem/exe/test_gem").read).to match(/require "test_gem"/)289 end290 end291 context "--bin parameter set" do292 before do293 reset!294 in_app_root295 bundle "gem #{gem_name} --bin"296 end297 it "builds exe skeleton" do298 expect(bundled_app("test_gem/exe/test_gem")).to exist299 end300 it "requires 'test-gem'" do301 expect(bundled_app("test_gem/exe/test_gem").read).to match(/require "test_gem"/)302 end303 end304 context "no --test parameter" do305 before do306 reset!307 in_app_root308 bundle "gem #{gem_name}"309 end310 it "doesn't create any spec/test file" do311 expect(bundled_app("test_gem/.rspec")).to_not exist312 expect(bundled_app("test_gem/spec/test_gem_spec.rb")).to_not exist313 expect(bundled_app("test_gem/spec/spec_helper.rb")).to_not exist314 expect(bundled_app("test_gem/test/test_test_gem.rb")).to_not exist315 expect(bundled_app("test_gem/test/minitest_helper.rb")).to_not exist316 end317 end318 context "--test parameter set to rspec" do319 before do320 reset!321 in_app_root322 bundle "gem #{gem_name} --test=rspec"323 end324 it "builds spec skeleton" do325 expect(bundled_app("test_gem/.rspec")).to exist326 expect(bundled_app("test_gem/spec/test_gem_spec.rb")).to exist327 expect(bundled_app("test_gem/spec/spec_helper.rb")).to exist328 end329 it "depends on a specific version of rspec", :rubygems => ">= 1.8.1" do330 remove_push_guard(gem_name)331 rspec_dep = generated_gem.gemspec.development_dependencies.find {|d| d.name == "rspec" }332 expect(rspec_dep).to be_specific333 end334 it "requires 'test-gem'" do335 expect(bundled_app("test_gem/spec/spec_helper.rb").read).to include(%(require "test_gem"))336 end337 it "creates a default test which fails" do338 expect(bundled_app("test_gem/spec/test_gem_spec.rb").read).to include("expect(false).to eq(true)")339 end340 end341 context "gem.test setting set to rspec" do342 before do343 reset!344 in_app_root345 bundle "config gem.test rspec"346 bundle "gem #{gem_name}"347 end348 it "builds spec skeleton" do349 expect(bundled_app("test_gem/.rspec")).to exist350 expect(bundled_app("test_gem/spec/test_gem_spec.rb")).to exist351 expect(bundled_app("test_gem/spec/spec_helper.rb")).to exist352 end353 end354 context "gem.test setting set to rspec and --test is set to minitest" do355 before do356 reset!357 in_app_root358 bundle "config gem.test rspec"359 bundle "gem #{gem_name} --test=minitest"360 end361 it "builds spec skeleton" do362 expect(bundled_app("test_gem/test/test_gem_test.rb")).to exist363 expect(bundled_app("test_gem/test/test_helper.rb")).to exist364 end365 end366 context "--test parameter set to minitest" do367 before do368 reset!369 in_app_root370 bundle "gem #{gem_name} --test=minitest"371 end372 it "depends on a specific version of minitest", :rubygems => ">= 1.8.1" do373 remove_push_guard(gem_name)374 rspec_dep = generated_gem.gemspec.development_dependencies.find {|d| d.name == "minitest" }375 expect(rspec_dep).to be_specific376 end377 it "builds spec skeleton" do378 expect(bundled_app("test_gem/test/test_gem_test.rb")).to exist379 expect(bundled_app("test_gem/test/test_helper.rb")).to exist380 end381 it "requires 'test-gem'" do382 expect(bundled_app("test_gem/test/test_helper.rb").read).to include(%(require "test_gem"))383 end384 it "requires 'minitest_helper'" do385 expect(bundled_app("test_gem/test/test_gem_test.rb").read).to include(%(require "test_helper"))386 end387 it "creates a default test which fails" do388 expect(bundled_app("test_gem/test/test_gem_test.rb").read).to include("assert false")389 end390 end391 context "gem.test setting set to minitest" do392 before do393 reset!394 in_app_root395 bundle "config gem.test minitest"396 bundle "gem #{gem_name}"397 end398 it "creates a default rake task to run the test suite" do399 rakefile = strip_whitespace <<-RAKEFILE400 require "bundler/gem_tasks"401 require "rake/testtask"402 Rake::TestTask.new(:test) do |t|403 t.libs << "test"404 t.libs << "lib"405 t.test_files = FileList["test/**/*_test.rb"]406 end407 task :default => :test408 RAKEFILE409 expect(bundled_app("test_gem/Rakefile").read).to eq(rakefile)410 end411 end412 context "--test with no arguments" do413 before do414 reset!415 in_app_root416 bundle "gem #{gem_name} --test"417 end418 it "defaults to rspec" do419 expect(bundled_app("test_gem/spec/spec_helper.rb")).to exist420 expect(bundled_app("test_gem/test/minitest_helper.rb")).to_not exist421 end422 it "creates a .travis.yml file to test the library against the current Ruby version on Travis CI" do423 expect(bundled_app("test_gem/.travis.yml").read).to match(/- #{RUBY_VERSION}/)424 end425 end426 context "--edit option" do427 it "opens the generated gemspec in the user's text editor" do428 reset!429 in_app_root430 output = bundle "gem #{gem_name} --edit=echo"431 gemspec_path = File.join(Dir.pwd, gem_name, "#{gem_name}.gemspec")432 expect(output).to include("echo \"#{gemspec_path}\"")433 end434 end435 end436 context "testing --mit and --coc options against bundle config settings" do437 let(:gem_name) { "test-gem" }438 context "with mit option in bundle config settings set to true" do439 before do440 global_config "BUNDLE_GEM__MIT" => "true", "BUNDLE_GEM__TEST" => "false", "BUNDLE_GEM__COC" => "false"441 end442 after { reset! }443 it_behaves_like "--mit flag"444 it_behaves_like "--no-mit flag"445 end446 context "with mit option in bundle config settings set to false" do447 it_behaves_like "--mit flag"448 it_behaves_like "--no-mit flag"449 end450 context "with coc option in bundle config settings set to true" do451 before do452 global_config "BUNDLE_GEM__MIT" => "false", "BUNDLE_GEM__TEST" => "false", "BUNDLE_GEM__COC" => "true"453 end454 after { reset! }455 it_behaves_like "--coc flag"456 it_behaves_like "--no-coc flag"457 end458 context "with coc option in bundle config settings set to false" do459 it_behaves_like "--coc flag"460 it_behaves_like "--no-coc flag"461 end462 end463 context "gem naming with dashed" do464 let(:gem_name) { "test-gem" }465 before do466 execute_bundle_gem(gem_name)467 end468 let(:generated_gem) { Bundler::GemHelper.new(bundled_app(gem_name).to_s) }469 it "generates a gem skeleton" do470 expect(bundled_app("test-gem/test-gem.gemspec")).to exist471 expect(bundled_app("test-gem/Gemfile")).to exist472 expect(bundled_app("test-gem/Rakefile")).to exist473 expect(bundled_app("test-gem/lib/test/gem.rb")).to exist474 expect(bundled_app("test-gem/lib/test/gem/version.rb")).to exist475 end476 it "starts with version 0.1.0" do477 expect(bundled_app("test-gem/lib/test/gem/version.rb").read).to match(/VERSION = "0.1.0"/)478 end479 it "nests constants so they work" do480 expect(bundled_app("test-gem/lib/test/gem/version.rb").read).to match(/module Test\n module Gem/)481 expect(bundled_app("test-gem/lib/test/gem.rb").read).to match(/module Test\n module Gem/)482 end483 it_should_behave_like "git config is present"484 context "git config user.{name,email} is not set" do485 before do486 `git config --unset user.name`487 `git config --unset user.email`488 reset!489 in_app_root490 bundle "gem #{gem_name}"491 remove_push_guard(gem_name)492 end493 it_should_behave_like "git config is absent"494 end495 it "requires the version file" do496 expect(bundled_app("test-gem/lib/test/gem.rb").read).to match(%r{require "test/gem/version"})497 end498 it "runs rake without problems" do499 system_gems ["rake-10.0.2"]500 rakefile = strip_whitespace <<-RAKEFILE501 task :default do502 puts 'SUCCESS'503 end504 RAKEFILE505 File.open(bundled_app("test-gem/Rakefile"), "w") do |file|506 file.puts rakefile507 end508 Dir.chdir(bundled_app(gem_name)) do509 sys_exec(rake)510 expect(out).to include("SUCCESS")511 end512 end513 context "--bin parameter set" do514 before do515 reset!516 in_app_root517 bundle "gem #{gem_name} --bin"518 end519 it "builds bin skeleton" do520 expect(bundled_app("test-gem/exe/test-gem")).to exist521 end522 it "requires 'test/gem'" do523 expect(bundled_app("test-gem/exe/test-gem").read).to match(%r{require "test/gem"})524 end525 end526 context "no --test parameter" do527 before do528 reset!529 in_app_root530 bundle "gem #{gem_name}"531 end532 it "doesn't create any spec/test file" do533 expect(bundled_app("test-gem/.rspec")).to_not exist534 expect(bundled_app("test-gem/spec/test/gem_spec.rb")).to_not exist535 expect(bundled_app("test-gem/spec/spec_helper.rb")).to_not exist536 expect(bundled_app("test-gem/test/test_test/gem.rb")).to_not exist537 expect(bundled_app("test-gem/test/minitest_helper.rb")).to_not exist538 end539 end540 context "--test parameter set to rspec" do541 before do542 reset!543 in_app_root544 bundle "gem #{gem_name} --test=rspec"545 end546 it "builds spec skeleton" do547 expect(bundled_app("test-gem/.rspec")).to exist548 expect(bundled_app("test-gem/spec/test/gem_spec.rb")).to exist549 expect(bundled_app("test-gem/spec/spec_helper.rb")).to exist550 end551 it "requires 'test/gem'" do552 expect(bundled_app("test-gem/spec/spec_helper.rb").read).to include(%(require "test/gem"))553 end554 it "creates a default test which fails" do555 expect(bundled_app("test-gem/spec/test/gem_spec.rb").read).to include("expect(false).to eq(true)")556 end557 it "creates a default rake task to run the specs" do558 rakefile = strip_whitespace <<-RAKEFILE559 require "bundler/gem_tasks"560 require "rspec/core/rake_task"561 RSpec::Core::RakeTask.new(:spec)562 task :default => :spec563 RAKEFILE564 expect(bundled_app("test-gem/Rakefile").read).to eq(rakefile)565 end566 end567 context "--test parameter set to minitest" do568 before do569 reset!570 in_app_root571 bundle "gem #{gem_name} --test=minitest"572 end573 it "builds spec skeleton" do574 expect(bundled_app("test-gem/test/test/gem_test.rb")).to exist575 expect(bundled_app("test-gem/test/test_helper.rb")).to exist576 end577 it "requires 'test/gem'" do578 expect(bundled_app("test-gem/test/test_helper.rb").read).to match(%r{require "test/gem"})579 end580 it "requires 'test_helper'" do581 expect(bundled_app("test-gem/test/test/gem_test.rb").read).to match(/require "test_helper"/)582 end583 it "creates a default test which fails" do584 expect(bundled_app("test-gem/test/test/gem_test.rb").read).to match(/assert false/)585 end586 it "creates a default rake task to run the test suite" do587 rakefile = strip_whitespace <<-RAKEFILE588 require "bundler/gem_tasks"589 require "rake/testtask"590 Rake::TestTask.new(:test) do |t|591 t.libs << "test"592 t.libs << "lib"593 t.test_files = FileList["test/**/*_test.rb"]594 end595 task :default => :test596 RAKEFILE597 expect(bundled_app("test-gem/Rakefile").read).to eq(rakefile)598 end599 end600 context "--test with no arguments" do601 before do602 reset!603 in_app_root604 bundle "gem #{gem_name} --test"605 end606 it "defaults to rspec" do607 expect(bundled_app("test-gem/spec/spec_helper.rb")).to exist608 expect(bundled_app("test-gem/test/minitest_helper.rb")).to_not exist609 end610 end611 context "--ext parameter set" do612 before do613 reset!614 in_app_root615 bundle "gem test_gem --ext"616 end617 it "builds ext skeleton" do618 expect(bundled_app("test_gem/ext/test_gem/extconf.rb")).to exist619 expect(bundled_app("test_gem/ext/test_gem/test_gem.h")).to exist620 expect(bundled_app("test_gem/ext/test_gem/test_gem.c")).to exist621 end622 it "includes rake-compiler" do623 expect(bundled_app("test_gem/test_gem.gemspec").read).to include('spec.add_development_dependency "rake-compiler"')624 end625 it "depends on compile task for build" do626 rakefile = strip_whitespace <<-RAKEFILE627 require "bundler/gem_tasks"628 require "rake/extensiontask"629 task :build => :compile630 Rake::ExtensionTask.new("test_gem") do |ext|631 ext.lib_dir = "lib/test_gem"632 end633 task :default => [:clobber, :compile, :spec]634 RAKEFILE635 expect(bundled_app("test_gem/Rakefile").read).to eq(rakefile)636 end637 end638 end639 describe "uncommon gem names" do640 it "can deal with two dashes" do641 bundle "gem a--a"642 Bundler.clear_gemspec_cache643 expect(bundled_app("a--a/a--a.gemspec")).to exist644 end645 it "fails gracefully with a ." do646 bundle "gem foo.gemspec"647 expect(last_command.bundler_err).to end_with("Invalid gem name foo.gemspec -- `Foo.gemspec` is an invalid constant name")648 end649 it "fails gracefully with a ^" do650 bundle "gem ^"651 expect(last_command.bundler_err).to end_with("Invalid gem name ^ -- `^` is an invalid constant name")652 end653 it "fails gracefully with a space" do654 bundle "gem 'foo bar'"655 expect(last_command.bundler_err).to end_with("Invalid gem name foo bar -- `Foo bar` is an invalid constant name")656 end657 it "fails gracefully when multiple names are passed" do658 bundle "gem foo bar baz"659 expect(last_command.bundler_err).to eq(<<-E.strip)660ERROR: "bundle gem" was called with arguments ["foo", "bar", "baz"]661Usage: "bundle gem NAME [OPTIONS]"662 E663 end664 end665 describe "#ensure_safe_gem_name" do666 before do667 bundle "gem #{subject}"668 end669 after do670 Bundler.clear_gemspec_cache671 end672 context "with an existing const name" do673 subject { "gem" }674 it { expect(out).to include("Invalid gem name #{subject}") }675 end676 context "with an existing hyphenated const name" do677 subject { "gem-specification" }678 it { expect(out).to include("Invalid gem name #{subject}") }679 end680 context "starting with an existing const name" do681 subject { "gem-somenewconstantname" }682 it { expect(out).not_to include("Invalid gem name #{subject}") }683 end684 context "ending with an existing const name" do685 subject { "somenewconstantname-gem" }686 it { expect(out).not_to include("Invalid gem name #{subject}") }687 end688 end689 context "on first run" do690 before do691 in_app_root692 end693 it "asks about test framework" do694 global_config "BUNDLE_GEM__MIT" => "false", "BUNDLE_GEM__COC" => "false"695 bundle "gem foobar" do |input, _, _|696 input.puts "rspec"697 end698 expect(bundled_app("foobar/spec/spec_helper.rb")).to exist699 rakefile = strip_whitespace <<-RAKEFILE700 require "bundler/gem_tasks"701 require "rspec/core/rake_task"702 RSpec::Core::RakeTask.new(:spec)703 task :default => :spec704 RAKEFILE705 expect(bundled_app("foobar/Rakefile").read).to eq(rakefile)706 expect(bundled_app("foobar/foobar.gemspec").read).to include('spec.add_development_dependency "rspec"')707 end708 it "asks about MIT license" do709 global_config "BUNDLE_GEM__TEST" => "false", "BUNDLE_GEM__COC" => "false"710 bundle :config711 bundle "gem foobar" do |input, _, _|712 input.puts "yes"713 end714 expect(bundled_app("foobar/LICENSE.txt")).to exist715 end716 it "asks about CoC" do717 global_config "BUNDLE_GEM__MIT" => "false", "BUNDLE_GEM__TEST" => "false"718 bundle "gem foobar" do |input, _, _|719 input.puts "yes"720 end721 expect(bundled_app("foobar/CODE_OF_CONDUCT.md")).to exist722 end723 end724 context "on conflicts with a previously created file" do725 it "should fail gracefully" do726 in_app_root do727 FileUtils.touch("conflict-foobar")728 end729 bundle "gem conflict-foobar"730 expect(last_command.bundler_err).to include("Errno::ENOTDIR")731 expect(exitstatus).to eql(32) if exitstatus732 end733 end734 context "on conflicts with a previously created directory" do735 it "should succeed" do736 in_app_root do737 FileUtils.mkdir_p("conflict-foobar/Gemfile")738 end739 bundle! "gem conflict-foobar"740 expect(last_command.stdout).to include("file_clash conflict-foobar/Gemfile").741 and include "Initializing git repo in #{bundled_app("conflict-foobar")}"742 end743 end744end...

Full Screen

Full Screen

indexes.rb

Source:indexes.rb Github

copy

Full Screen

2module Spec3 module Indexes4 def dep(name, reqs = nil)5 @deps ||= []6 @deps << Bundler::Dependency.new(name, reqs)7 end8 def platform(*args)9 @platforms ||= []10 @platforms.concat args.map {|p| Gem::Platform.new(p) }11 end12 alias_method :platforms, :platform13 def resolve(args = [])14 @platforms ||= ["ruby"]15 deps = []16 default_source = instance_double("Bundler::Source::Rubygems", :specs => @index)17 source_requirements = { :default => default_source }18 @deps.each do |d|19 @platforms.each do |p|20 source_requirements[d.name] = d.source = default_source21 deps << Bundler::DepProxy.new(d, p)22 end23 end24 source_requirements ||= {}25 Bundler::Resolver.resolve(deps, @index, source_requirements, *args)26 end27 def should_resolve_as(specs)28 got = resolve29 got = got.map(&:full_name).sort30 expect(got).to eq(specs.sort)31 end32 def should_resolve_and_include(specs, args = [])33 got = resolve(args)34 got = got.map(&:full_name).sort35 specs.each do |s|36 expect(got).to include(s)37 end38 end39 def should_conflict_on(names)40 got = resolve41 flunk "The resolve succeeded with: #{got.map(&:full_name).sort.inspect}"42 rescue Bundler::VersionConflict => e43 expect(Array(names).sort).to eq(e.conflicts.sort)44 end45 def gem(*args, &blk)46 build_spec(*args, &blk).first47 end48 def locked(*args)49 Bundler::SpecSet.new(args.map do |name, version|50 gem(name, version)51 end)52 end53 def should_conservative_resolve_and_include(opts, unlock, specs)54 # empty unlock means unlock all55 opts = Array(opts)56 search = Bundler::GemVersionPromoter.new(@locked, unlock).tap do |s|57 s.level = opts.first58 s.strict = opts.include?(:strict)59 s.prerelease_specified = Hash[@deps.map {|d| [d.name, d.requirement.prerelease?] }]60 end61 should_resolve_and_include specs, [@base, search]62 end63 def an_awesome_index64 build_index do65 gem "rack", %w[0.8 0.9 0.9.1 0.9.2 1.0 1.1]66 gem "rack-mount", %w[0.4 0.5 0.5.1 0.5.2 0.6]67 # --- Pre-release support68 gem "rubygems\0", ["1.3.2"]69 # --- Rails70 versions "1.2.3 2.2.3 2.3.5 3.0.0.beta 3.0.0.beta1" do |version|71 gem "activesupport", version72 gem "actionpack", version do73 dep "activesupport", version74 if version >= v("3.0.0.beta")75 dep "rack", "~> 1.1"76 dep "rack-mount", ">= 0.5"77 elsif version > v("2.3") then dep "rack", "~> 1.0.0"78 elsif version > v("2.0.0") then dep "rack", "~> 0.9.0"79 end80 end81 gem "activerecord", version do82 dep "activesupport", version83 dep "arel", ">= 0.2" if version >= v("3.0.0.beta")84 end85 gem "actionmailer", version do86 dep "activesupport", version87 dep "actionmailer", version88 end89 if version < v("3.0.0.beta")90 gem "railties", version do91 dep "activerecord", version92 dep "actionpack", version93 dep "actionmailer", version94 dep "activesupport", version95 end96 else97 gem "railties", version98 gem "rails", version do99 dep "activerecord", version100 dep "actionpack", version101 dep "actionmailer", version102 dep "activesupport", version103 dep "railties", version104 end105 end106 end107 versions "1.0 1.2 1.2.1 1.2.2 1.3 1.3.0.1 1.3.5 1.4.0 1.4.2 1.4.2.1" do |version|108 platforms "ruby java mswin32 mingw32 x64-mingw32" do |platform|109 next if version == v("1.4.2.1") && platform != pl("x86-mswin32")110 next if version == v("1.4.2") && platform == pl("x86-mswin32")111 gem "nokogiri", version, platform do112 dep "weakling", ">= 0.0.3" if platform =~ pl("java")113 end114 end115 end116 versions "0.0.1 0.0.2 0.0.3" do |version|117 gem "weakling", version118 end119 # --- Rails related120 versions "1.2.3 2.2.3 2.3.5" do |version|121 gem "activemerchant", version do122 dep "activesupport", ">= #{version}"123 end124 end125 gem "reform", ["1.0.0"] do126 dep "activesupport", ">= 1.0.0.beta1"127 end128 gem "need-pre", ["1.0.0"] do129 dep "activesupport", "~> 3.0.0.beta1"130 end131 end132 end133 # Builder 3.1.4 will activate first, but if all134 # goes well, it should resolve to 3.0.4135 def a_conflict_index136 build_index do137 gem "builder", %w[3.0.4 3.1.4]138 gem("grape", "0.2.6") do139 dep "builder", ">= 0"140 end141 versions "3.2.8 3.2.9 3.2.10 3.2.11" do |version|142 gem("activemodel", version) do143 dep "builder", "~> 3.0.0"144 end145 end146 gem("my_app", "1.0.0") do147 dep "activemodel", ">= 0"148 dep "grape", ">= 0"149 end150 end151 end152 def a_complex_conflict_index153 build_index do154 gem("a", %w[1.0.2 1.1.4 1.2.0 1.4.0]) do155 dep "d", ">= 0"156 end157 gem("d", %w[1.3.0 1.4.1]) do158 dep "x", ">= 0"159 end160 gem "d", "0.9.8"161 gem("b", "0.3.4") do162 dep "a", ">= 1.5.0"163 end164 gem("b", "0.3.5") do165 dep "a", ">= 1.2"166 end167 gem("b", "0.3.3") do168 dep "a", "> 1.0"169 end170 versions "3.2 3.3" do |version|171 gem("c", version) do172 dep "a", "~> 1.0"173 end174 end175 gem("my_app", "1.3.0") do176 dep "c", ">= 4.0"177 dep "b", ">= 0"178 end179 gem("my_app", "1.2.0") do180 dep "c", "~> 3.3.0"181 dep "b", "0.3.4"182 end183 gem("my_app", "1.1.0") do184 dep "c", "~> 3.2.0"185 dep "b", "0.3.5"186 end187 end188 end189 def index_with_conflict_on_child190 build_index do191 gem "json", %w[1.6.5 1.7.7 1.8.0]192 gem("chef", "10.26") do193 dep "json", [">= 1.4.4", "<= 1.7.7"]194 end195 gem("berkshelf", "2.0.7") do196 dep "json", ">= 1.7.7"197 end198 gem("chef_app", "1.0.0") do199 dep "berkshelf", "~> 2.0"200 dep "chef", "~> 10.26"201 end202 end203 end204 # Issue #3459205 def a_complicated_index206 build_index do207 gem "foo", %w[3.0.0 3.0.5] do208 dep "qux", ["~> 3.1"]209 dep "baz", ["< 9.0", ">= 5.0"]210 dep "bar", ["~> 1.0"]211 dep "grault", ["~> 3.1"]212 end213 gem "foo", "1.2.1" do214 dep "baz", ["~> 4.2"]215 dep "bar", ["~> 1.0"]216 dep "qux", ["~> 3.1"]217 dep "grault", ["~> 2.0"]218 end219 gem "bar", "1.0.5" do220 dep "grault", ["~> 3.1"]221 dep "baz", ["< 9", ">= 4.2"]222 end223 gem "bar", "1.0.3" do224 dep "baz", ["< 9", ">= 4.2"]225 dep "grault", ["~> 2.0"]226 end227 gem "baz", "8.2.10" do228 dep "grault", ["~> 3.0"]229 dep "garply", [">= 0.5.1", "~> 0.5"]230 end231 gem "baz", "5.0.2" do232 dep "grault", ["~> 2.0"]233 dep "garply", [">= 0.3.1"]234 end235 gem "baz", "4.2.0" do236 dep "grault", ["~> 2.0"]237 dep "garply", [">= 0.3.1"]238 end239 gem "grault", %w[2.6.3 3.1.1]240 gem "garply", "0.5.1" do241 dep "waldo", ["~> 0.1.3"]242 end243 gem "waldo", "0.1.5" do244 dep "plugh", ["~> 0.6.0"]245 end246 gem "plugh", %w[0.6.3 0.6.11 0.7.0]247 gem "qux", "3.2.21" do248 dep "plugh", [">= 0.6.4", "~> 0.6"]249 dep "corge", ["~> 1.0"]250 end251 gem "corge", "1.10.1"252 end253 end254 def a_unresovable_child_index255 build_index do256 gem "json", %w[1.8.0]257 gem("chef", "10.26") do258 dep "json", [">= 1.4.4", "<= 1.7.7"]259 end260 gem("berkshelf", "2.0.7") do261 dep "json", ">= 1.7.7"262 end263 gem("chef_app_error", "1.0.0") do264 dep "berkshelf", "~> 2.0"265 dep "chef", "~> 10.26"266 end267 end268 end269 def a_index_with_root_conflict_on_child270 build_index do271 gem "builder", %w[2.1.2 3.0.1 3.1.3]272 gem "i18n", %w[0.4.1 0.4.2]273 gem "activesupport", %w[3.0.0 3.0.1 3.0.5 3.1.7]274 gem("activemodel", "3.0.5") do275 dep "activesupport", "= 3.0.5"276 dep "builder", "~> 2.1.2"277 dep "i18n", "~> 0.4"278 end279 gem("activemodel", "3.0.0") do280 dep "activesupport", "= 3.0.0"281 dep "builder", "~> 2.1.2"282 dep "i18n", "~> 0.4.1"283 end284 gem("activemodel", "3.1.3") do285 dep "activesupport", "= 3.1.3"286 dep "builder", "~> 2.1.2"287 dep "i18n", "~> 0.5"288 end289 gem("activerecord", "3.0.0") do290 dep "activesupport", "= 3.0.0"291 dep "activemodel", "= 3.0.0"292 end293 gem("activerecord", "3.0.5") do294 dep "activesupport", "= 3.0.5"295 dep "activemodel", "= 3.0.5"296 end297 gem("activerecord", "3.0.9") do298 dep "activesupport", "= 3.1.5"299 dep "activemodel", "= 3.1.5"300 end301 end302 end303 def a_circular_index304 build_index do305 gem "rack", "1.0.1"306 gem("foo", "0.2.6") do307 dep "bar", ">= 0"308 end309 gem("bar", "1.0.0") do310 dep "foo", ">= 0"311 end312 gem("circular_app", "1.0.0") do313 dep "foo", ">= 0"314 dep "bar", ">= 0"315 end316 end317 end318 def an_ambiguous_index319 build_index do320 gem("a", "1.0.0") do321 dep "c", ">= 0"322 end323 gem("b", %w[0.5.0 1.0.0])324 gem("b", "2.0.0") do325 dep "c", "< 2.0.0"326 end327 gem("c", "1.0.0") do328 dep "d", "1.0.0"329 end330 gem("c", "2.0.0") do331 dep "d", "2.0.0"332 end333 gem("d", %w[1.0.0 2.0.0])334 end335 end336 def optional_prereleases_index337 build_index do338 gem("a", %w[1.0.0])339 gem("a", "2.0.0") do340 dep "b", ">= 2.0.0.pre"341 end342 gem("b", %w[0.9.0 1.5.0 2.0.0.pre])343 # --- Pre-release support344 gem "rubygems\0", ["1.3.2"]345 end346 end347 end348end...

Full Screen

Full Screen

end

Using AI Code Generation

copy

Full Screen

1puts Gem::Specification.find_by_name('rubygems-update').version2puts Gem::Specification.find_by_name('rubygems-update').version3puts Gem::Specification.find_by_name('rubygems-update').version4puts Gem::Specification.find_by_name('rubygems-update').version5puts Gem::Specification.find_by_name('rubygems-update').version6puts Gem::Specification.find_by_name('rubygems-update').version7puts Gem::Specification.find_by_name('rubygems-update').version8puts Gem::Specification.find_by_name('rubygems-update').version9puts Gem::Specification.find_by_name('rubygems-update').version10puts Gem::Specification.find_by_name('rubygems-update').version11puts Gem::Specification.find_by_name('rubygems-update').version12puts Gem::Specification.find_by_name('rubygems-update').version13puts Gem::Specification.find_by_name('rubygems-update').version

Full Screen

Full Screen

end

Using AI Code Generation

copy

Full Screen

1uri = URI.parse("http://rubygems.org/api/v1/gems.json")2response = Net::HTTP.get_response(uri)3gems = JSON.parse(json)4gems_with_summary = gems.select {|gem| gem["summary"] != nil}5gems_with_summary_and_not_end = gems_with_summary.select {|gem| gem["summary"].downcase != "end"}6gems_with_summary_and_not_end_and_not_deprecated = gems_with_summary_and_not_end.select {|gem| gem["deprecated"] == false}7gems_with_summary_and_not_end_and_not_deprecated_and_have_homepage = gems_with_summary_and_not_end_and_not_deprecated.select {|gem| gem["homepage_uri"] != nil}8gems_with_summary_and_not_end_and_not_deprecated_and_have_homepage_and_not_development = gems_with_summary_and_not_end_and_not_deprecated_and_have_homepage.select {|gem| gem["development_dependencies"] == false}9sorted_gems = gems_with_summary_and_not_end_and_not_deprecated_and_have_homepage_and_not_development.sort_by {|gem| gem["name"]}

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Vcr_ruby automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used method in

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful