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,78 @@
1
+ require File.dirname(__FILE__) + '/../../../spec_helper'
2
+
3
+ require 'rake'
4
+
5
+ describe DpkgTools::Package::Rails::BuildTasks, "task creation" do
6
+ it "check_setup should be fine if base_path is defined" do
7
+ DpkgTools::Package::Rails::BuildTasks.any_instance.stubs(:define_tasks)
8
+ DpkgTools::Package::Rails::BuildTasks.any_instance.stubs(:define_base_tasks)
9
+
10
+ result = DpkgTools::Package::Rails::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::Rails::BuildTasks.any_instance.stubs(:define_tasks)
18
+ DpkgTools::Package::Rails::BuildTasks.any_instance.stubs(:define_base_tasks)
19
+
20
+ lambda { DpkgTools::Package::Rails::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::Rails::BuildTasks.new do |t|
25
+ t.base_path = 'path'
26
+ end
27
+
28
+ DpkgTools::Package::Rails.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::Rails::BuildTasks.new do |t|
35
+ t.base_path = 'path'
36
+ end
37
+
38
+ DpkgTools::Package::Rails.expects(:create_setup).with('path').returns(:setup)
39
+
40
+ build_tasks.create_setup.should == :setup
41
+ end
42
+ end
43
+
44
+ describe DpkgTools::Package::Rails::BuildTasks, "rake tasks" do
45
+ before(:each) do
46
+ @rake = Rake::Application.new
47
+ Rake.application = @rake
48
+
49
+ @build_tasks = DpkgTools::Package::Rails::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::Rails.create_builder from the task 'binary-arch'" do
59
+ mock_builder = mock('DpkgTools::Package::Rails::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::Rails.create_builder from the task 'binary-indep'" do
66
+ mock_builder = mock('DpkgTools::Package::Rails::Builder')
67
+ mock_builder.expects(:binary_package)
68
+ @build_tasks.expects(:create_builder).returns(mock_builder)
69
+ @rake["binary-indep"].invoke
70
+ end
71
+
72
+ it "should be able to correctly generate the mongrel_cluster YAML config file" do
73
+ mock_setup = mock('DpkgTools::Package::Rails::Setup')
74
+ mock_setup.expects(:generate_mongrel_cluster_config)
75
+ @build_tasks.expects(:create_setup).returns(mock_setup)
76
+ @rake["dpkg:mongrel_cluster"].invoke
77
+ end
78
+ end
@@ -0,0 +1,152 @@
1
+ require File.dirname(__FILE__) + '/../../../spec_helper'
2
+
3
+ describe DpkgTools::Package::Rails::Setup, ".from_path" do
4
+ it "should return the correct class from .data_class" do
5
+ DpkgTools::Package::Rails::Setup.data_class.should == DpkgTools::Package::Rails::Data
6
+ end
7
+
8
+ it "should create a DpkgTools::Package::Rails::Data instance, and feed it to .new" do
9
+ DpkgTools::Package::Rails::Setup.stubs(:needs_bootstrapping?).returns(false)
10
+ DpkgTools::Package::Rails::Data.expects(:new).with('base_path').returns(:data)
11
+ DpkgTools::Package::Rails::Setup.expects(:new).with(:data, 'base_path').returns(:instance)
12
+
13
+ DpkgTools::Package::Rails::Setup.from_path('base_path').should == :instance
14
+ end
15
+ end
16
+
17
+ describe DpkgTools::Package::Rails::Setup, "bootstrapping" do
18
+ before(:each) do
19
+ DpkgTools::Package::Rails::Data.stubs(:resources_path).returns('/a/path/to/resources')
20
+ end
21
+
22
+ it "should be able to construct the target file path of a file for bootstrapping" do
23
+ DpkgTools::Package::Rails::Setup.bootstrap_file_path('base_path', 'deb.yml').
24
+ should == 'base_path/config/deb.yml'
25
+ end
26
+
27
+ it "should be able to report which files are needed for bootstrapping" do
28
+ DpkgTools::Package::Rails::Setup.bootstrap_files.should == ['deb.yml']
29
+ end
30
+ end
31
+
32
+ describe DpkgTools::Package::Rails::Setup, ".new" do
33
+ before(:each) do
34
+ @data = stub('stub DpkgTools::Package::Rails::Data', :name => 'name', :version => '1', :base_path => 'base_path')
35
+ end
36
+
37
+ it "should raise an error without any arguments" do
38
+ lambda { DpkgTools::Package::Rails::Setup.new }.should raise_error
39
+ end
40
+
41
+ it "should require one argument" do
42
+ DpkgTools::Package::Rails::Setup.new(@data)
43
+ end
44
+
45
+ it "should result in @config being set to a DpkgTools::Package::Config instance" do
46
+ setup = DpkgTools::Package::Rails::Setup.new(@data)
47
+ setup.config.should be_an_instance_of(DpkgTools::Package::Config)
48
+ end
49
+ end
50
+
51
+ describe DpkgTools::Package::Rails::Setup do
52
+ before(:each) do
53
+ @data = stub('stub DpkgTools::Package::Rails::Data', :name => 'name', :version => '1', :base_path => 'base_path',
54
+ :resources_path => '/a/path/to/resources',
55
+ :app_install_path => '/var/lib/name',
56
+ :pidfile_dir_path => '/var/run/name',
57
+ :mongrel_cluster_config_hash => {'port' => "8000",
58
+ 'environment' => 'production',
59
+ 'address' => '127.0.0.1',
60
+ 'servers' => 3})
61
+ @data.stubs(:deployers_ssh_keys_dir).returns('deployers_ssh_keys')
62
+ @config = DpkgTools::Package::Config.new('name', '1', :base_path => 'base_path')
63
+ end
64
+
65
+ it "should be able to provide a list of the resource files to be copied across during setup" do
66
+ DpkgTools::Package::Rails::Setup.resource_file_names.
67
+ should == ['apache.conf.erb', 'logrotate.conf.erb', 'mongrel_cluster_init.erb', 'deploy.rb']
68
+ end
69
+
70
+ it ".prepare_package should copy the conf templates and extra structures across" do
71
+ DpkgTools::Package::Rails::Setup.stubs(:resource_file_names).returns(['apache.conf.erb'])
72
+ DpkgTools::Package::Rails::Data.stubs(:resources_path).returns('/a/path/to/resources')
73
+ data = stub('stub DpkgTools::Package::Rails::Data', :name => 'name', :version => '1', :base_path => 'base_path',
74
+ :resources_path => '/a/path/to/resources')
75
+ data.stubs(:deployers_ssh_keys_dir).returns('deployers_ssh_keys')
76
+ config = DpkgTools::Package::Config.new('name', '1', :base_path => 'base_path')
77
+ DpkgTools::Package::Rails::Setup.expects(:bootstrap_file).with('base_path', 'apache.conf.erb')
78
+
79
+ DpkgTools::Package::Rails::Setup.expects(:create_dir_if_needed).with('deployers_ssh_keys')
80
+
81
+ DpkgTools::Package::Rails::Setup.expects(:sh).with('capify "base_path"')
82
+ DpkgTools::Package::Rails::Setup.expects(:generate_mongrel_cluster_config).with(@data, @config)
83
+
84
+ DpkgTools::Package::Rails::Setup.prepare_package(@data, @config)
85
+ end
86
+
87
+ it "should be able to back up and reset the resource files created by .prepare_package" do
88
+ DpkgTools::Package::Rails::Setup.stubs(:resource_file_names).returns(['apache.conf.erb'])
89
+ DpkgTools::Package::Rails::Setup.expects(:bootstrap_file).with('base_path', 'apache.conf.erb', :backup => true)
90
+
91
+ DpkgTools::Package::Rails::Setup.reset_package_resource_files(@data, @config)
92
+ end
93
+
94
+ it "should be able to generate the complete config/mongrel_cluster.yml hash" do
95
+ DpkgTools::Package::Rails::Setup.generate_mongrel_cluster_config_hash(@data, @config).
96
+ should == {'port' => "8000",
97
+ 'environment' => 'production',
98
+ 'address' => '127.0.0.1',
99
+ 'servers' => 3,
100
+ 'pid_file' => '/var/run/name/mongrel.pid',
101
+ 'cwd' => '/var/lib/name/current',
102
+ 'log_file' => 'log/mongrel.log',
103
+ 'user' => 'name',
104
+ 'group' => 'name'}
105
+ end
106
+
107
+ it "should be able to write the config/mongrel_cluster.yml file" do
108
+ conf_data = {'port' => '8000'}
109
+ conf_data.expects(:to_yaml).returns("---\nport: blah")
110
+ DpkgTools::Package::Rails::Setup.expects(:generate_mongrel_cluster_config_hash).with(@data, @config).returns(conf_data)
111
+ mock_file = mock('File')
112
+ mock_file.expects(:write).with("# Auto-generated by dpkg-tools, don't edit!\n# You can edit config/deb.yml and then regenerate this file\n# with rake dpkg:mongrel_cluster.\n\nport: blah")
113
+ File.expects(:open).with('base_path/config/mongrel_cluster.yml', 'w').yields(mock_file)
114
+
115
+ DpkgTools::Package::Rails::Setup.generate_mongrel_cluster_config(@data, @config)
116
+ end
117
+ end
118
+
119
+ describe DpkgTools::Package::Rails::Setup, "instances" do
120
+ before(:each) do
121
+ @data = stub("stub DpkgTools::Package::Rails::Data", :name => 'rails-app-name', :version => '1.0.8',
122
+ :full_name => 'rails-app-name-1.0.8', :base_path => 'base_path')
123
+ @setup = DpkgTools::Package::Rails::Setup.new(@data)
124
+ end
125
+
126
+ it "should provide access to the correct options for making a new DpkgTools::Package::Config" do
127
+ @setup.config_options.should == {:base_path => 'base_path'}
128
+ end
129
+
130
+ it "should provide access to its Package::Rails::Data" do
131
+ @setup.data.should == @data
132
+ end
133
+
134
+ it "should be able to return the correct list of classes to build control files with" do
135
+ @setup.control_file_classes.should == DpkgTools::Package::Rails::ControlFiles.classes
136
+ end
137
+
138
+ it "should properly invoke .prepare_package from #prepare_package" do
139
+ DpkgTools::Package::Rails::Setup.expects(:prepare_package).with(@setup.data, @setup.config)
140
+ @setup.prepare_package
141
+ end
142
+
143
+ it "should properly invoke .prepare_package from #prepare_package" do
144
+ DpkgTools::Package::Rails::Setup.expects(:generate_mongrel_cluster_config).with(@setup.data, @setup.config)
145
+ @setup.generate_mongrel_cluster_config
146
+ end
147
+
148
+ it "should properly invoke .reset_package_resource_files from #reset_package_resource_files" do
149
+ DpkgTools::Package::Rails::Setup.expects(:reset_package_resource_files).with(@setup.data, @setup.config)
150
+ @setup.reset_package_resource_files
151
+ end
152
+ end
@@ -0,0 +1,27 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
+
3
+ describe DpkgTools::Package::Rails, ".create_builder" do
4
+ it "should instantiate a Package::Rails::Data and a Package::Rails::Builder and make 'em work" do
5
+ DpkgTools::Package::Rails::Builder.expects(:from_path).with('/a/path/to/rails-app').returns(:builder)
6
+
7
+ DpkgTools::Package::Rails.create_builder('/a/path/to/rails-app').should == :builder
8
+ end
9
+ end
10
+
11
+ describe DpkgTools::Package::Rails, ".setup_from_path" do
12
+ it "should be able to create package structure from a path to a gem file" do
13
+ mock_setup = mock('mock DpkgTools::Package::Rails::Setup')
14
+ DpkgTools::Package::Rails::Setup.expects(:from_path).with('/path/to/rails-app').returns(mock_setup)
15
+ mock_setup.expects(:create_structure)
16
+
17
+ DpkgTools::Package::Rails.setup_from_path('/path/to/rails-app')
18
+ end
19
+ end
20
+
21
+ describe DpkgTools::Package::Rails, ".create_setup" do
22
+ it "should be able to create a Setup instance" do
23
+ DpkgTools::Package::Rails::Setup.expects(:from_path).with('/path/to/rails-app').returns(:setup)
24
+
25
+ DpkgTools::Package::Rails.create_setup('/path/to/rails-app').should == :setup
26
+ end
27
+ end
@@ -0,0 +1,87 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
+
3
+ describe DpkgTools::Package::BuildTasks, "task creation" do
4
+ it "should yield itself if a block is given to .new" do
5
+ DpkgTools::Package::BuildTasks.any_instance.stubs(:define_tasks)
6
+
7
+ yielded_result = nil
8
+ result = DpkgTools::Package::BuildTasks.new do |t|
9
+ yielded_result = t
10
+ end
11
+ result.should === yielded_result
12
+ end
13
+
14
+ it "should call the necessary methods to set up the base and subclass Rake tasks on init" do
15
+ DpkgTools::Package::BuildTasks.any_instance.expects(:check_setup)
16
+ DpkgTools::Package::BuildTasks.any_instance.expects(:define_tasks)
17
+ DpkgTools::Package::BuildTasks.any_instance.expects(:define_base_tasks)
18
+
19
+ DpkgTools::Package::BuildTasks.new
20
+ end
21
+ end
22
+
23
+ describe DpkgTools::Package::BuildTasks, "instances" do
24
+ before(:each) do
25
+ @rake = Rake::Application.new
26
+ Rake.application = @rake
27
+
28
+ @build_tasks = DpkgTools::Package::BuildTasks.new
29
+ @mock_builder = stub('DpkgTools::Package::Builder')
30
+ @build_tasks.stubs(:create_builder).returns(@mock_builder)
31
+ @mock_setup = stub('DpkgTools::Package::Setup')
32
+ @build_tasks.stubs(:create_setup).returns(@mock_setup)
33
+ end
34
+
35
+ after(:each) do
36
+ Rake.application = nil
37
+ end
38
+
39
+ it "should define the needed base tasks for debian/rules emulation" do
40
+ @build_tasks.stubs(:task).with(anything)
41
+ @build_tasks.expects(:task).with(:clean)
42
+ @build_tasks.expects(:task).with('build-arch')
43
+ @build_tasks.expects(:task).with('build-indep')
44
+ @build_tasks.expects(:task).with(:build)
45
+ @build_tasks.expects(:task).with("binary-arch")
46
+ @build_tasks.expects(:task).with("binary-indep")
47
+ @build_tasks.expects(:task).with(:binary)
48
+
49
+ @build_tasks.define_base_tasks
50
+ end
51
+
52
+ it "should invoke binary-arch from :binary when the builder says it's an arch package" do
53
+ @mock_builder.expects(:architecture_independent?).returns(false)
54
+
55
+ @rake['binary-arch'].expects(:invoke)
56
+ @rake['binary'].invoke
57
+ end
58
+
59
+ it "should invoke binary-indep from :binary when the builder says it's an arch-indep package" do
60
+ @mock_builder.expects(:architecture_independent?).returns(true)
61
+
62
+ @rake['binary-indep'].expects(:invoke)
63
+ @rake['binary'].invoke
64
+ end
65
+
66
+ it "should invoke build-arch from :build when the builder says it's an arch package" do
67
+ @mock_builder.expects(:architecture_independent?).returns(false)
68
+
69
+ @rake['build-arch'].expects(:invoke)
70
+ @rake['build'].invoke
71
+ end
72
+
73
+ it "should invoke build-indep from :build when the builder says it's an arch-indep package" do
74
+ @mock_builder.expects(:architecture_independent?).returns(true)
75
+
76
+ @rake['build-indep'].expects(:invoke)
77
+ @rake['build'].invoke
78
+ end
79
+
80
+ it "should call the correct reset methods on a setup instance from dpkg:setup:reset" do
81
+ @mock_setup.expects(:reset_maintainer_script_templates)
82
+ @mock_setup.expects(:reset_control_files)
83
+ @mock_setup.expects(:reset_package_resource_files)
84
+
85
+ @rake['dpkg:setup:reset'].invoke
86
+ end
87
+ end
@@ -0,0 +1,247 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
+
3
+ describe DpkgTools::Package::Setup do
4
+ describe "bootstrapping" do
5
+ it "should report that it does NOT need bootstrapping if deb.yml is present" do
6
+ DpkgTools::Package::Setup.expects(:bootstrap_file_path).with('base_path', 'deb.yml').returns('base_path/deb.yml')
7
+ DpkgTools::Package::Setup.expects(:bootstrap_files).returns('deb.yml')
8
+ File.expects(:file?).with('base_path/deb.yml').returns(true)
9
+
10
+ DpkgTools::Package::Setup.needs_bootstrapping?('base_path').should be_false
11
+ end
12
+
13
+ it "should report that it does need bootstrapping if deb.yml is NOT present" do
14
+ DpkgTools::Package::Setup.expects(:bootstrap_file_path).with('base_path', 'deb.yml').returns('base_path/deb.yml')
15
+ DpkgTools::Package::Setup.expects(:bootstrap_files).returns('deb.yml')
16
+ File.expects(:file?).with('base_path/deb.yml').returns(false)
17
+
18
+ DpkgTools::Package::Setup.needs_bootstrapping?('base_path').should be_true
19
+ end
20
+
21
+ it "should respond to bootstrap" do
22
+ DpkgTools::Package::Setup.should respond_to(:bootstrap)
23
+ end
24
+
25
+ it "should provide a for-overriding bootstrap_files method" do
26
+ DpkgTools::Package::Setup.bootstrap_files.should == ['deb.yml']
27
+ end
28
+
29
+ it "should provide a for-overriding bootstrap_file_path method" do
30
+ DpkgTools::Package::Setup.bootstrap_file_path('base_path', 'deb.yml').should == 'base_path/deb.yml'
31
+ end
32
+
33
+ describe ".bootstrap_file support methods" do
34
+ it "should be able to report that a target file already exists" do
35
+ File.stubs(:file?).with('target/file/path').returns(true)
36
+ DpkgTools::Package::Setup.file_exists?('target/file/path').should be_true
37
+ end
38
+
39
+ it "should be able to report that a target file does not already exist" do
40
+ File.stubs(:file?).with('target/file/path').returns(false)
41
+ DpkgTools::Package::Setup.file_exists?('target/file/path').should be_false
42
+ end
43
+
44
+ it "should be able to move a target file out of the way by adding a .bak suffix" do
45
+ FileUtils.expects(:mv).with('target/file/path', 'target/file/path.bak')
46
+ DpkgTools::Package::Setup.move_original_aside('target/file/path')
47
+ end
48
+
49
+ it "should be able to copy a bootstrap file across to a target file path" do
50
+ FileUtils.expects(:cp).with('source/file/path', 'target/file/path.bak')
51
+ DpkgTools::Package::Setup.copy_bootstrap_file_across('source/file/path', 'target/file/path.bak')
52
+ end
53
+ end
54
+
55
+ describe ".bootstrap_file" do
56
+ before(:each) do
57
+ mock_data_class = mock('DpkgTools::Package::Data')
58
+ mock_data_class.stubs(:resources_path).returns('/a/path/to/resources')
59
+ DpkgTools::Package::Setup.stubs(:data_class).returns(mock_data_class)
60
+ end
61
+
62
+ it "should be able to create a needed files" do
63
+ DpkgTools::Package::Setup.expects(:bootstrap_file_path).with('base_path', 'deb.yml').returns('bootstrap_file_path')
64
+ File.stubs(:file?).with('bootstrap_file_path').returns(false)
65
+
66
+ FileUtils.expects(:cp).with('/a/path/to/resources/deb.yml', 'bootstrap_file_path')
67
+
68
+ DpkgTools::Package::Setup.bootstrap_file('base_path', 'deb.yml')
69
+ end
70
+
71
+ it "should not, by default, attempt to create a file that's already there..." do
72
+ DpkgTools::Package::Setup.expects(:bootstrap_file_path).with('base_path', 'deb.yml').returns('bootstrap_file_path')
73
+ File.stubs(:file?).with('bootstrap_file_path').returns(true)
74
+
75
+ FileUtils.expects(:cp).never
76
+
77
+ DpkgTools::Package::Setup.bootstrap_file('base_path', 'deb.yml')
78
+ end
79
+
80
+ it "should be able to backup and replace a file that's already there..." do
81
+ DpkgTools::Package::Setup.expects(:bootstrap_file_path).with('base_path', 'deb.yml').returns('bootstrap_file_path')
82
+ File.stubs(:file?).with('bootstrap_file_path').returns(true)
83
+
84
+ FileUtils.expects(:mv).with('bootstrap_file_path', 'bootstrap_file_path.bak')
85
+ FileUtils.expects(:cp).with('/a/path/to/resources/deb.yml', 'bootstrap_file_path')
86
+
87
+ DpkgTools::Package::Setup.bootstrap_file('base_path', 'deb.yml', :backup => true)
88
+ end
89
+ end
90
+
91
+ it ".bootstrap should copy across the files correctly" do
92
+ DpkgTools::Package::Setup.stubs(:bootstrap_files).returns('deb.yml')
93
+ DpkgTools::Package::Setup.expects(:bootstrap_file).with('base_path', 'deb.yml')
94
+
95
+ DpkgTools::Package::Setup.bootstrap('base_path')
96
+ end
97
+ end
98
+
99
+ describe ".from_path support methods" do
100
+ it "should provide a for-overriding method to return the Package::Data subclass to use" do
101
+ DpkgTools::Package::Setup.data_class.should == DpkgTools::Package::Data
102
+ end
103
+ end
104
+
105
+ describe ".from_path" do
106
+ it "should create a DpkgTools::Package::Data instance, and feed it to .new" do
107
+ DpkgTools::Package::Setup.expects(:needs_bootstrapping?).with('base_path').returns(false)
108
+ DpkgTools::Package::Data.expects(:new).with('base_path').returns(:data)
109
+ DpkgTools::Package::Setup.expects(:new).with(:data, 'base_path').returns(:instance)
110
+
111
+ DpkgTools::Package::Setup.from_path('base_path').should == :instance
112
+ end
113
+
114
+ it "should be able to bootstrap the rails app if needed" do
115
+ DpkgTools::Package::Setup.expects(:needs_bootstrapping?).with('base_path').returns(true)
116
+ DpkgTools::Package::Setup.expects(:bootstrap).with('base_path')
117
+
118
+ DpkgTools::Package::Data.expects(:new).with('base_path').returns(:data)
119
+ DpkgTools::Package::Setup.expects(:new).with(:data, 'base_path').returns(:instance)
120
+
121
+ DpkgTools::Package::Setup.from_path('base_path').should == :instance
122
+ end
123
+ end
124
+ end
125
+
126
+ describe DpkgTools::Package::Setup, "#create_structure" do
127
+ before(:each) do
128
+ @data = stub("stub DpkgTools::Package::Data", :name => 'hello', :version => '1')
129
+ DpkgTools::Package::Config.root_path = '/a/path/to/package/dirs'
130
+ @config = DpkgTools::Package::Config.new('hello', '1', {})
131
+ DpkgTools::Package::Config.expects(:new).with('hello', '1', {}).returns(@config)
132
+
133
+ @setup = DpkgTools::Package::Setup.new(@data, :base_path => 'base_path')
134
+ end
135
+
136
+ it "should be able to provide the options needed for DpkgTools::Package::Config" do
137
+ @setup.config_options.should == {}
138
+ end
139
+
140
+ it "should be able to perform all the steps needed to create the package structure" do
141
+ DpkgTools::Package.expects(:check_package_dir).with(@config)
142
+
143
+ @setup.expects(:prepare_package)
144
+ @setup.expects(:write_control_files)
145
+ @setup.expects(:copy_maintainer_script_templates)
146
+
147
+ @setup.create_structure
148
+ end
149
+
150
+ it "should be able to write out the control files" do
151
+ mock_control_file = mock('DpkgTools::Package::ControlFile::* instance')
152
+ mock_control_file.expects(:write)
153
+
154
+ mock_control_file_class = mock('DpkgTools::Package::ControlFile::* class')
155
+ mock_control_file_class.expects(:new).with(@data, @config).returns(mock_control_file)
156
+
157
+ @setup.expects(:control_file_classes).returns([mock_control_file_class])
158
+
159
+ @setup.write_control_files
160
+ end
161
+
162
+ it "should be able to return a list of maintainer script template names" do
163
+ @setup.maintainer_script_template_names.should == ['postinst.erb', 'postrm.erb', 'preinst.erb', 'prerm.erb']
164
+ end
165
+
166
+ it "should be able to copy across any of the maintainer script templates present in the resources dir" do
167
+ @data.stubs(:resources_path).returns('/a/path/to/resources')
168
+ File.expects(:file?).with('/a/path/to/resources/postinst.erb').returns(true)
169
+ File.expects(:file?).with('/a/path/to/resources/postrm.erb').returns(false)
170
+ File.expects(:file?).with('/a/path/to/resources/preinst.erb').returns(false)
171
+ File.expects(:file?).with('/a/path/to/resources/prerm.erb').returns(true)
172
+
173
+ FileUtils.expects(:cp).with('/a/path/to/resources/postinst.erb', '/a/path/to/package/dirs/hello-1/debian/postinst.erb')
174
+ FileUtils.expects(:cp).with('/a/path/to/resources/prerm.erb', '/a/path/to/package/dirs/hello-1/debian/prerm.erb')
175
+
176
+ @setup.copy_maintainer_script_templates
177
+ end
178
+
179
+ it "should provide a no-op version of prepare_package" do
180
+ @setup.should respond_to(:prepare_package)
181
+ end
182
+ end
183
+
184
+ describe DpkgTools::Package::Setup, "regenerating control files and maintainer scripts" do
185
+ before(:each) do
186
+ @data = stub("stub DpkgTools::Package::Data", :name => 'hello', :version => '1')
187
+ DpkgTools::Package::Config.root_path = '/a/path/to/package/dirs'
188
+ @config = DpkgTools::Package::Config.new('hello', '1', {})
189
+ DpkgTools::Package::Config.expects(:new).with('hello', '1', {}).returns(@config)
190
+
191
+ @setup = DpkgTools::Package::Setup.new(@data, :base_path => 'base_path')
192
+ end
193
+
194
+ it "should be able to regenerate the control files, saving the existing files to name.bak" do
195
+ mock_control_file_class = mock('DpkgTools::Package::ControlFile')
196
+ mock_control_file_class.expects(:new).with(@data, @config).returns(mock_control_file_class)
197
+ mock_control_file_class.stubs(:needs_reset?).returns(true)
198
+ mock_control_file_class.stubs(:file_path).returns('/a/path/to/control_file')
199
+ @setup.stubs(:control_file_classes).returns([mock_control_file_class])
200
+
201
+ mock_control_file_class.expects(:write)
202
+ File.expects(:exist?).with('/a/path/to/control_file').returns(true)
203
+ FileUtils.expects(:mv).with('/a/path/to/control_file', '/a/path/to/control_file.bak')
204
+ @setup.reset_control_files
205
+ end
206
+
207
+ it "should not bother trying to back up a control file if the file is missing" do
208
+ mock_control_file_class = mock('DpkgTools::Package::ControlFile')
209
+ mock_control_file_class.expects(:new).with(@data, @config).returns(mock_control_file_class)
210
+ mock_control_file_class.stubs(:needs_reset?).returns(true)
211
+ mock_control_file_class.stubs(:file_path).returns('/a/path/to/control_file')
212
+ @setup.stubs(:control_file_classes).returns([mock_control_file_class])
213
+
214
+ File.expects(:exist?).with('/a/path/to/control_file').returns(false)
215
+ mock_control_file_class.expects(:write)
216
+ @setup.reset_control_files
217
+ end
218
+
219
+ it "should not try to regenerate a control file which doesn't need it" do
220
+ mock_control_file_class = mock('DpkgTools::Package::ControlFile')
221
+ mock_control_file_class.expects(:new).with(@data, @config).returns(mock_control_file_class)
222
+ mock_control_file_class.stubs(:needs_reset?).returns(false)
223
+ mock_control_file_class.stubs(:file_path).returns('/a/path/to/control_file')
224
+ @setup.stubs(:control_file_classes).returns([mock_control_file_class])
225
+
226
+ mock_control_file_class.expects(:write).never
227
+ @setup.reset_control_files
228
+ end
229
+
230
+ it "should be able to regenerate maintainer scripts, as needed" do
231
+ @data.stubs(:resources_path).returns('/a/path/to/resources')
232
+ File.expects(:file?).with('/a/path/to/resources/postinst.erb').returns(true)
233
+ File.expects(:file?).with('/a/path/to/resources/postrm.erb').returns(false)
234
+ File.expects(:file?).with('/a/path/to/resources/preinst.erb').returns(false)
235
+ File.expects(:file?).with('/a/path/to/resources/prerm.erb').returns(true)
236
+
237
+ FileUtils.expects(:identical?).with('/a/path/to/resources/prerm.erb',
238
+ '/a/path/to/package/dirs/hello-1/debian/prerm.erb').returns(true)
239
+ FileUtils.expects(:identical?).with('/a/path/to/resources/postinst.erb',
240
+ '/a/path/to/package/dirs/hello-1/debian/postinst.erb').returns(false)
241
+ FileUtils.expects(:mv).with('/a/path/to/package/dirs/hello-1/debian/postinst.erb',
242
+ '/a/path/to/package/dirs/hello-1/debian/postinst.erb.bak')
243
+ FileUtils.expects(:cp).with('/a/path/to/resources/postinst.erb', '/a/path/to/package/dirs/hello-1/debian/postinst.erb')
244
+
245
+ @setup.reset_maintainer_script_templates
246
+ end
247
+ end