dpkg-tools 0.3.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (100) hide show
  1. data/CHANGES +198 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README +17 -0
  4. data/Rakefile +1 -0
  5. data/bin/dpkg-etc +6 -0
  6. data/bin/dpkg-gem +6 -0
  7. data/bin/dpkg-rails +6 -0
  8. data/lib/dpkg-tools.rb +6 -0
  9. data/lib/dpkg-tools/command_line.rb +142 -0
  10. data/lib/dpkg-tools/package.rb +30 -0
  11. data/lib/dpkg-tools/package/builder.rb +112 -0
  12. data/lib/dpkg-tools/package/config.rb +96 -0
  13. data/lib/dpkg-tools/package/control_files.rb +24 -0
  14. data/lib/dpkg-tools/package/control_files/base.rb +75 -0
  15. data/lib/dpkg-tools/package/control_files/changelog.rb +23 -0
  16. data/lib/dpkg-tools/package/control_files/control.rb +148 -0
  17. data/lib/dpkg-tools/package/control_files/copyright.rb +27 -0
  18. data/lib/dpkg-tools/package/control_files/rakefile.rb +28 -0
  19. data/lib/dpkg-tools/package/control_files/rules.rb +29 -0
  20. data/lib/dpkg-tools/package/data.rb +125 -0
  21. data/lib/dpkg-tools/package/etc.rb +26 -0
  22. data/lib/dpkg-tools/package/etc/builder.rb +19 -0
  23. data/lib/dpkg-tools/package/etc/control_files.rb +22 -0
  24. data/lib/dpkg-tools/package/etc/control_files/changelog.rb +30 -0
  25. data/lib/dpkg-tools/package/etc/control_files/rakefile.rb +18 -0
  26. data/lib/dpkg-tools/package/etc/data.rb +48 -0
  27. data/lib/dpkg-tools/package/etc/rake.rb +31 -0
  28. data/lib/dpkg-tools/package/etc/setup.rb +30 -0
  29. data/lib/dpkg-tools/package/fs_methods.rb +10 -0
  30. data/lib/dpkg-tools/package/gem.rb +43 -0
  31. data/lib/dpkg-tools/package/gem/builder.rb +77 -0
  32. data/lib/dpkg-tools/package/gem/control_files.rb +23 -0
  33. data/lib/dpkg-tools/package/gem/control_files/changelog.rb +19 -0
  34. data/lib/dpkg-tools/package/gem/control_files/copyright.rb +24 -0
  35. data/lib/dpkg-tools/package/gem/control_files/rakefile.rb +19 -0
  36. data/lib/dpkg-tools/package/gem/data.rb +115 -0
  37. data/lib/dpkg-tools/package/gem/gem_format.rb +10 -0
  38. data/lib/dpkg-tools/package/gem/rake.rb +37 -0
  39. data/lib/dpkg-tools/package/gem/setup.rb +159 -0
  40. data/lib/dpkg-tools/package/rails.rb +26 -0
  41. data/lib/dpkg-tools/package/rails/builder.rb +77 -0
  42. data/lib/dpkg-tools/package/rails/cap.rb +30 -0
  43. data/lib/dpkg-tools/package/rails/control_files.rb +22 -0
  44. data/lib/dpkg-tools/package/rails/control_files/changelog.rb +19 -0
  45. data/lib/dpkg-tools/package/rails/control_files/rakefile.rb +24 -0
  46. data/lib/dpkg-tools/package/rails/data.rb +160 -0
  47. data/lib/dpkg-tools/package/rails/rake.rb +40 -0
  48. data/lib/dpkg-tools/package/rails/setup.rb +84 -0
  49. data/lib/dpkg-tools/package/rake.rb +90 -0
  50. data/lib/dpkg-tools/package/setup.rb +145 -0
  51. data/lib/dpkg-tools/version.rb +23 -0
  52. data/spec/dpkg-tools/command_line_spec.rb +9 -0
  53. data/spec/dpkg-tools/package/builder_spec.rb +159 -0
  54. data/spec/dpkg-tools/package/config_spec.rb +150 -0
  55. data/spec/dpkg-tools/package/control_files/base_spec.rb +111 -0
  56. data/spec/dpkg-tools/package/control_files/changelog_spec.rb +22 -0
  57. data/spec/dpkg-tools/package/control_files/control_spec.rb +131 -0
  58. data/spec/dpkg-tools/package/control_files/copyright_spec.rb +29 -0
  59. data/spec/dpkg-tools/package/control_files/rakefile_spec.rb +37 -0
  60. data/spec/dpkg-tools/package/control_files/rules_spec.rb +16 -0
  61. data/spec/dpkg-tools/package/control_files_spec.rb +12 -0
  62. data/spec/dpkg-tools/package/data_spec.rb +115 -0
  63. data/spec/dpkg-tools/package/etc/builder_spec.rb +28 -0
  64. data/spec/dpkg-tools/package/etc/control_files/changelog_spec.rb +21 -0
  65. data/spec/dpkg-tools/package/etc/control_files/rakefile_spec.rb +16 -0
  66. data/spec/dpkg-tools/package/etc/control_files_spec.rb +12 -0
  67. data/spec/dpkg-tools/package/etc/data_spec.rb +74 -0
  68. data/spec/dpkg-tools/package/etc/rake_spec.rb +71 -0
  69. data/spec/dpkg-tools/package/etc/setup_spec.rb +62 -0
  70. data/spec/dpkg-tools/package/etc_spec.rb +39 -0
  71. data/spec/dpkg-tools/package/fs_methods_spec.rb +33 -0
  72. data/spec/dpkg-tools/package/gem/builder_spec.rb +84 -0
  73. data/spec/dpkg-tools/package/gem/control_files/changelog_spec.rb +25 -0
  74. data/spec/dpkg-tools/package/gem/control_files/copyright_spec.rb +28 -0
  75. data/spec/dpkg-tools/package/gem/control_files/rakefile_spec.rb +17 -0
  76. data/spec/dpkg-tools/package/gem/control_files_spec.rb +12 -0
  77. data/spec/dpkg-tools/package/gem/data_spec.rb +176 -0
  78. data/spec/dpkg-tools/package/gem/gem_format_spec.rb +26 -0
  79. data/spec/dpkg-tools/package/gem/rake_spec.rb +102 -0
  80. data/spec/dpkg-tools/package/gem/setup_spec.rb +274 -0
  81. data/spec/dpkg-tools/package/gem_spec.rb +68 -0
  82. data/spec/dpkg-tools/package/rails/builder_spec.rb +113 -0
  83. data/spec/dpkg-tools/package/rails/cap_spec.rb +37 -0
  84. data/spec/dpkg-tools/package/rails/control_files/changelog_spec.rb +25 -0
  85. data/spec/dpkg-tools/package/rails/control_files/rakefile_spec.rb +24 -0
  86. data/spec/dpkg-tools/package/rails/control_files_spec.rb +12 -0
  87. data/spec/dpkg-tools/package/rails/data_spec.rb +178 -0
  88. data/spec/dpkg-tools/package/rails/rake_spec.rb +78 -0
  89. data/spec/dpkg-tools/package/rails/setup_spec.rb +152 -0
  90. data/spec/dpkg-tools/package/rails_spec.rb +27 -0
  91. data/spec/dpkg-tools/package/rake_spec.rb +87 -0
  92. data/spec/dpkg-tools/package/setup_spec.rb +247 -0
  93. data/spec/dpkg-tools/package_spec.rb +34 -0
  94. data/spec/fixtures/BlueCloth-1.0.0.gem +1190 -0
  95. data/spec/fixtures/database.yml +33 -0
  96. data/spec/spec.opts +1 -0
  97. data/spec/spec_helper.rb +52 -0
  98. data/tasks/dist.rake +118 -0
  99. data/tasks/rspec.rake +21 -0
  100. metadata +165 -0
@@ -0,0 +1,25 @@
1
+ require File.dirname(__FILE__) + '/../../../../spec_helper'
2
+
3
+ describe DpkgTools::Package::Gem::ControlFiles::Changelog, "#changelog" do
4
+ before(:each) do
5
+ config = DpkgTools::Package::Config.new('gem-name', '1.0.8', :suffix => 'rubygem')
6
+ stub_data = stub('DpkgTools::Package::Gem::Data', :full_name => 'gem-name-1.0.8', :debian_revision => '1')
7
+ @metadata = DpkgTools::Package::Gem::ControlFiles::Changelog.new(stub_data, config)
8
+ end
9
+
10
+ it "should be able to generate the current time formatted as per RFC 822" do
11
+ mock_time = mock('Time')
12
+ mock_time.expects(:rfc822).returns('rfc_time')
13
+ Time.expects(:now).returns(mock_time)
14
+
15
+ @metadata.change_time.should == 'rfc_time'
16
+ end
17
+
18
+ it "should be able to generate a changelog" do
19
+ @metadata.expects(:change_time).returns('RFC 822 change time')
20
+
21
+ @metadata.changelog.should == "gem-name-rubygem (1.0.8-1) cp-gutsy; urgency=low\n"\
22
+ " * Packaged up gem-name-1.0.8\n"\
23
+ " -- Matt Patterson <matt@reprocessed.org> RFC 822 change time\n"
24
+ end
25
+ end
@@ -0,0 +1,28 @@
1
+ require File.dirname(__FILE__) + '/../../../../spec_helper'
2
+
3
+ describe DpkgTools::Package::Gem::ControlFiles::Copyright, "#license_file" do
4
+ it "should be able to locate and return the Gem's license file" do
5
+ stub_data = stub('stub DpkgTools::Package::Gem::Data', :files => ["LICENSE"],
6
+ :file_entries => [[{"path" => "LICENSE"}, "License file text"]])
7
+ metadata = DpkgTools::Package::Gem::ControlFiles::Copyright.new(stub_data, :config)
8
+
9
+ metadata.license_file.should == "License file text"
10
+ end
11
+
12
+ it "should be able to cope with nil entries in data.files (as seen in the mysql gem)" do
13
+ stub_data = stub('stub DpkgTools::Package::Gem::Data', :files => ["LICENSE", nil],
14
+ :file_entries => [[{"path" => "LICENSE"}, "License file text"]])
15
+ metadata = DpkgTools::Package::Gem::ControlFiles::Copyright.new(stub_data, :config)
16
+
17
+ metadata.license_file.should == "License file text"
18
+ end
19
+
20
+ it "should be able to locate licenses called COPYING" do
21
+ stub_data = stub('stub DpkgTools::Package::Gem::Data', :files => ["COPYING"],
22
+ :file_entries => [[{"path" => "COPYING"}, "License file text"]])
23
+ metadata = DpkgTools::Package::Gem::ControlFiles::Copyright.new(stub_data, :config)
24
+
25
+ metadata.license_file.should == "License file text"
26
+ end
27
+ end
28
+
@@ -0,0 +1,17 @@
1
+ require File.dirname(__FILE__) + '/../../../../spec_helper'
2
+
3
+ describe DpkgTools::Package::Gem::ControlFiles::Rakefile do
4
+ it "should be able to generate the contents of the Rakefile" do
5
+ config = DpkgTools::Package::Config.new("gem-name", "1.0.8", :suffix => 'rubygem')
6
+ stub_data = stub("DpkgTools::Package::Gem::Data", :full_name => "gem-name-1.0.8")
7
+ metadata = DpkgTools::Package::Gem::ControlFiles::Rakefile.new(stub_data, config)
8
+
9
+ metadata.rakefile.should == "require 'rubygems'\n" \
10
+ "require 'dpkg-tools'\n" \
11
+ "\n" \
12
+ "DpkgTools::Package::Gem::BuildTasks.new do |t|\n" \
13
+ " t.root_path = File.dirname(Rake.original_dir)\n" \
14
+ " t.gem_path = File.join(Rake.original_dir, 'gem-name-1.0.8.gem')\n" \
15
+ "end\n"
16
+ end
17
+ end
@@ -0,0 +1,12 @@
1
+ require File.dirname(__FILE__) + '/../../../spec_helper'
2
+
3
+ describe DpkgTools::Package::Gem::ControlFiles do
4
+ it "should provide access to the list of control file classes" do
5
+ DpkgTools::Package::Gem::ControlFiles.classes.
6
+ should == [DpkgTools::Package::Gem::ControlFiles::Changelog,
7
+ DpkgTools::Package::ControlFiles::Control,
8
+ DpkgTools::Package::Gem::ControlFiles::Copyright,
9
+ DpkgTools::Package::Gem::ControlFiles::Rakefile,
10
+ DpkgTools::Package::ControlFiles::Rules]
11
+ end
12
+ end
@@ -0,0 +1,176 @@
1
+ require File.dirname(__FILE__) + '/../../../spec_helper'
2
+
3
+ describe DpkgTools::Package::Gem::Data do
4
+ it "should report its resources_dirname correctly" do
5
+ DpkgTools::Package::Gem::Data.resources_dirname.should == 'gem'
6
+ end
7
+ end
8
+
9
+ describe DpkgTools::Package::Gem::Data, ".native_extension_deps (managing c-library deps for gems which compile native extensions)" do
10
+ it "should be able to retrieve a list of deps given a gem name and version number" do
11
+ DpkgTools::Package::Gem::Data.stubs(:native_extensions_deps_map).returns({'name' => {'1.0.8' => [{:name => 'package-devel'}]}})
12
+ DpkgTools::Package::Gem::Data.native_extension_deps('name', '1.0.8').should == [{:name => 'package-devel'}]
13
+ end
14
+
15
+ it "should be able to retrieve a list of deps given a gem name and version number even if no specific deps for that version exist" do
16
+ DpkgTools::Package::Gem::Data.stubs(:native_extensions_deps_map).returns({'name' => {'all' => [{:name => 'package-devel'}]}})
17
+ DpkgTools::Package::Gem::Data.native_extension_deps('name', '1.0.8').should == [{:name => 'package-devel'}]
18
+ end
19
+ end
20
+
21
+ describe DpkgTools::Package::Gem::Data, ".native_extensions_deps_map (managing c-library deps for gems which compile native extensions)" do
22
+ it "should load its map of gems with native extensions -> deps from a YAML file" do
23
+ DpkgTools::Package::Gem::Data.stubs(:resources_path).returns('/a/path/to')
24
+ YAML.expects(:load_file).with('/a/path/to/gems_to_deps.yml').returns(:hash)
25
+ DpkgTools::Package::Gem::Data.expects(:process_extensions_map).with(:hash).returns(:hash)
26
+ DpkgTools::Package::Gem::Data.native_extensions_deps_map.should == :hash
27
+ end
28
+
29
+ it "should cache the result of process_extensions_map" do
30
+ DpkgTools::Package::Gem::Data.send(:remove_instance_variable, :@native_extensions_deps_map)
31
+ YAML.stubs(:load_file).returns(:hash)
32
+ DpkgTools::Package::Gem::Data.expects(:process_extensions_map).with(:hash).returns(:hash)
33
+ DpkgTools::Package::Gem::Data.native_extensions_deps_map.should == :hash
34
+ DpkgTools::Package::Gem::Data.native_extensions_deps_map.should == :hash
35
+ end
36
+ end
37
+
38
+ describe DpkgTools::Package::Gem::Data, ".process_extensions_map (managing c-library deps for gems which compile native extensions)" do
39
+ it "should be able to process a gem entry with a single specific version with a single dep" do
40
+ input_hash = {'name' => {'1.0.8' => 'dep'}}
41
+ DpkgTools::Package::Gem::Data.process_extensions_map(input_hash).should == {'name' => {'1.0.8' => [{:name => 'dep'}]}}
42
+ end
43
+
44
+ it "should be able to process a gem entry with a single specific version with multiple deps" do
45
+ input_hash = {'name' => {'1.0.8' => ['dep1', 'dep2']}}
46
+ DpkgTools::Package::Gem::Data.process_extensions_map(input_hash).should == {'name' => {'1.0.8' => [{:name => 'dep1'}, {:name => 'dep2'}]}}
47
+ end
48
+
49
+ it "should be able to process a gem entry with a single dep" do
50
+ input_hash = {'name' => 'dep'}
51
+ DpkgTools::Package::Gem::Data.process_extensions_map(input_hash).should == {'name' => {'all' => [{:name => 'dep'}]}}
52
+ end
53
+
54
+ it "should be able to process a gem entry with multiple deps" do
55
+ input_hash = {'name' => ['dep1', 'dep2']}
56
+ DpkgTools::Package::Gem::Data.process_extensions_map(input_hash).should == {'name' => {'all' => [{:name => 'dep1'}, {:name => 'dep2'}]}}
57
+ end
58
+
59
+ it "should be able to process a gem entry with a single dep" do
60
+ input_hash = {'name' => 'dep'}
61
+ DpkgTools::Package::Gem::Data.process_extensions_map(input_hash).should == {'name' => {'all' => [{:name => 'dep'}]}}
62
+ end
63
+
64
+ it "should be able to process a gem entry with multiple deps" do
65
+ input_hash = {'name' => ['dep1', 'dep2']}
66
+ DpkgTools::Package::Gem::Data.process_extensions_map(input_hash).should == {'name' => {'all' => [{:name => 'dep1'}, {:name => 'dep2'}]}}
67
+ end
68
+
69
+ it "should be able to process a gem entry where the version is processed into a Float" do
70
+ input_hash = {'name' => {1.0 => 'dep'}}
71
+ DpkgTools::Package::Gem::Data.process_extensions_map(input_hash).should == {'name' => {'1.0' => [{:name => 'dep'}]}}
72
+ end
73
+
74
+ it "should be able to process a gem entries with multiple deps and a mixed style" do
75
+ input_hash = {'mysql' => {2.6 => 'libmysqlclient-dev', 2.7 => ['libmysqlclient-dev', 'other-dep']}}
76
+ expected_hash = {'mysql' => {'2.6' => [{:name => 'libmysqlclient-dev'}], '2.7' => [{:name => 'libmysqlclient-dev'}, {:name => 'other-dep'}]}}
77
+ DpkgTools::Package::Gem::Data.process_extensions_map(input_hash).should == expected_hash
78
+ end
79
+ end
80
+
81
+ describe DpkgTools::Package::Gem::Data, ".new" do
82
+ it "should raise an error without any arguments" do
83
+ lambda { DpkgTools::Package::Gem::Data.new }.should raise_error
84
+ end
85
+
86
+ it "should require one argument" do
87
+ version = stub('Version', :to_s => '1.0.8')
88
+ stub_spec = stub("stub Gem::Specification", :name => 'gem_name', :version => version,
89
+ :full_name => 'gem_name-1.0.8', :dependencies => :deps,
90
+ :summary => 'A gem', :files => :files)
91
+ stub_format = stub('stub Gem::Format', :spec => stub_spec)
92
+
93
+ DpkgTools::Package::Gem::Data.new(stub_format, 'gem_byte_string')
94
+ end
95
+ end
96
+
97
+ describe DpkgTools::Package::Gem::Data, "instances" do
98
+ before(:each) do
99
+ DpkgTools::Package::Config.root_path = '/a/path/to'
100
+ version = stub('Version', :to_s => '1.0.8')
101
+ stub_requirement = stub('stub Gem::Requirement', :as_list => [">= 0.0.0"])
102
+ @mock_dep_list = [stub('stub Gem::Dependency', :name => 'whatagem', :version_requirements => stub_requirement)]
103
+ @spec = stub("stub Gem::Specification", :name => 'gem_name', :version => version,
104
+ :full_name => 'gem_name-1.0.8', :dependencies => @mock_dep_list,
105
+ :summary => 'A gem', :files => :files, :extensions => [])
106
+ @format = stub("stub Gem::Format", :spec => @spec, :file_entries => :file_entries)
107
+ @data = DpkgTools::Package::Gem::Data.new(@format, 'gem_byte_string')
108
+ end
109
+
110
+ it "should provide access to its gem_byte_string" do
111
+ @data.gem_byte_string.should == 'gem_byte_string'
112
+ end
113
+
114
+ it "should provide access to their Gem::Spec" do
115
+ @data.spec.should == @spec
116
+ end
117
+
118
+ it "should provide access to its name" do
119
+ @data.name.should == 'gem_name'
120
+ end
121
+
122
+ it "should convert the Gem::Version object to a string" do
123
+ @data.version.should == '1.0.8'
124
+ end
125
+
126
+ it "should provide access to its full_name" do
127
+ @data.full_name.should == 'gem_name-1.0.8'
128
+ end
129
+
130
+ it "should provide access to the Gem::Format's file_entries attribute" do
131
+ @data.file_entries.should == :file_entries
132
+ end
133
+
134
+ it "should provide access to the Gem::Specification's files attribute" do
135
+ @data.files.should == :files
136
+ end
137
+
138
+ it "should provide access to the changelog-derived debian_revision" do
139
+ @data.debian_revision.should == "1"
140
+ end
141
+
142
+ it "should provide access to the debian architecture name" do
143
+ @data.debian_arch.should == "all"
144
+ end
145
+
146
+ it "should provide report the debian architecture name as i386 if spec.extensions is not empty" do
147
+ @spec.stubs(:extensions).returns(['extconf.rb'])
148
+ @data.debian_arch.should == "i386"
149
+ end
150
+
151
+ it "should be able to generate a sensible list of deps" do
152
+ @data.send(:base_deps).should == [{:name => "whatagem-rubygem", :requirements => [">= 0.0.0-1"]}]
153
+ end
154
+
155
+ it "should provide access to any install-time dependencies" do
156
+ @data.dependencies.should == [{:name => "rubygems", :requirements => [">= 0.9.4-1"]},
157
+ {:name => "whatagem-rubygem", :requirements => [">= 0.0.0-1"]}]
158
+ end
159
+
160
+ it "should provide access to any build-time dependencies" do
161
+ DpkgTools::Package::Gem::Data.stubs(:native_extension_deps).with('gem_name', '1.0.8').returns([{:name => 'libblah-devel'}])
162
+ @data.build_dependencies.should == [{:name => "rubygems", :requirements => [">= 0.9.4-1"]},
163
+ {:name => "rake-rubygem", :requirements => [">= 0.7.0-1"]},
164
+ {:name => "dpkg-tools-rubygem", :requirements => [">= #{DpkgTools::VERSION::STRING}-1"]},
165
+ {:name => "whatagem-rubygem", :requirements => [">= 0.0.0-1"]},
166
+ {:name => 'libblah-devel'}]
167
+ end
168
+
169
+ it "should provide access to the summary from the spec" do
170
+ @data.summary.should == @spec.summary
171
+ end
172
+
173
+ it "should provide access to the information DpkgTools::Package::Config needs to generate the package Rakefile's path" do
174
+ @data.rakefile_location.should == [:base_path, 'Rakefile']
175
+ end
176
+ end
@@ -0,0 +1,26 @@
1
+ require File.dirname(__FILE__) + '/../../../spec_helper'
2
+ require File.dirname(__FILE__) + '/../../../../lib/dpkg-tools/package/gem/gem_format'
3
+
4
+ describe DpkgTools::Package::Gem::GemFormat do
5
+ before(:each) do
6
+ klass = Class.new
7
+ klass.send(:include, DpkgTools::Package::Gem::GemFormat)
8
+ @module = klass.new
9
+ end
10
+
11
+ describe "creating Gem::Format objects" do
12
+ it "should be able to turn a byte string of a gem into a Gem::Format" do
13
+ StringIO.expects(:new).with('gem_byte_string').returns(:string_io)
14
+ Gem::Format.expects(:from_io).with(:string_io)
15
+
16
+ @module.format_from_string('gem_byte_string')
17
+ end
18
+
19
+ it "should be able to turn an old-format gem's byte string into a Gem::OldFormat" do
20
+ StringIO.expects(:new).with(anything).returns(:string_io)
21
+ Gem::OldFormat.expects(:from_io).with(:string_io)
22
+
23
+ @module.format_from_string(File.read(File.dirname(__FILE__) + '/../../../fixtures/BlueCloth-1.0.0.gem'))
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,102 @@
1
+ require File.dirname(__FILE__) + '/../../../spec_helper'
2
+
3
+ require 'rake'
4
+
5
+ describe DpkgTools::Package::Gem::BuildTasks, "task creation" do
6
+ it "check_setup should be fine if base_path is defined" do
7
+ DpkgTools::Package::Gem::BuildTasks.any_instance.stubs(:define_tasks)
8
+ DpkgTools::Package::Gem::BuildTasks.any_instance.stubs(:define_base_tasks)
9
+
10
+ result = DpkgTools::Package::Gem::BuildTasks.new do |t|
11
+ t.gem_path = 'gem_path'
12
+ t.root_path = 'root_path'
13
+ end
14
+ result.gem_path.should == 'gem_path'
15
+ result.root_path.should == 'root_path'
16
+ end
17
+
18
+ it "should raise an error if gem_path and root_path haven't been defined" do
19
+ lambda { DpkgTools::Package::Gem::BuildTasks.new }.should raise_error(ArgumentError)
20
+ end
21
+
22
+ it "should set DpkgTools::Package::Config.root_path correctly" do
23
+ DpkgTools::Package::Gem::BuildTasks.any_instance.stubs(:define_tasks)
24
+ DpkgTools::Package::Gem::BuildTasks.any_instance.stubs(:define_base_tasks)
25
+
26
+ DpkgTools::Package::Config.expects(:root_path=).with('root_path')
27
+
28
+ DpkgTools::Package::Gem::BuildTasks.new do |t|
29
+ t.gem_path = 'gem_path'
30
+ t.root_path = 'root_path'
31
+ end
32
+ end
33
+
34
+ it "should define the needed tasks" do
35
+ build_tasks = DpkgTools::Package::Gem::BuildTasks.new do |t|
36
+ t.gem_path = 'gem_path'
37
+ t.root_path = 'root_path'
38
+ end
39
+
40
+ build_tasks.expects(:task).with("binary-arch")
41
+ build_tasks.expects(:task).with("binary-indep")
42
+ build_tasks.expects(:task).with("build-arch")
43
+ build_tasks.expects(:task).with("build-indep")
44
+
45
+ build_tasks.define_tasks
46
+ end
47
+
48
+ it "should be able to return a properly instantiated Builder from create_builder" do
49
+ build_tasks = DpkgTools::Package::Gem::BuildTasks.new do |t|
50
+ t.gem_path = 'gem_path'
51
+ t.root_path = 'root_path'
52
+ end
53
+
54
+ DpkgTools::Package::Gem.expects(:create_builder).with('gem_path').returns(:builder)
55
+
56
+ build_tasks.create_builder.should == :builder
57
+ end
58
+ end
59
+
60
+ describe DpkgTools::Package::Gem::BuildTasks, "rake tasks" do
61
+ before(:each) do
62
+ @rake = Rake::Application.new
63
+ Rake.application = @rake
64
+
65
+ @build_tasks = DpkgTools::Package::Gem::BuildTasks.new do |t|
66
+ t.gem_path = "path/to/gem_file.gem"
67
+ t.root_path = "path"
68
+ end
69
+ end
70
+
71
+ after(:each) do
72
+ Rake.application = nil
73
+ end
74
+
75
+ it "should properly call the DpkgTools::Package::Gem.create_builder from the task 'binary-arch'" do
76
+ mock_builder = mock('mock DpkgTools::Package::Gem::Builder')
77
+ mock_builder.expects(:binary_package)
78
+ @build_tasks.expects(:create_builder).returns(mock_builder)
79
+ @rake["binary-arch"].invoke
80
+ end
81
+
82
+ it "should properly call the DpkgTools::Package::Gem.create_builder from the task 'binary-indep'" do
83
+ mock_builder = mock('mock DpkgTools::Package::Gem::Builder')
84
+ mock_builder.expects(:binary_package)
85
+ @build_tasks.expects(:create_builder).returns(mock_builder)
86
+ @rake["binary-indep"].invoke
87
+ end
88
+
89
+ it "should properly call the DpkgTools::Package::Gem.create_builder from the task 'build-arch'" do
90
+ mock_builder = mock('mock DpkgTools::Package::Gem::Builder')
91
+ mock_builder.expects(:build_package)
92
+ @build_tasks.expects(:create_builder).returns(mock_builder)
93
+ @rake["build-arch"].invoke
94
+ end
95
+
96
+ it "should properly call the DpkgTools::Package::Gem.create_builder from the task 'build-indep'" do
97
+ mock_builder = mock('mock DpkgTools::Package::Gem::Builder')
98
+ mock_builder.expects(:build_package)
99
+ @build_tasks.expects(:create_builder).returns(mock_builder)
100
+ @rake["build-indep"].invoke
101
+ end
102
+ end
@@ -0,0 +1,274 @@
1
+ require File.dirname(__FILE__) + '/../../../spec_helper'
2
+
3
+ describe DpkgTools::Package::Gem::Setup do
4
+ # it "should be able to create the .orig.tar.gz containing a correctly named folder and the .gem" do
5
+ # # not really sure how to test this meaningfully
6
+ # #DpkgTools::Package::Gem.write_orig_tarball
7
+ # end
8
+
9
+ it "should be able to write a .gem file to the correct place" do
10
+ config = stub("DpkgTools::Package::Config", :gem_path => 'a/path/to/.gem')
11
+ mock_file = mock('mock File')
12
+ mock_file.expects(:write).with('gem byte string')
13
+ File.expects(:open).with('a/path/to/.gem', 'wb').yields(mock_file)
14
+
15
+ DpkgTools::Package::Gem::Setup.write_gem_file(config, 'gem byte string')
16
+ end
17
+
18
+ it "should be able to retrieve a gem given its URL" do
19
+ Gem::RemoteFetcher.fetcher.expects(:fetch_path).with(:uri).returns(:gem_byte_string)
20
+ DpkgTools::Package::Gem::Setup.gem_file_from_uri(:uri).should == :gem_byte_string
21
+ end
22
+
23
+ it "should be able to retrieve the latest Gem:::Platform::RUBY version from a list of specs and sources " do
24
+ specs_n_sources = [[stub('spec', :platform => Gem::Platform::WIN32), 'a_uri'],
25
+ [stub('spec', :platform => Gem::Platform::RUBY), 'a_second_uri'],
26
+ [stub('spec', :platform => Gem::Platform::RUBY), 'a_third_uri']]
27
+
28
+ DpkgTools::Package::Gem::Setup.most_recent_spec_n_source(specs_n_sources)[1].should == 'a_second_uri'
29
+ end
30
+
31
+ it "should be able to retrieve the latest version where @spec.platform is unset (where it notionally defaults to RUBY)" do
32
+ specs_n_sources = [[stub('spec', :platform => Gem::Platform::WIN32), 'a_uri'],
33
+ [stub('spec', :platform => nil), 'a_second_uri'],
34
+ [stub('spec', :platform => nil), 'a_third_uri']]
35
+
36
+ DpkgTools::Package::Gem::Setup.most_recent_spec_n_source(specs_n_sources)[1].should == 'a_second_uri'
37
+ end
38
+
39
+ it "should be able to retrieve specs and sources for a named gem" do
40
+ mock_installer = mock('mock Gem::RemoteInstaller instance')
41
+ mock_installer.expects(:specs_n_sources_matching).with('gem_name', anything).returns(:specs_n_sources)
42
+ Gem::RemoteInstaller.expects(:new).returns(mock_installer)
43
+
44
+ DpkgTools::Package::Gem::Setup.specs_n_sources_for_name('gem_name').should == :specs_n_sources
45
+ end
46
+
47
+ it "should be able to retrieve the most recent spec and source uri for a named gem" do
48
+ DpkgTools::Package::Gem::Setup.expects(:most_recent_spec_n_source).with(:specs_n_sources).returns(:most_recent)
49
+ DpkgTools::Package::Gem::Setup.expects(:specs_n_sources_for_name).with('gem_name').returns(:specs_n_sources)
50
+
51
+ DpkgTools::Package::Gem::Setup.spec_n_source_for_name('gem_name').should == :most_recent
52
+ end
53
+
54
+ it "should retrieve the Gem::Format and bytes for a gem given a path to the .gem file" do
55
+ File.expects(:read).with('path/to/package.gem').returns('gem byte string')
56
+ DpkgTools::Package::Gem::Setup.expects(:format_from_string).with('gem byte string').returns(:format)
57
+
58
+ DpkgTools::Package::Gem::Setup.format_and_file_from_path('path/to/package.gem').should == [:format, 'gem byte string']
59
+ end
60
+
61
+ it "should be able to create a new instance from a spec and source" do
62
+ DpkgTools::Package::Gem::Setup.expects(:gem_uri_from_spec_n_source).with(:spec, 'source_uri').returns('http://a/uri/to/gem_name.gem')
63
+ DpkgTools::Package::Gem::Setup.expects(:gem_file_from_uri).with('http://a/uri/to/gem_name.gem').returns('gem byte string')
64
+ DpkgTools::Package::Gem::Setup.expects(:format_from_string).with('gem byte string').returns(:format)
65
+
66
+ DpkgTools::Package::Gem::Data.expects(:new).with(:format, 'gem byte string').returns(:data)
67
+
68
+ DpkgTools::Package::Gem::Setup.expects(:new).with(:data).returns(:instance)
69
+
70
+ DpkgTools::Package::Gem::Setup.from_spec_and_source(:spec, 'source_uri').should == :instance
71
+ end
72
+
73
+ it "should be able to create a new instance from a spec and source via the cache" do
74
+ DpkgTools::Package::Gem::Setup.expects(:cache_key_from_spec).with(:spec).returns('gem_name-1.0.8')
75
+
76
+ DpkgTools::Package::Gem::Setup.dependency_cache.expects(:has_key?).with('gem_name-1.0.8').returns(false)
77
+
78
+ DpkgTools::Package::Gem::Setup.expects(:from_spec_and_source).with(:spec, 'source_uri').returns(:instance)
79
+
80
+ DpkgTools::Package::Gem::Setup.from_spec_and_source_via_cache(:spec, 'source_uri').should == :instance
81
+ end
82
+
83
+ it "should be able to create a new instance given a gem name, complete with DpkgTools::Package::Gem::Data" do
84
+ DpkgTools::Package::Gem::Setup.expects(:spec_n_source_for_name).with('gem_name').returns([:spec, 'source_uri'])
85
+ DpkgTools::Package::Gem::Setup.expects(:from_spec_and_source_via_cache).with(:spec, 'source_uri').returns(:instance)
86
+
87
+ DpkgTools::Package::Gem::Setup.from_name('gem_name').should == :instance
88
+ end
89
+
90
+ it "should be able to return an instance from the cache after a cache hit from a spec and source" do
91
+ DpkgTools::Package::Gem::Setup.expects(:cache_key_from_spec).with(:spec).returns('gem_name-1.0.8')
92
+
93
+ DpkgTools::Package::Gem::Setup.dependency_cache.expects(:has_key?).with('gem_name-1.0.8').returns(true)
94
+ DpkgTools::Package::Gem::Setup.dependency_cache.expects(:[]).with('gem_name-1.0.8').returns(:instance)
95
+ DpkgTools::Package::Gem::Setup.from_spec_and_source_via_cache(:spec, 'source_uri').should == :instance
96
+ end
97
+
98
+ it "should be able to create a new instance, complete with DpkgTools::Package::Gem::Data, given a path to a .gem" do
99
+ DpkgTools::Package::Gem::Data.expects(:new).with(:format, 'gem byte string').returns(:data)
100
+ DpkgTools::Package::Gem::Setup.expects(:new).with(:data).returns(:instance)
101
+ DpkgTools::Package::Gem::Setup.expects(:format_and_file_from_path).with('path/to/package.gem').returns([:format, 'gem byte string'])
102
+
103
+ DpkgTools::Package::Gem::Setup.from_path('path/to/package.gem').should == :instance
104
+ end
105
+
106
+ it "should be able to return the most recent spec_n_source that satisfies a Gem::Requirement from a spec_n_source" do
107
+ specs_n_sources = [[stub('spec', :platform => Gem::Platform::WIN32, :version => Gem::Version.create('1.1.8')), 'a_uri'],
108
+ [stub('spec', :platform => Gem::Platform::RUBY, :version => Gem::Version.create('1.1.8')), 'a_second_uri'],
109
+ [stub('spec', :platform => Gem::Platform::RUBY, :version => Gem::Version.create('1.1.0')), 'a_third_uri'],
110
+ [stub('spec', :platform => Gem::Platform::WIN32, :version => Gem::Version.create('1.0.8')), 'a_fourth_uri'],
111
+ [stub('spec', :platform => Gem::Platform::RUBY, :version => Gem::Version.create('1.0.8')), 'a_fifth_uri'],
112
+ [stub('spec', :platform => Gem::Platform::RUBY, :version => Gem::Version.create('1.0.2')), 'a_sixth_uri'],
113
+ [stub('spec', :platform => Gem::Platform::RUBY, :version => Gem::Version.create('0.9.8')), 'a_seventh_uri']]
114
+
115
+ requirement = Gem::Requirement.create(['< 1.1.0', '>= 1.0.0'])
116
+
117
+ DpkgTools::Package::Gem::Setup.most_recent_spec_n_source_satisfying_requirement(requirement, specs_n_sources)[1].
118
+ should == 'a_fifth_uri'
119
+ end
120
+
121
+ it "should be able to return the most recent spec_n_source that satisfies a Gem::Requirement from a spec_n_source, even when spec.platform is unset " do
122
+ specs_n_sources = [[stub('spec', :platform => Gem::Platform::WIN32, :version => Gem::Version.create('1.1.8')), 'a_uri'],
123
+ [stub('spec', :platform => Gem::Platform::RUBY, :version => Gem::Version.create('1.1.8')), 'a_second_uri'],
124
+ [stub('spec', :platform => nil, :version => Gem::Version.create('1.1.0')), 'a_third_uri'],
125
+ [stub('spec', :platform => Gem::Platform::WIN32, :version => Gem::Version.create('1.0.8')), 'a_fourth_uri'],
126
+ [stub('spec', :platform => nil, :version => Gem::Version.create('1.0.8')), 'a_fifth_uri'],
127
+ [stub('spec', :platform => Gem::Platform::RUBY, :version => Gem::Version.create('1.0.2')), 'a_sixth_uri'],
128
+ [stub('spec', :platform => Gem::Platform::RUBY, :version => Gem::Version.create('0.9.8')), 'a_seventh_uri']]
129
+
130
+ requirement = Gem::Requirement.create(['< 1.1.0', '>= 1.0.0'])
131
+
132
+ DpkgTools::Package::Gem::Setup.most_recent_spec_n_source_satisfying_requirement(requirement, specs_n_sources)[1].
133
+ should == 'a_fifth_uri'
134
+ end
135
+
136
+ it "should be able to return a spec_n_source that satisfies a Gem::Requirement from a name" do
137
+ DpkgTools::Package::Gem::Setup.expects(:most_recent_spec_n_source_satisfying_requirement).
138
+ with(:requirement, :specs_n_sources).returns(:spec_n_source)
139
+ DpkgTools::Package::Gem::Setup.expects(:specs_n_sources_for_name).with('gem_name').returns(:specs_n_sources)
140
+
141
+ DpkgTools::Package::Gem::Setup.spec_n_source_for_name_and_requirement('gem_name', :requirement).should == :spec_n_source
142
+ end
143
+
144
+ it "should be able to create a new instance from a gem name and version requirement" do
145
+ DpkgTools::Package::Gem::Setup.expects(:spec_n_source_for_name_and_requirement).with('gem_name', :requirement).returns([:spec, 'source_uri'])
146
+ DpkgTools::Package::Gem::Setup.expects(:from_spec_and_source_via_cache).with(:spec, 'source_uri').returns(:instance)
147
+
148
+ DpkgTools::Package::Gem::Setup.from_name_and_requirement('gem_name', :requirement).should == :instance
149
+ end
150
+
151
+ it "should provide access to a cache of dependencies" do
152
+ DpkgTools::Package::Gem::Setup.dependency_cache.should be_an_instance_of(Hash)
153
+ end
154
+
155
+ it "should persist the cache store between queries" do
156
+ DpkgTools::Package::Gem::Setup.dependency_cache.should === DpkgTools::Package::Gem::Setup.dependency_cache
157
+ end
158
+
159
+ it "should be able to generate a name, version cache key from a spec" do
160
+ mock_spec = mock('mock Gem::Specification')
161
+ mock_spec.expects(:name).returns('gem_name')
162
+ mock_version = mock('mock Gem::Version')
163
+ mock_version.expects(:to_s).returns('1.0.8')
164
+ mock_spec.expects(:version).returns(mock_version)
165
+
166
+ DpkgTools::Package::Gem::Setup.cache_key_from_spec(mock_spec).should == 'gem_name-1.0.8'
167
+ end
168
+ end
169
+
170
+ describe DpkgTools::Package::Gem::Setup, ".new" do
171
+ it "should raise an error without any arguments" do
172
+ lambda { DpkgTools::Package::Gem::Setup.new }.should raise_error
173
+ end
174
+
175
+ it "should require one arguments" do
176
+ data = stub("DpkgTools::Package::Gem::Data", :name => 'gem_name', :version => '1.0.8')
177
+ DpkgTools::Package::Gem::Setup.new(data)
178
+ end
179
+ end
180
+
181
+ describe DpkgTools::Package::Gem::Setup, "instances" do
182
+ before(:each) do
183
+ @config = DpkgTools::Package::Config.new('gem_name', '1.0.8', :suffix => 'rubygem')
184
+ DpkgTools::Package::Config.expects(:new).with('gem_name', '1.0.8', :suffix => 'rubygem').returns(@config)
185
+ @data = stub("stub DpkgTools::Package::Gem::Data", :name => 'gem_name', :version => '1.0.8',
186
+ :full_name => 'gem_name-1.0.8', :gem_byte_string => 'gem byte string')
187
+
188
+ @setup = DpkgTools::Package::Gem::Setup.new(@data)
189
+ end
190
+
191
+ it "should provide access to its Package::Gem::Data" do
192
+ @setup.data.should == @data
193
+ end
194
+
195
+ it "should provide access to its Package::Config" do
196
+ @setup.config.should == @config
197
+ end
198
+
199
+ it "should provide the correct options needed to make a DpkgTools::Package::Config" do
200
+ @setup.config_options.should == {:suffix => 'rubygem'}
201
+ end
202
+
203
+ it "should be able to write a .orig.tar.gz file with the gem in" do
204
+ DpkgTools::Package::Gem::Setup.expects(:write_orig_tarball).with(@config, 'gem byte string')
205
+
206
+ @setup.write_orig_tarball
207
+ end
208
+
209
+ it "should be able to write the .gem file" do
210
+ DpkgTools::Package::Gem::Setup.expects(:write_gem_file).with(@config, 'gem byte string')
211
+
212
+ @setup.write_gem_file
213
+ end
214
+
215
+ it "should be able to return the correct list of classes to build control files with" do
216
+ @setup.control_file_classes.should == DpkgTools::Package::Gem::ControlFiles.classes
217
+ end
218
+
219
+ it "should be able to perform all the gem-specific steps needed to create the package structure" do
220
+ @setup.expects(:write_orig_tarball)
221
+ @setup.expects(:write_gem_file)
222
+
223
+ @setup.prepare_package
224
+ end
225
+
226
+ it "should be able to create a setup instance for a dependency which has already had its dependencies fetched" do
227
+ mock_dep_setup = mock('mock DpkgTools::Package::Gem::Setup')
228
+ mock_dep_setup.expects(:fetched_dependencies?).returns(true)
229
+ DpkgTools::Package::Gem::Setup.expects(:from_name_and_requirement).
230
+ with('gem_name', :requirement).returns(mock_dep_setup)
231
+ mock_dependency = mock('mock Gem::Dependency')
232
+ mock_dependency.expects(:name).returns('gem_name')
233
+ mock_dependency.expects(:version_requirements).returns(:requirement)
234
+
235
+ @setup.fetch_dependency(mock_dependency).should == mock_dep_setup
236
+ end
237
+
238
+ it "should be able to create a setup instance (and its dependencies) for a dependency" do
239
+ mock_dep_setup = mock('mock DpkgTools::Package::Gem::Setup')
240
+ mock_dep_setup.expects(:fetched_dependencies?).returns(false)
241
+ mock_dep_setup.expects(:fetch_dependencies).returns([:child_dep])
242
+ DpkgTools::Package::Gem::Setup.expects(:from_name_and_requirement).
243
+ with('gem_name', :requirement).returns(mock_dep_setup)
244
+ mock_dependency = mock('mock Gem::Dependency')
245
+ mock_dependency.expects(:name).returns('gem_name')
246
+ mock_dependency.expects(:version_requirements).returns(:requirement)
247
+
248
+ @setup.fetch_dependency(mock_dependency).should == [mock_dep_setup, :child_dep]
249
+ end
250
+
251
+ it "should be able to create setup instances for any dependencies" do
252
+ stub_spec = stub('Gem::Specification', :dependencies => [:dep1, :dep2])
253
+ @data.expects(:spec).returns(stub_spec)
254
+ @setup.expects(:fetch_dependency).with(:dep1).returns(:dep1_setup)
255
+ @setup.expects(:fetch_dependency).with(:dep2).returns(:dep2_setup)
256
+ @setup.fetch_dependencies.should == [:dep1_setup, :dep2_setup]
257
+ end
258
+
259
+ it "should provide access to the class dependency_cache" do
260
+ DpkgTools::Package::Gem::Setup.expects(:dependency_cache).returns(:dependency_cache)
261
+ @setup.dependency_cache.should == :dependency_cache
262
+ end
263
+
264
+ it "should be able to record the fact that it has fetched its dependencies" do
265
+ stub_spec = stub('Gem::Specification', :dependencies => [])
266
+ @data.expects(:spec).returns(stub_spec)
267
+ @setup.fetch_dependencies
268
+ @setup.fetched_dependencies?.should be_true
269
+ end
270
+
271
+ it "should be able to record the fact that it has NOT fetched its dependencies" do
272
+ @setup.fetched_dependencies?.should be_false
273
+ end
274
+ end