alloy-microgem 0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. data/LICENSE +21 -0
  2. data/README.rdoc +55 -0
  3. data/Rakefile +24 -0
  4. data/TODO +13 -0
  5. data/bin/zinflate +17 -0
  6. data/bin//302/265gem +14 -0
  7. data/lib/microgem.rb +56 -0
  8. data/lib/microgem/bare_specification.rb +40 -0
  9. data/lib/microgem/bin_wrapper_emitter.rb +58 -0
  10. data/lib/microgem/config.rb +96 -0
  11. data/lib/microgem/dependency.rb +37 -0
  12. data/lib/microgem/downloader.rb +48 -0
  13. data/lib/microgem/installer.rb +147 -0
  14. data/lib/microgem/options_parser.rb +67 -0
  15. data/lib/microgem/requirement.rb +36 -0
  16. data/lib/microgem/source.rb +108 -0
  17. data/lib/microgem/specification.rb +65 -0
  18. data/lib/microgem/specification_emitter.rb +75 -0
  19. data/lib/microgem/unpacker.rb +55 -0
  20. data/lib/microgem/utils.rb +51 -0
  21. data/lib/microgem/version.rb +35 -0
  22. data/lib/microgem/yamlable.rb +32 -0
  23. data/test/bare_specification_test.rb +43 -0
  24. data/test/bin_wrapper_emitter_test.rb +57 -0
  25. data/test/config_test.rb +131 -0
  26. data/test/dependency_test.rb +41 -0
  27. data/test/downloader_test.rb +100 -0
  28. data/test/fixtures/gems.github.com +0 -0
  29. data/test/fixtures/gems.rubyforge.org +0 -0
  30. data/test/fixtures/gems/rake-0.8.0/rake.rb +1 -0
  31. data/test/fixtures/gems/rake-0.8.1/rake.rb +1 -0
  32. data/test/fixtures/gems/test-spec-0.3.0/test-spec.rb +1 -0
  33. data/test/fixtures/gems/test-spec-mock-0.3.0/test-spec-mock.rb +1 -0
  34. data/test/fixtures/rails-2.1.1.gemspec +26 -0
  35. data/test/fixtures/rails-2.1.1.gemspec.marshal +0 -0
  36. data/test/fixtures/rake-0.8.1.gem +0 -0
  37. data/test/fixtures/rake-0.8.1.gemspec +20 -0
  38. data/test/fixtures/rake-0.8.1.gemspec.marshal +0 -0
  39. data/test/fixtures/rake-0.8.1.gemspec.rz +2 -0
  40. data/test/fixtures/specs.4.8.gz +0 -0
  41. data/test/installer_test.rb +198 -0
  42. data/test/microgem_test.rb +34 -0
  43. data/test/options_parser_test.rb +36 -0
  44. data/test/requirement_test.rb +40 -0
  45. data/test/source_test.rb +153 -0
  46. data/test/specification_emitter_test.rb +139 -0
  47. data/test/specification_test.rb +45 -0
  48. data/test/test_helper.rb +71 -0
  49. data/test/unpacker_test.rb +91 -0
  50. data/test/utils_test.rb +42 -0
  51. data/test/version_test.rb +27 -0
  52. data/test/yamlable_test.rb +15 -0
  53. metadata +114 -0
@@ -0,0 +1,41 @@
1
+ ##!/usr/bin/env macruby
2
+
3
+ require File.expand_path('../test_helper', __FILE__)
4
+
5
+ class Gem::Dependency
6
+ alias_method :meet_requirements?, :meets_requirements?
7
+ end
8
+
9
+ describe "Gem::Dependency" do
10
+ def setup
11
+ gem_spec = gem_spec_fixture('rails', '2.1.1')
12
+ @dependencies = gem_spec.dependencies
13
+ @dependency = @dependencies.find { |d| d.name == 'rake' }
14
+ end
15
+
16
+ it "should return its version requirements" do
17
+ @dependency.version_requirements.should == Gem::Requirement[:requirements => [[">=", Gem::Version[:version => '0.8.1']]]]
18
+ end
19
+
20
+ it "should return whether or not its requirements are met" do
21
+ @dependencies.find { |d| d.name == 'rake' }.should.meet_requirements
22
+
23
+ Gem::Micro.stubs(:installed_gem_dirnames).with('rake').returns([])
24
+ @dependencies.find { |d| d.name == 'rake' }.should.not.meet_requirements
25
+ end
26
+
27
+ it "should return its gem spec matching the required version" do
28
+ rake = gem_spec_fixture('rake', '0.8.1')
29
+ Gem::Micro::Source.expects(:gem_spec).with('rake', @dependency.version_requirements.version).returns(rake)
30
+ @dependency.gem_spec.should == rake
31
+ end
32
+
33
+ it "should raise a Gem::Micro::GemSpecMissingError if the gem spec for this dependency can't be found" do
34
+ Gem::Micro::Source.stubs(:gem_spec).returns(nil)
35
+ lambda { @dependency.gem_spec }.should.raise Gem::Micro::GemSpecMissingError
36
+ end
37
+
38
+ it "should return a string representation of itself" do
39
+ @dependency.to_s.should == "rake >= 0.8.1"
40
+ end
41
+ end
@@ -0,0 +1,100 @@
1
+ ##!/usr/bin/env macruby
2
+
3
+ require File.expand_path('../test_helper', __FILE__)
4
+
5
+ describe "Downloader, in simple mode" do
6
+ before do
7
+ @arguments = {
8
+ :remote => 'http://gems.rubyforge.org/gems/rake-0.8.1.gem',
9
+ :local => File.join(TMP_PATH, 'gems', 'rake-0.8.1.gem')
10
+ }
11
+ FileUtils.rm_rf(File.join(TMP_PATH, 'gems'))
12
+ Gem::Micro::Config.stubs(:simple_downloader?).returns(true)
13
+ end
14
+
15
+ it "should GET files with curl" do
16
+ Gem::Micro::Downloader.expects(:system).with("#{Gem::Micro::Downloader.curl_binary} --silent --location --output '#{@arguments[:local]}' '#{@arguments[:remote]}'").returns(true)
17
+ Gem::Micro::Downloader.get(@arguments[:remote], @arguments[:local])
18
+ end
19
+
20
+ it "should raise a DownloadError when something goes wrong" do
21
+ Gem::Micro::Downloader.expects(:system).returns(false)
22
+ lambda {
23
+ Gem::Micro::Downloader.get(@arguments[:remote], @arguments[:local])
24
+ }.should.raise(Gem::Micro::Downloader::DownloadError)
25
+ end
26
+ end
27
+
28
+ describe "DownloadError, in complex mode" do
29
+ before do
30
+ @arguments = {
31
+ :remote => 'http://gems.rubyforge.org/gems/rake-0.8.1.gem',
32
+ :local => File.join(TMP_PATH, 'gems', 'rake-0.8.1.gem')
33
+ }
34
+ FileUtils.rm_rf(File.join(TMP_PATH, 'gems'))
35
+ Gem::Micro::Config.stubs(:simple_downloader?).returns(false)
36
+ end
37
+
38
+ it "should GET files with Net::HTTP" do
39
+ stub_response('200', {
40
+ 'Content-Length' => '90112',
41
+ 'Content-Type' => 'application/x-tar',
42
+ 'Content-Encoding' => 'posix'
43
+ }, body = 'Gem body')
44
+
45
+ Gem::Micro::Downloader.get(@arguments[:remote], @arguments[:local])
46
+ File.should.exist(@arguments[:local])
47
+ File.read(@arguments[:local]).should == body
48
+ end
49
+
50
+ it "should raise a DownloadError when something goes wrong" do
51
+ stub_response('500', {
52
+ 'Content-Length' => '0',
53
+ 'Content-Type' => 'text/plain'
54
+ }, body = '')
55
+
56
+ lambda {
57
+ Gem::Micro::Downloader.get(@arguments[:remote], @arguments[:local])
58
+ }.should.raise(Gem::Micro::Downloader::DownloadError)
59
+
60
+ File.should.not.exist(@arguments[:local])
61
+ end
62
+
63
+ it "should follow redirects" do
64
+ stub_response('302', {
65
+ 'Location' => (location = 'http://rubyforge-gems.ruby-forum.com/gems/rake-0.8.1.gem'),
66
+ 'Content-Type' => 'text/html; charset=iso-8859-1'
67
+ }, body = '', 'http://gems.rubyforge.org/gems/rake-0.8.1.gem')
68
+ stub_response('200', {
69
+ 'Content-Length' => '90112',
70
+ 'Content-Type' => 'application/x-tar',
71
+ 'Content-Encoding' => 'posix'
72
+ }, body = 'Gem body', location)
73
+
74
+ Gem::Micro::Downloader.get(@arguments[:remote], @arguments[:local])
75
+ File.should.exist(@arguments[:local])
76
+ File.read(@arguments[:local]).should == body
77
+ end
78
+
79
+ private
80
+
81
+ def stub_response(status_code, headers, body, url=nil)
82
+ uri = URI.parse(url) unless url.nil?
83
+
84
+ explanation = {
85
+ '200' => ['OK', Net::HTTPOK],
86
+ '302' => ['Found', Net::HTTPFound],
87
+ '500' => ['Internal server error', Net::HTTPInternalServerError]
88
+ }
89
+ http_response = explanation[status_code].last.new('1.1', status_code, explanation[status_code].first)
90
+ http_response.stubs(:read_body).returns(body)
91
+ headers.each do |key, value|
92
+ http_response.add_field(key, value)
93
+ end
94
+ if uri.nil?
95
+ Net::HTTP.stubs(:start).returns(http_response)
96
+ else
97
+ Net::HTTP.stubs(:start).with(uri.host, uri.port).returns(http_response)
98
+ end
99
+ end
100
+ end
Binary file
Binary file
@@ -0,0 +1 @@
1
+ # stub
@@ -0,0 +1 @@
1
+ # stub
@@ -0,0 +1 @@
1
+ # stub
@@ -0,0 +1,26 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = %q{rails}
3
+ s.version = "2.1.1"
4
+
5
+ s.specification_version = 2 if s.respond_to? :specification_version=
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["David Heinemeier Hansson"]
9
+ s.date = %q{2008-09-04}
10
+ s.default_executable = %q{rails}
11
+ s.description = %q{Rails is a framework for building web-application using CGI, FCGI, mod_ruby, or WEBrick on top of either MySQL, PostgreSQL, SQLite, DB2, SQL Server, or Oracle with eRuby- or Builder-based templates.}
12
+ s.email = %q{david@loudthinking.com}
13
+ s.executables = ["rails"]
14
+ s.homepage = %q{http://www.rubyonrails.org}
15
+ s.require_paths = ["lib"]
16
+ s.rubyforge_project = %q{rails}
17
+ s.rubygems_version = '1.3.1'
18
+ s.summary = %q{Web-application framework with template engine, control-flow layer, and ORM.}
19
+
20
+ s.add_dependency(%q<rake>, [">= 0.8.1"])
21
+ s.add_dependency(%q<activesupport>, ["= 2.1.1"])
22
+ s.add_dependency(%q<activerecord>, ["= 2.1.1"])
23
+ s.add_dependency(%q<actionpack>, ["= 2.1.1"])
24
+ s.add_dependency(%q<actionmailer>, ["= 2.1.1"])
25
+ s.add_dependency(%q<activeresource>, ["= 2.1.1"])
26
+ end
Binary file
@@ -0,0 +1,20 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = "rake"
3
+ s.version = "0.8.1"
4
+
5
+ s.specification_version = 2 if s.respond_to? :specification_version=
6
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
7
+
8
+ s.authors = ["Jim Weirich"]
9
+ s.date = %q{2007-12-26}
10
+ s.default_executable = %q{rake}
11
+ s.description = %q{Rake is a Make-like program implemented in Ruby. Tasks and dependencies are specified in standard Ruby syntax.}
12
+ s.email = %q{jim@weirichhouse.org}
13
+ s.executables = ["rake"]
14
+ s.has_rdoc = true
15
+ s.homepage = %q{http://rake.rubyforge.org}
16
+ s.require_paths = ["lib"]
17
+ s.rubyforge_project = %q{rake}
18
+ s.rubygems_version = '1.3.1'
19
+ s.summary = %q{Ruby based make-like utility.}
20
+ end
@@ -0,0 +1,2 @@
1
+ x�e��J�@����-zPQP���Mo�E�E�Km���6�6c����As�}� xq�������:D��K��)ӁJ{���Oe,����[L�I���� �1�孜�j�$�G?��=!��������Ûm�@;
2
+ �L�i[�����!�F"��Kf=���,����NG\���"9ʊ��=��m<~"o].��Q ��T*Wn�6@�ڵ,J����o�9�X���f�8�=��}`F��=�ؠ���.B��d�7�{�5K�f���/Fhr�
Binary file
@@ -0,0 +1,198 @@
1
+ ##!/usr/bin/env macruby
2
+
3
+ require File.expand_path('../test_helper', __FILE__)
4
+
5
+ describe "Gem::Micro::Installer, in general" do
6
+ include Gem::Micro::Utils
7
+
8
+ def setup
9
+ @gem_spec = gem_spec_fixture('rake', '0.8.1')
10
+ @source = Gem::Micro::Source.new('gems.github.com', tmpdir)
11
+ @gem_spec.source = @source
12
+ @installer = Gem::Micro::Installer.new(@gem_spec)
13
+ end
14
+
15
+ def teardown
16
+ remove_microgem_tmpdir!
17
+ end
18
+
19
+ it "should return the url to download the gem from" do
20
+ @installer.url.should == "http://gems.github.com/gems/rake-0.8.1.gem"
21
+ end
22
+
23
+ it "should return the path to the install path" do
24
+ @installer.install_path.should ==
25
+ File.join(Gem::Micro::Config.gems_path, 'rake-0.8.1')
26
+ end
27
+
28
+ it "should return the path to the gem in the temporary work directory" do
29
+ @installer.work_dir.should ==
30
+ File.join(tmpdir, 'rake-0.8.1')
31
+ end
32
+
33
+ it "should return the path to the gems data directory in the temporary directory" do
34
+ @installer.data_dir.should ==
35
+ File.join(@installer.work_dir, 'data')
36
+ end
37
+
38
+ it "should return the path to the gems data archive in the temporary directory" do
39
+ @installer.data_file.should ==
40
+ File.join(@installer.work_dir, 'data.tar.gz')
41
+ end
42
+
43
+ it "should return the path to the gems metadata file in the temporary directory" do
44
+ @installer.metadata_file.should ==
45
+ File.join(@installer.work_dir, 'metadata')
46
+ end
47
+
48
+ it "should return the path to the gems metadata archive in the temporary directory" do
49
+ @installer.metadata_archive_file.should ==
50
+ File.join(@installer.work_dir, 'metadata.gz')
51
+ end
52
+
53
+ it "should download the gem to the work directory" do
54
+ Gem::Micro::Downloader.expects(:get).with(@installer.url, @installer.gem_file)
55
+ @installer.download
56
+ end
57
+
58
+ it "should unpack the gem using tar" do
59
+ @installer.stubs(:gem_file).returns(fixture('rake-0.8.1.gem'))
60
+ @installer.unpack
61
+ File.should.exist File.join(@installer.work_dir, 'data', 'README')
62
+ end
63
+
64
+ it "should reload the Gem::Specification from the metadata_file" do
65
+ @installer.stubs(:gem_file).returns(fixture('rake-0.8.1.gem'))
66
+ @installer.unpack
67
+
68
+ @installer.load_full_spec!
69
+ @installer.gem_spec.executables.should == %w{ rake }
70
+ end
71
+
72
+ it "should return the path to the Ruby `.gemspec' file" do
73
+ @installer.ruby_gemspec_file.should ==
74
+ File.join(Gem::Micro::Config.specifications_path, 'rake-0.8.1.gemspec')
75
+ end
76
+
77
+ it "should create a `.gemspec' file so RubyGems can find the gem" do
78
+ FileUtils.mkdir_p(File.dirname(@installer.ruby_gemspec_file))
79
+ @installer.create_ruby_gemspec!
80
+
81
+ File.read(@installer.ruby_gemspec_file).should == @gem_spec.to_ruby
82
+ end
83
+
84
+ it "should return the path to the gem cache directory" do
85
+ @installer.gem_cache_file.should ==
86
+ File.join(Gem::Micro::Config.cache_path, @gem_spec.gem_filename)
87
+ end
88
+
89
+ # FIXME: The marshalled gemspecs don't contain all data, we need to get this
90
+ # from the metadata.tar.gz archive in the gem.
91
+ it "should create bin wrappers for each executable" do
92
+ emitter = Gem::Micro::BinWrapperEmitter.new('rake', 'rake')
93
+ Gem::Micro::BinWrapperEmitter.expects(:new).with('rake', 'rake').returns(emitter)
94
+ emitter.expects(:create_bin_wrapper!)
95
+
96
+ @installer.stubs(:gem_file).returns(fixture('rake-0.8.1.gem'))
97
+ @installer.unpack
98
+ @installer.load_full_spec!
99
+
100
+ @installer.create_bin_wrappers!
101
+ end
102
+ end
103
+
104
+ describe "Gem::Micro::Installer.install" do
105
+ def setup
106
+ @gem_spec = Marshal.load(File.read(fixture('rake-0.8.1.gemspec.marshal')))
107
+ @installer = Gem::Micro::Installer.new(@gem_spec)
108
+ @installer.stubs(:download)
109
+ @installer.stubs(:unpack)
110
+ @installer.stubs(:load_full_spec!)
111
+ @installer.stubs(:create_ruby_gemspec!)
112
+ @installer.stubs(:create_bin_wrappers!)
113
+ @installer.stubs(:replace)
114
+ end
115
+
116
+ it "should install its dependencies that are not installed yet" do
117
+ #Gem::Micro::Source.expects(:gem_spec)
118
+
119
+ @gem_spec = Marshal.load(File.read(fixture('rails-2.1.1.gemspec.marshal')))
120
+ @installer.instance_variable_set(:@gem_spec, @gem_spec)
121
+
122
+ Gem::Micro::Config.stubs(:gems_path).returns(fixture('gems'))
123
+
124
+ @gem_spec.dependencies.each do |dep|
125
+ dep_gem_spec = mock('Dependency gem spec mock')
126
+ Gem::Micro::Source.stubs(:gem_spec).with(dep.name, dep.version_requirements.version).returns(dep_gem_spec)
127
+
128
+ if dep.name == 'rake'
129
+ dep_gem_spec.expects(:install!).never
130
+ else
131
+ dep_gem_spec.expects(:install!).once
132
+ end
133
+ end
134
+
135
+ @installer.install!
136
+ end
137
+
138
+ it "should download the gem" do
139
+ @installer.expects(:download)
140
+ @installer.install!
141
+ end
142
+
143
+ it "should unpack the gem" do
144
+ @installer.expects(:unpack)
145
+ @installer.install!
146
+ end
147
+
148
+ it "should load the full gem spec" do
149
+ @installer.expects(:load_full_spec!)
150
+ @installer.install!
151
+ end
152
+
153
+ it "should move the unpacked data directory of the gem to install_path" do
154
+ @installer.expects(:replace).with(@installer.data_dir, @installer.install_path)
155
+ @installer.install!
156
+ end
157
+
158
+ it "should move the gem file to gem_cache_file" do
159
+ @installer.expects(:replace).with(@installer.gem_file, @installer.gem_cache_file)
160
+ @installer.install!
161
+ end
162
+
163
+ it "should create bin wrappers" do
164
+ @installer.expects(:create_bin_wrappers!)
165
+ @installer.install!
166
+ end
167
+
168
+ it "should create a `.gemspec' file" do
169
+ @installer.expects(:create_ruby_gemspec!)
170
+ @installer.install!
171
+ end
172
+
173
+ it "should skip the actual installation of the gem _if_ after installing the dependencies it exists" do
174
+ File.expects(:exist?).with(@installer.install_path).returns(true)
175
+ @installer.expects(:download).never
176
+ @installer.expects(:unpack).never
177
+ @installer.expects(:load_full_spec!).never
178
+ @installer.expects(:replace).never
179
+ @installer.expects(:create_bin_wrappers!).never
180
+ @installer.expects(:create_ruby_gemspec!).never
181
+
182
+ @installer.install!
183
+ end
184
+
185
+ it "should _not_ skip the actual installation of the gem _if_ Config.force? returns `true'" do
186
+ File.stubs(:exist?).returns(true)
187
+ Gem::Micro::Config.stubs(:force?).returns(true)
188
+
189
+ @installer.expects(:download).times(1)
190
+ @installer.expects(:unpack).times(1)
191
+ @installer.expects(:load_full_spec!).times(1)
192
+ @installer.expects(:replace).times(2)
193
+ @installer.expects(:create_bin_wrappers!).times(1)
194
+ @installer.expects(:create_ruby_gemspec!).times(1)
195
+
196
+ @installer.install!
197
+ end
198
+ end
@@ -0,0 +1,34 @@
1
+ ##!/usr/bin/env macruby
2
+
3
+ require File.expand_path('../test_helper', __FILE__)
4
+
5
+ describe "Gem::Micro" do
6
+ def setup
7
+ Gem::Micro::Config.stubs(:gems_path).returns(fixture('gems'))
8
+ end
9
+
10
+ it "should return an array of all installed gems" do
11
+ Gem::Micro.installed_gem_dirnames.should ==
12
+ %w{ rake-0.8.0 rake-0.8.1 test-spec-0.3.0 test-spec-mock-0.3.0 }
13
+ end
14
+
15
+ it "should return an array of all installed gems matching the given name" do
16
+ Gem::Micro.installed_gem_dirnames('rake').should == %w{ rake-0.8.0 rake-0.8.1 }
17
+ Gem::Micro.installed_gem_dirnames('test-spec').should == %w{ test-spec-0.3.0 }
18
+ Gem::Micro.installed_gem_dirnames('test-spec-mock').should == %w{ test-spec-mock-0.3.0 }
19
+ end
20
+
21
+ it "should start the installation process of a gem" do
22
+ gem_spec = Marshal.load(File.read(fixture('rake-0.8.1.gemspec.marshal')))
23
+ Gem::Micro::Source.expects(:gem_spec).with('rake', Gem::Version[:version => '0']).returns(gem_spec)
24
+
25
+ gem_spec.expects(:install!)
26
+
27
+ Gem::Micro.run(%w{ install rake })
28
+ end
29
+
30
+ it "should update the source indices" do
31
+ Gem::Micro::Source.expects(:update!)
32
+ Gem::Micro.run(%w{ sources update })
33
+ end
34
+ end