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,28 @@
1
+ require File.dirname(__FILE__) + '/../../../spec_helper'
2
+
3
+ describe DpkgTools::Package::Etc::Builder, "instances" do
4
+ before(:each) do
5
+ @config = DpkgTools::Package::Config.new('rails-app', '1.0.8')
6
+ DpkgTools::Package::Etc::Data.expects(:load_package_data).with('/a/path/to/conf-package', 'deb.yml').
7
+ returns({'name' => 'conf-package', 'version' => '1.0.8'})
8
+ @data = DpkgTools::Package::Etc::Data.new('/a/path/to/conf-package')
9
+
10
+ @builder = DpkgTools::Package::Etc::Builder.new(@data)
11
+ end
12
+
13
+ it "should provide the correct options for DpkgTools::Package::Config " do
14
+ @builder.config_options.should == {:base_path => "/a/path/to/conf-package"}
15
+ end
16
+
17
+ it "should be able to create the needed install dirs" do
18
+ @builder.expects(:create_dir_if_needed).with('/a/path/to/conf-package/debian/tmp/etc')
19
+
20
+ @builder.create_install_dirs
21
+ end
22
+
23
+ it "should copy the contents of package/etc to package/debian/tmp/etc/" do
24
+ FileUtils.expects(:cp_r).with('/a/path/to/conf-package/etc', '/a/path/to/conf-package/debian/tmp/etc')
25
+
26
+ @builder.install_package_files
27
+ end
28
+ end
@@ -0,0 +1,21 @@
1
+ require File.dirname(__FILE__) + '/../../../../spec_helper'
2
+
3
+ describe DpkgTools::Package::Etc::ControlFiles::Changelog, "#changelog" do
4
+ before(:each) do
5
+ @config = DpkgTools::Package::Config.new('rails-app', '1.0.8')
6
+ @stub_data = stub('DpkgTools::Package::Etc::Data', :full_name => 'rails-app-1.0.8', :debian_revision => '1')
7
+ @metadata = DpkgTools::Package::Etc::ControlFiles::Changelog.new(@stub_data, @config)
8
+ end
9
+
10
+ it "should be able to generate a changelog" do
11
+ changelog_fixture = {'date' => "2008-04-16T12:00:00+00:00",
12
+ 'version' => "1.0.1",
13
+ 'changes' => ['Change details']}
14
+ @config.stubs(:base_path).returns('base_path')
15
+ YAML.stubs(:load_file).with('base_path/changelog.yml').returns([changelog_fixture])
16
+
17
+ @metadata.changelog.should == "rails-app (1.0.1-1) cp-gutsy; urgency=low\n"\
18
+ " * Change details\n"\
19
+ " -- Matt Patterson <matt@reprocessed.org> Wed, 16 Apr 2008 12:00:00 -0000\n"
20
+ end
21
+ end
@@ -0,0 +1,16 @@
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::Etc::ControlFiles::Rakefile.new(stub_data, config)
8
+
9
+ metadata.rakefile.should == "require 'rubygems'\n" \
10
+ "require 'dpkg-tools'\n" \
11
+ "\n" \
12
+ "DpkgTools::Package::Etc::BuildTasks.new do |t|\n" \
13
+ " t.base_path = Rake.original_dir\n" \
14
+ "end\n"
15
+ end
16
+ end
@@ -0,0 +1,12 @@
1
+ require File.dirname(__FILE__) + '/../../../spec_helper'
2
+
3
+ describe DpkgTools::Package::Etc::ControlFiles do
4
+ it "should provide access to the list of control file classes" do
5
+ DpkgTools::Package::Etc::ControlFiles.classes.
6
+ should == [DpkgTools::Package::Etc::ControlFiles::Changelog,
7
+ DpkgTools::Package::ControlFiles::Control,
8
+ DpkgTools::Package::ControlFiles::Copyright,
9
+ DpkgTools::Package::Etc::ControlFiles::Rakefile,
10
+ DpkgTools::Package::ControlFiles::Rules]
11
+ end
12
+ end
@@ -0,0 +1,74 @@
1
+ require File.dirname(__FILE__) + '/../../../spec_helper'
2
+
3
+ describe DpkgTools::Package::Etc::Data do
4
+ it "should provide access to the name of the resources subdir in the gem" do
5
+ DpkgTools::Package::Etc::Data.resources_dirname.should == 'etc'
6
+ end
7
+
8
+ it "should return no dependencies by default" do
9
+ DpkgTools::Package::Etc::Data.base_package_deps.should == []
10
+ end
11
+
12
+ it "should return no gem dependencies by default" do
13
+ DpkgTools::Package::Etc::Data.base_gem_deps.should == []
14
+ end
15
+
16
+ describe DpkgTools::Package::Rails::Data, ".new" do
17
+ it "should raise an error without any arguments" do
18
+ lambda { DpkgTools::Package::Gem::Data.new }.should raise_error
19
+ end
20
+
21
+ it "should take the conf package's base path, then read in the deb.yml" do
22
+ DpkgTools::Package::Etc::Data.expects(:load_package_data).with('base_path', 'deb.yml').returns({'name' => 'rails-app', 'version' => '1.0.8'})
23
+ DpkgTools::Package::Etc::Data.expects(:process_dependencies).with({'name' => 'rails-app', 'version' => '1.0.8'}).returns(:deps)
24
+ DpkgTools::Package::Etc::Data.new('base_path').should be_an_instance_of(DpkgTools::Package::Etc::Data)
25
+ end
26
+ end
27
+
28
+ describe "instances" do
29
+ before(:each) do
30
+ package_data = {'name' => 'conf-package', 'version' => '1.0.8', 'license' => '(c) Matt 4evah',
31
+ 'summary' => "Matt's great configuration package"}
32
+ DpkgTools::Package::Etc::Data.stubs(:load_package_data).with('base_path', 'deb.yml').
33
+ returns(package_data)
34
+ DpkgTools::Package::Etc::Data.expects(:process_dependencies).with(package_data).returns(:deps)
35
+ @data = DpkgTools::Package::Etc::Data.new('base_path')
36
+ end
37
+
38
+ it "should profess to be an architecture-independent package" do
39
+ @data.architecture_independent?.should be_true
40
+ end
41
+
42
+ it "should provide access to its install-time deps" do
43
+ @data.dependencies.should == :deps
44
+ end
45
+
46
+ it "should provide access to its build-time deps" do
47
+ @data.build_dependencies.should == :deps
48
+ end
49
+
50
+ it "should provide access to its name" do
51
+ @data.name.should == 'conf-package'
52
+ end
53
+
54
+ it "should convert the Gem::Version object to a string" do
55
+ @data.version.should == '1.0.8'
56
+ end
57
+
58
+ it "should provide access to the changelog-derived debian_revision" do
59
+ @data.debian_revision.should == "1"
60
+ end
61
+
62
+ it "should provide access to the debian architecture name" do
63
+ @data.debian_arch.should == "all"
64
+ end
65
+
66
+ it "should provide access to its license" do
67
+ @data.license.should == "(c) Matt 4evah"
68
+ end
69
+
70
+ it "should provide access to its summary" do
71
+ @data.summary.should == "Matt's great configuration package"
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,71 @@
1
+ require File.dirname(__FILE__) + '/../../../spec_helper'
2
+
3
+ require 'rake'
4
+
5
+ describe DpkgTools::Package::Etc::BuildTasks, "task creation" do
6
+ it "check_setup should be fine if base_path is defined" do
7
+ DpkgTools::Package::Etc::BuildTasks.any_instance.stubs(:define_tasks)
8
+ DpkgTools::Package::Etc::BuildTasks.any_instance.stubs(:define_base_tasks)
9
+
10
+ result = DpkgTools::Package::Etc::BuildTasks.new do |t|
11
+ t.base_path = 'path'
12
+ end
13
+ result.base_path.should == 'path'
14
+ end
15
+
16
+ it "should raise an error if base_path hasn't been defined" do
17
+ DpkgTools::Package::Etc::BuildTasks.any_instance.stubs(:define_tasks)
18
+ DpkgTools::Package::Etc::BuildTasks.any_instance.stubs(:define_base_tasks)
19
+
20
+ lambda { DpkgTools::Package::Etc::BuildTasks.new }.should raise_error(ArgumentError)
21
+ end
22
+
23
+ it "should be able to return a properly instantiated Builder from create_builder" do
24
+ build_tasks = DpkgTools::Package::Etc::BuildTasks.new do |t|
25
+ t.base_path = 'path'
26
+ end
27
+
28
+ DpkgTools::Package::Etc.expects(:create_builder).with('path').returns(:builder)
29
+
30
+ build_tasks.create_builder.should == :builder
31
+ end
32
+
33
+ it "should be able to return a properly instantiated Setup from create_setup" do
34
+ build_tasks = DpkgTools::Package::Etc::BuildTasks.new do |t|
35
+ t.base_path = 'path'
36
+ end
37
+
38
+ DpkgTools::Package::Etc.expects(:create_setup).with('path').returns(:setup)
39
+
40
+ build_tasks.create_setup.should == :setup
41
+ end
42
+ end
43
+
44
+ describe DpkgTools::Package::Etc::BuildTasks, "rake tasks" do
45
+ before(:each) do
46
+ @rake = Rake::Application.new
47
+ Rake.application = @rake
48
+
49
+ @build_tasks = DpkgTools::Package::Etc::BuildTasks.new do |t|
50
+ t.base_path = "base_path"
51
+ end
52
+ end
53
+
54
+ after(:each) do
55
+ Rake.application = nil
56
+ end
57
+
58
+ it "should properly call the DpkgTools::Package::Etc.create_builder from the task 'binary-arch'" do
59
+ mock_builder = mock('DpkgTools::Package::Etc::Builder')
60
+ mock_builder.expects(:binary_package)
61
+ @build_tasks.expects(:create_builder).returns(mock_builder)
62
+ @rake["binary-arch"].invoke
63
+ end
64
+
65
+ it "should properly call the DpkgTools::Package::Etc.create_builder from the task 'binary-indep'" do
66
+ mock_builder = mock('DpkgTools::Package::Etc::Builder')
67
+ mock_builder.expects(:binary_package)
68
+ @build_tasks.expects(:create_builder).returns(mock_builder)
69
+ @rake["binary-indep"].invoke
70
+ end
71
+ end
@@ -0,0 +1,62 @@
1
+ require File.dirname(__FILE__) + '/../../../spec_helper'
2
+
3
+ describe DpkgTools::Package::Etc::Setup do
4
+ describe "bootstrapping support" do
5
+ it "should return base_path/deb.yml when asked to return bootstrap_file_path" do
6
+ DpkgTools::Package::Etc::Setup.bootstrap_file_path('base_path', 'deb.yml').should == 'base_path/deb.yml'
7
+ end
8
+ end
9
+
10
+ it "should report deb.yml as its required bootstrap file" do
11
+ DpkgTools::Package::Etc::Setup.bootstrap_files.should == ['deb.yml', 'changelog.yml']
12
+ end
13
+
14
+ it "should report DpkgTools::Package::Etc::Data for data_class" do
15
+ DpkgTools::Package::Etc::Setup.data_class.should == DpkgTools::Package::Etc::Data
16
+ end
17
+
18
+ describe ".from_path" do
19
+ it "should create a DpkgTools::Package::Etc::Data instance, and feed it to .new" do
20
+ DpkgTools::Package::Etc::Setup.expects(:needs_bootstrapping?).with('base_path').returns(false)
21
+ DpkgTools::Package::Etc::Data.expects(:new).with('base_path').returns(:data)
22
+ DpkgTools::Package::Etc::Setup.expects(:new).with(:data, 'base_path').returns(:instance)
23
+
24
+ DpkgTools::Package::Etc::Setup.from_path('base_path').should == :instance
25
+ end
26
+ end
27
+
28
+ describe DpkgTools::Package::Etc::Setup, "instances" do
29
+ before(:each) do
30
+ @data = stub("stub DpkgTools::Package::Etc::Data", :name => 'hello', :version => '1', :base_path => 'base_path')
31
+ @config = DpkgTools::Package::Config.new('hello', '1', {:base_path => 'base_path'})
32
+ DpkgTools::Package::Config.expects(:new).with('hello', '1', {:base_path => 'base_path'}).returns(@config)
33
+
34
+ @setup = DpkgTools::Package::Etc::Setup.new(@data)
35
+ end
36
+
37
+ it "should provide access to the correct options for making a new DpkgTools::Package::Config" do
38
+ @setup.config_options.should == {:base_path => 'base_path'}
39
+ end
40
+
41
+ it "should return the right thing for #control_file_classes" do
42
+ DpkgTools::Package::Etc::ControlFiles.expects(:classes).returns(:classes)
43
+ @setup.control_file_classes.should == :classes
44
+ end
45
+
46
+ describe "#prepare_package" do
47
+ it "should create an etc/ dir if it isn't already there" do
48
+ File.stubs(:directory?).with('base_path/etc').returns(false)
49
+ Dir.expects(:mkdir).with('base_path/etc')
50
+
51
+ @setup.prepare_package
52
+ end
53
+
54
+ it "should not create the etc/ dir if it is there" do
55
+ File.stubs(:directory?).with('base_path/etc').returns(true)
56
+ Dir.expects(:mkdir).with('base_path/etc').never
57
+
58
+ @setup.prepare_package
59
+ end
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,39 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
+
3
+ describe DpkgTools::Package::Etc, ".create_builder" do
4
+ it "should instantiate a Package::Etc::Data and a Package::Etc::Builder and make 'em work" do
5
+ DpkgTools::Package::Etc::Builder.expects(:from_path).with('/path/to/package').returns(:builder)
6
+
7
+ DpkgTools::Package::Etc.create_builder('/path/to/package').should == :builder
8
+ end
9
+ end
10
+
11
+ describe DpkgTools::Package::Etc, ".setup_from_path" do
12
+ it "should be able to create package structure from a path to a not-yet-extant conf package dir" do
13
+ mock_setup = mock('mock DpkgTools::Package::Etc::Setup')
14
+ File.stubs(:directory?).with('/path/to/package').returns(false)
15
+ Dir.expects(:mkdir).with('/path/to/package')
16
+ DpkgTools::Package::Etc::Setup.expects(:from_path).with('/path/to/package').returns(mock_setup)
17
+ mock_setup.expects(:create_structure)
18
+
19
+ DpkgTools::Package::Etc.setup_from_path('/path/to/package')
20
+ end
21
+
22
+ it "should be able to create package structure from a path to a dir that exists" do
23
+ mock_setup = mock('mock DpkgTools::Package::Etc::Setup')
24
+ File.stubs(:directory?).with('/path/to/package').returns(true)
25
+ Dir.expects(:mkdir).with('/path/to/package').never
26
+ DpkgTools::Package::Etc::Setup.expects(:from_path).with('/path/to/package').returns(mock_setup)
27
+ mock_setup.expects(:create_structure)
28
+
29
+ DpkgTools::Package::Etc.setup_from_path('/path/to/package')
30
+ end
31
+ end
32
+
33
+ describe DpkgTools::Package::Etc, ".create_setup" do
34
+ it "should be able to create a Setup instance" do
35
+ DpkgTools::Package::Etc::Setup.expects(:from_path).with('/path/to/package').returns(:setup)
36
+
37
+ DpkgTools::Package::Etc.create_setup('/path/to/package').should == :setup
38
+ end
39
+ end
@@ -0,0 +1,33 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
+
3
+ module FSMethodsContainer
4
+ class << self
5
+ include DpkgTools::Package::FSMethods
6
+ end
7
+ end
8
+
9
+ describe DpkgTools::Package::FSMethods, "filesystem-related convenience methods" do
10
+ it "should be able to make a directory that isn't there" do
11
+ File.expects(:exists?).with('path').returns(false)
12
+ FileUtils.expects(:mkdir_p).with('path')
13
+
14
+ FSMethodsContainer.create_dir_if_needed('path')
15
+ end
16
+
17
+ it "should be able to conditionally make a directory" do
18
+ File.expects(:exists?).with('path').returns(true)
19
+ File.expects(:file?).with('path').returns(false)
20
+ FileUtils.expects(:mkdir_p).never
21
+
22
+ FSMethodsContainer.create_dir_if_needed('path')
23
+ end
24
+
25
+ it "should error if directory it was asked to make is an existing file" do
26
+ File.expects(:exists?).with('path').returns(true)
27
+ File.expects(:file?).with('path').returns(true)
28
+ FileUtils.expects(:mkdir_p).never
29
+
30
+ lambda { FSMethodsContainer.create_dir_if_needed('path') }.should raise_error
31
+ end
32
+
33
+ end
@@ -0,0 +1,84 @@
1
+ require File.dirname(__FILE__) + '/../../../spec_helper'
2
+
3
+ describe DpkgTools::Package::Gem::Builder do
4
+ it "should be able to grab the bytes of a gem file and extract a Gem::Format" do
5
+ mock_file = mock('mock File')
6
+ mock_file.expects(:read).returns('gem byte string')
7
+ File.expects(:open).with('path/to/file.gem', 'rb').returns(mock_file)
8
+ DpkgTools::Package::Gem::Builder.expects(:format_from_string).with('gem byte string')
9
+ DpkgTools::Package::Gem::Builder.format_and_file_from_file_path('path/to/file.gem')
10
+ end
11
+
12
+ it "should be able to snarf the gem file, create a DpkgTools::Package::Gem::Data and a Builder instance" do
13
+ data = stub('DpkgTools::Package::Gem::Data', :name => 'name', :version => 'version')
14
+ DpkgTools::Package::Gem::Data.expects(:new).with(:format, 'gem byte string').returns(data)
15
+ DpkgTools::Package::Gem::Builder.expects(:new).with(data).returns(:instance)
16
+ DpkgTools::Package::Gem::Builder.expects(:format_and_file_from_file_path).with('gem_path').returns([:format, 'gem byte string'])
17
+
18
+ DpkgTools::Package::Gem::Builder.from_file_path('gem_path').should == :instance
19
+ end
20
+ end
21
+
22
+ describe DpkgTools::Package::Gem::Builder, "instances" do
23
+ before(:each) do
24
+ DpkgTools::Package::Config.stubs(:root_path).returns("a/path/to")
25
+ @stub_data = stub("stub DpkgTools::Package::Gem::Data", :name => 'stub_gem', :version => '1.0.8',
26
+ :full_name => 'gem_name-1.0.8', :debian_revision => '1',
27
+ :debian_arch => 'all', :gem_byte_string => 'gem byte string')
28
+
29
+ @builder = DpkgTools::Package::Gem::Builder.new(@stub_data)
30
+ end
31
+
32
+ it "should provide the right options for DpkgTools::Package::Config" do
33
+ @builder.config_options.should == {:suffix => 'rubygem'}
34
+ end
35
+
36
+ it "should provide access to @gem_byte_string" do
37
+ @builder.gem_byte_string.should == 'gem byte string'
38
+ end
39
+
40
+ it "should be able to create the needed install dirs" do
41
+ @builder.expects(:create_dir_if_needed).with('a/path/to/stub-gem-rubygem-1.0.8/debian/tmp/usr/lib/ruby/gems/1.8')
42
+ @builder.expects(:create_dir_if_needed).with('a/path/to/stub-gem-rubygem-1.0.8/debian/tmp/usr/bin')
43
+
44
+ @builder.create_install_dirs
45
+ end
46
+
47
+ it "should override Gem.bindir to provide a sensible alternative" do
48
+ @builder.override_gem_bindir
49
+
50
+ ::Gem.bindir.should == "a/path/to/stub-gem-rubygem-1.0.8/debian/tmp/usr/bin"
51
+ end
52
+
53
+ it "should be able to install the gem into the buildroot" do
54
+ @builder.expects(:override_gem_bindir)
55
+ mock_installer = mock('mock Gem::Installer')
56
+ mock_installer.expects(:install).with(false, 'a/path/to/stub-gem-rubygem-1.0.8/debian/tmp/usr/lib/ruby/gems/1.8')
57
+ Gem::Installer.expects(:new).with('a/path/to/stub-gem-rubygem-1.0.8/stub_gem-1.0.8.gem', {:wrappers => true, :env_shebang => true}).
58
+ returns(mock_installer)
59
+
60
+ @builder.install_gem
61
+ end
62
+
63
+ it "should be able to install the RI and RDoc for the gem" do
64
+ mock_doc_manager = mock('mock Gem::DocManager')
65
+ mock_doc_manager.expects(:generate_ri)
66
+ mock_doc_manager.expects(:generate_rdoc)
67
+ Gem::DocManager.expects(:new).with(:installed_gem_spec).returns(mock_doc_manager)
68
+
69
+ @builder.install_docs(:installed_gem_spec)
70
+ end
71
+
72
+ it "should be able to perform the steps needed to install all the package's files" do
73
+ @builder.expects(:install_gem).returns(:installed_gem_spec)
74
+ @builder.expects(:install_docs).with(:installed_gem_spec)
75
+
76
+ @builder.build_package_files
77
+ end
78
+
79
+ it "should be able to perform the steps needed to finish the install all the package's files" do
80
+ @builder.expects(:sh).with('chown -R root:root "a/path/to/stub-gem-rubygem-1.0.8/debian/tmp"')
81
+
82
+ @builder.install_package_files
83
+ end
84
+ end