How to use fetcher method of Gem Package

Best Rr_ruby code snippet using Gem.fetcher

test_gem_spec_fetcher.rb

Source:test_gem_spec_fetcher.rb Github

copy

Full Screen

1# frozen_string_literal: true2require 'rubygems/test_case'3require 'rubygems/spec_fetcher'4class TestGemSpecFetcher < Gem::TestCase5 def tuple(*args)6 Gem::NameTuple.new(*args)7 end8 def setup9 super10 @uri = URI.parse @gem_repo11 @source = Gem::Source.new(@uri)12 @sf = Gem::SpecFetcher.new13 end14 def test_initialize15 fetcher = Gem::SpecFetcher.new16 assert_same Gem.sources, fetcher.sources17 end18 def test_initialize_source19 alternate = 'http://alternate.example'20 fetcher = Gem::SpecFetcher.new alternate21 refute_same Gem.sources, fetcher.sources22 assert_equal alternate, fetcher.sources23 end24 def test_initialize_nonexistent_home_dir25 FileUtils.rmdir Gem.user_home26 assert Gem::SpecFetcher.new27 end28 def test_initialize_unwritable_home_dir29 skip 'chmod not supported' if Gem.win_platform?30 FileUtils.chmod 0000, Gem.user_home31 begin32 assert Gem::SpecFetcher.new33 ensure34 FileUtils.chmod 0755, Gem.user_home35 end36 end37 def test_spec_for_dependency_all38 spec_fetcher do |fetcher|39 fetcher.spec 'a', 140 fetcher.spec 'a', '2.a'41 fetcher.spec 'a', 242 fetcher.spec 'a', '3.a'43 end44 dep = Gem::Dependency.new 'a', ">= 1"45 specs_and_sources, _ = @sf.spec_for_dependency dep46 spec_names = specs_and_sources.map do |spec, source_uri|47 [spec.full_name, source_uri]48 end49 expected = [['a-1', @source], ['a-2', @source]]50 assert_equal expected, spec_names51 assert_same specs_and_sources.first.last, specs_and_sources.last.last52 end53 def test_spec_for_dependency_latest54 spec_fetcher do |fetcher|55 fetcher.spec 'a', 156 fetcher.spec 'a', 257 fetcher.spec 'a', '3.a'58 end59 dep = Gem::Dependency.new 'a'60 specs_and_sources, _ = @sf.spec_for_dependency dep61 spec_names = specs_and_sources.map do |spec, source_uri|62 [spec.full_name, source_uri]63 end64 assert_equal [['a-2', Gem::Source.new(@gem_repo)]],65 spec_names66 end67 def test_spec_for_dependency_prerelease68 spec_fetcher do |fetcher|69 fetcher.spec 'a', '1.a'70 fetcher.spec 'a', 171 end72 specs_and_sources, _ = @sf.spec_for_dependency dep('a', '1.a')73 spec_names = specs_and_sources.map do |spec, source_uri|74 [spec.full_name, source_uri]75 end76 assert_equal [['a-1.a', Gem::Source.new(@gem_repo)]], spec_names77 end78 def test_spec_for_dependency_platform79 util_set_arch 'i386-linux'80 spec_fetcher do |fetcher|81 fetcher.legacy_platform82 end83 dep = Gem::Dependency.new 'pl', 184 specs_and_sources, _ = @sf.spec_for_dependency dep85 spec_names = specs_and_sources.map do |spec, source_uri|86 [spec.full_name, source_uri]87 end88 assert_equal [['pl-1-x86-linux', Gem::Source.new(@gem_repo)]],89 spec_names90 end91 def test_spec_for_dependency_mismatched_platform92 util_set_arch 'hrpa-989'93 spec_fetcher do |fetcher|94 fetcher.legacy_platform95 end96 dep = Gem::Dependency.new 'pl', 197 specs_and_sources, errors = @sf.spec_for_dependency dep98 assert_equal 0, specs_and_sources.size99 assert_equal 1, errors.size100 pmm = errors.first101 assert_equal "i386-linux", pmm.platforms.first102 assert_equal "Found pl (1), but was for platform i386-linux", pmm.wordy103 end104 def test_spec_for_dependency_bad_fetch_spec105 src = Gem::Source.new(@gem_repo)106 def src.fetch_spec(name)107 raise Gem::RemoteFetcher::FetchError.new("bad news from the internet", @uri)108 end109 Gem.sources.replace [src]110 spec_fetcher do |fetcher|111 fetcher.spec 'a', 1112 fetcher.spec 'a', '2.a'113 fetcher.spec 'a', 2114 fetcher.spec 'a', '3.a'115 end116 dep = Gem::Dependency.new 'a', ">= 1"117 specs_and_sources, errors = @sf.spec_for_dependency dep118 assert_equal [], specs_and_sources119 sfp = errors.first120 assert_kind_of Gem::SourceFetchProblem, sfp121 assert_equal src, sfp.source122 assert_equal "bad news from the internet (#{@gem_repo})", sfp.error.message123 end124 def test_available_specs_latest125 spec_fetcher do |fetcher|126 fetcher.spec 'a', 1127 fetcher.spec 'a', 2128 fetcher.spec 'a', '3.a'129 fetcher.legacy_platform130 end131 specs, _ = @sf.available_specs(:latest)132 assert_equal [@source], specs.keys133 expected = Gem::NameTuple.from_list \134 [['a', v(2), Gem::Platform::RUBY],135 ['pl', v(1), 'i386-linux']]136 assert_equal expected, specs[@source]137 end138 def test_available_specs_released139 spec_fetcher do |fetcher|140 fetcher.spec 'a', 1141 fetcher.legacy_platform142 end143 specs, _ = @sf.available_specs(:released)144 assert_equal [@source], specs.keys145 expected = Gem::NameTuple.from_list \146 [['a', v(1), Gem::Platform::RUBY],147 ['pl', v(1), 'i386-linux']]148 assert_equal expected, specs[@source]149 end150 def test_available_specs_complete151 spec_fetcher do |fetcher|152 fetcher.spec 'a', 1153 fetcher.spec 'a', '2.a'154 fetcher.spec 'b', 2155 fetcher.legacy_platform156 end157 specs, _ = @sf.available_specs(:complete)158 assert_equal [@source], specs.keys159 expected = Gem::NameTuple.from_list \160 [['a', v(1), Gem::Platform::RUBY],161 ['a', v('2.a'), Gem::Platform::RUBY],162 ['b', v(2), Gem::Platform::RUBY],163 ['pl', v(1), 'i386-linux']]164 assert_equal expected, specs[@source]165 end166 def test_available_specs_complete_handles_no_prerelease167 spec_fetcher do |fetcher|168 fetcher.spec 'a', 1169 fetcher.spec 'a', '2.a'170 fetcher.spec 'b', 2171 fetcher.legacy_platform172 end173 v = Gem.marshal_version174 @fetcher.data.delete "#{@gem_repo}prerelease_specs.#{v}.gz"175 specs, _ = @sf.available_specs(:complete)176 assert_equal [@source], specs.keys177 expected = Gem::NameTuple.from_list \178 [['a', v(1), Gem::Platform::RUBY],179 ['b', v(2), Gem::Platform::RUBY],180 ['pl', v(1), 'i386-linux']]181 assert_equal expected, specs[@source]182 end183 def test_available_specs_cache184 spec_fetcher do |fetcher|185 fetcher.spec 'a', 1186 end187 specs, _ = @sf.available_specs(:latest)188 refute specs[@source].empty?189 @fetcher.data["#{@gem_repo}/latest_specs.#{Gem.marshal_version}.gz"] = nil190 cached_specs, _ = @sf.available_specs(:latest)191 assert_equal specs, cached_specs192 end193 def test_available_specs_cache_released194 spec_fetcher do |fetcher|195 fetcher.spec 'a', 1196 fetcher.spec 'a', '2.a'197 fetcher.spec 'b', 2198 fetcher.legacy_platform199 end200 specs, _ = @sf.available_specs(:released)201 refute specs[@source].empty?202 @fetcher.data["#{@gem_repo}/specs.#{Gem.marshal_version}.gz"] = nil203 cached_specs, _ = @sf.available_specs(:released)204 assert_equal specs, cached_specs205 end206 def test_available_specs_prerelease207 spec_fetcher do |fetcher|208 fetcher.spec 'a', 1209 fetcher.spec 'a', '2.a'210 end211 specs, _ = @sf.available_specs(:prerelease)212 expected = Gem::NameTuple.from_list \213 [['a', v('2.a'), Gem::Platform::RUBY]]214 assert_equal expected, specs[@source]215 end216 def test_available_specs_with_bad_source217 Gem.sources.replace ["http://not-there.nothing"]218 specs, errors = @sf.available_specs(:latest)219 assert_equal({}, specs)220 assert_kind_of Gem::SourceFetchProblem, errors.first221 end222end...

Full Screen

Full Screen

fetcher

Using AI Code Generation

copy

Full Screen

1puts Gem::Specification.find_by_name("rake").gem_dir2puts Gem::Specification.find_by_name("rake").gem_dir3puts Gem::Specification.find_by_name("rake").gem_dir4puts Gem::Specification.find_by_name("rake").gem_dir5puts Gem::Specification.find_by_name("rake").gem_dir6puts Gem::Specification.find_by_name("rake").gem_dir7puts Gem::Specification.find_by_name("rake").gem_dir8puts Gem::Specification.find_by_name("rake").gem_dir9puts Gem::Specification.find_by_name("rake").gem_dir10puts Gem::Specification.find_by_name("rake").gem_dir11puts Gem::Specification.find_by_name("rake").gem_dir

Full Screen

Full Screen

fetcher

Using AI Code Generation

copy

Full Screen

1spec = Gem::SourceIndex.from_gems_in('/var/lib/gems/1.8/specs').find_name(gem_name, version).last2spec_file = fetcher.download(spec, '/tmp')3spec = Gem::Format.from_file_by_path(spec_file).spec4 source_path = File.join(spec.full_gem_path, path)5 Dir.glob(File.join(source_path, '**', '*.rb')).each do |file|6 source_file = fetcher.download(file, '/tmp')

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.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful