jumpstart 0.6.3 → 0.6.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/Rakefile CHANGED
@@ -72,5 +72,5 @@ end
72
72
  def rubygems_actions
73
73
  Dir.chdir("#{JumpStart::ROOT_PATH}")
74
74
  system "gem build jumpstart.gemspec"
75
- system "gem push jumpstart-#{JumpStart.version}.gem"
75
+ system "gem push jumpstart-#{JumpStart.version}.gem"
76
76
  end
@@ -1,4 +1,4 @@
1
1
  ---
2
2
  :jumpstart_version_major: 0
3
3
  :jumpstart_version_minor: 6
4
- :jumpstart_version_patch: 3
4
+ :jumpstart_version_patch: 4
@@ -123,24 +123,30 @@ module JumpStart::FileTools
123
123
  # Will also replace strings present in the target_file path. so if the method call looked like: FileUtils.replace_strings(target_file, :name => "Ian", :country => "England")
124
124
  # and target_file was: /Users/name/Sites/country the strings matching NAME and COUNTRY inside the file would be swapped out and then a new file at the path: /Users/Ian/Sites/England would be created and populated with the contents. The file at the previous path would be deleted.
125
125
  # Finally if you specify a symbol and append _CLASS in the template, that instance will be replace with a capitalized version of the string.
126
+
127
+ #TODO REMOVE DIRECTORY PATH FROM FILE NAME SO THAT FILE CREATION REMAINS CONSISTENT
128
+
126
129
  def replace_strings(target_file, args)
127
130
  if File.file?(target_file)
128
131
  permissions = File.executable?(target_file)
129
132
  txt = IO.read(target_file)
130
133
  old_dir = target_file.sub(/\/\w+\.*\w*$/, '')
131
- new_file = target_file.dup
134
+ new_file = target_file.gsub(/#{old_dir}/, '')
135
+ new_dir = old_dir.dup
132
136
  args.each do |x, y|
133
137
  txt.gsub!(/#{x.to_s.upcase}_CLASS/, y.capitalize)
134
138
  txt.gsub!(/#{x.to_s.upcase}/, y)
139
+ new_dir.gsub!(/\/#{x.to_s.downcase}/, "/#{y}")
135
140
  new_file.gsub!(/#{x.to_s.downcase}/, y)
136
141
  end
137
- new_dir = new_file.sub(/\/\w+\.*\w*$/, '')
138
- FileUtils.mkdir_p(new_dir)
139
- FileUtils.rm(target_file)
140
- File.open(new_file, "w") do |file|
142
+ if old_dir.to_s != new_dir.to_s
143
+ FileUtils.mkdir_p(new_dir)
144
+ end
145
+ File.open(FileUtils.join_paths(new_dir, new_file), "w+") do |file|
141
146
  file.puts txt
142
147
  file.chmod(0755) if permissions
143
148
  end
149
+ FileUtils.rm(target_file)
144
150
  if File.directory?(old_dir)
145
151
  if (Dir.entries(old_dir) - JumpStart::IGNORE_DIRS).empty?
146
152
  FileUtils.remove_dir(old_dir)
@@ -0,0 +1,65 @@
1
+ set :application, 'APP_NAME'
2
+ set :domain, 'REMOTE_SERVER'
3
+ set :user, 'i0n'
4
+
5
+ set :repository, "#{user}@#{domain}:/home/#{user}/git/#{application}.git"
6
+
7
+ role :app, domain # This may be the same as the `Web` server
8
+ role :web, domain # Your HTTP server, Apache/etc
9
+ role :db, domain , :primary => true # This is where Rails migrations will run
10
+
11
+ set :scm_verbose, true
12
+
13
+ set :scm, :git
14
+ set :scm_username, user
15
+ set :runner, user
16
+ set :use_sudo, false
17
+ set :branch, "master"
18
+ set :deploy_via, :checkout
19
+ set :git_shallow_clone, 1
20
+ set :deploy_to, "/home/#{user}/sites/#{application}"
21
+ default_run_options[:pty] = true
22
+
23
+ namespace :deploy do
24
+ #task which causes Passenger to initiate a restart
25
+ task :restart do
26
+ run "mkdir -p #{release_path}/tmp && touch #{release_path}/tmp/restart.txt"
27
+ end
28
+
29
+ namespace :db do
30
+
31
+ desc "Create database for the production environment using the servers rake db:setup task.\n Loads the schema, and initializes with the seed data"
32
+ task :setup do
33
+ run "cd #{current_path}; rake db:setup RAILS_ENV=production"
34
+ end
35
+
36
+ desc "Populates the production database using lib/tasks/populate which I will use as my own internal convention for this process"
37
+ task :populate do
38
+ run "cd #{current_path}; rake db:populate RAILS_ENV=production"
39
+ end
40
+
41
+ end
42
+
43
+ desc "Task to set up the remote Nginx server for app deployment"
44
+ task :nginx do
45
+ run "#{sudo} nginx_auto_config /usr/local/bin/nginx.remote.conf /opt/nginx/conf/nginx.conf APP_NAME"
46
+ end
47
+
48
+ desc "Create bare remote git repo then add remote origin to local git repo and push to remote"
49
+ task :git do
50
+ run "cd /home/#{user}/git; mkdir #{application}.git; cd #{application}.git; git init --bare"
51
+ `git remote add origin ssh://#{user}@#{domain}/~/git/#{application}.git`
52
+ `git push origin master`
53
+ end
54
+
55
+ end
56
+
57
+ # Reminder of default actions for cap deploy:
58
+ # deploy:update_code
59
+ # deploy:symlink
60
+ # deploy:restart
61
+
62
+ # eg: after 'deploy:symlink', 'deploy:restart'
63
+
64
+ # This is a test string APP_NAME_CLASS
65
+ # This is a test string REMOTE_SERVER_CLASS
@@ -1196,8 +1196,6 @@ class TestJumpstartBase < Test::Unit::TestCase
1196
1196
  assert File.exists?("#{JumpStart::ROOT_PATH}/test/destination_dir/test_jumpstart_project/normal_folder_name/test_line_file_without_extension")
1197
1197
  assert File.exists?("#{JumpStart::ROOT_PATH}/test/destination_dir/test_jumpstart_project/normal_folder_name/test_whole_file_with_extension.txt")
1198
1198
  assert File.exists?("#{JumpStart::ROOT_PATH}/test/destination_dir/test_jumpstart_project/normal_folder_name/test_whole_file_without_extension")
1199
- assert File.exists?("#{JumpStart::ROOT_PATH}/test/destination_dir/test_jumpstart_project/test_replace_strings/replace_strings_1.rb")
1200
- assert File.exists?("#{JumpStart::ROOT_PATH}/test/destination_dir/test_jumpstart_project/test_replace_strings/replace_strings_2.txt")
1201
1199
  assert File.exists?("#{JumpStart::ROOT_PATH}/test/destination_dir/test_jumpstart_project/test_append_to_end_of_file_remove_last_line_1.txt")
1202
1200
  assert !File.exists?("#{JumpStart::ROOT_PATH}/test/destination_dir/test_jumpstart_project/_L._test_append_to_end_of_file_remove_last_line_1.txt")
1203
1201
  assert File.exists?("#{JumpStart::ROOT_PATH}/test/destination_dir/test_jumpstart_project/test_append_to_end_of_file_remove_last_line_2.txt")
@@ -3,41 +3,41 @@ require 'helper'
3
3
  class TestJumpstartFileTools < Test::Unit::TestCase
4
4
 
5
5
  context "Testing JumpStart::FileUtils#append_after_line class method.\n" do
6
-
6
+
7
7
  setup do
8
8
  FileUtils.remove_lines("#{JumpStart::ROOT_PATH}/test/test_jumpstart_templates/test_fileutils/append_after_line_test.txt", :pattern => "Inserted by append_after_line method test.")
9
9
  end
10
-
10
+
11
11
  should "insert specified line at line number 4 of target file" do
12
12
  FileUtils.append_after_line("#{JumpStart::ROOT_PATH}/test/test_jumpstart_templates/test_fileutils/append_after_line_test.txt", "Line from check_source_type.txt. Line number: 3", "Inserted by append_after_line method test.")
13
13
  file = IO.readlines("#{JumpStart::ROOT_PATH}/test/test_jumpstart_templates/test_fileutils/append_after_line_test.txt")
14
14
  assert_equal 4, (file.find_index("Inserted by append_after_line method test.\n").to_i + 1)
15
15
  end
16
-
16
+
17
17
  should "fail because new line is not specified." do
18
18
  assert_raises(ArgumentError) {FileUtils.append_after_line("#{JumpStart::ROOT_PATH}/test/test_jumpstart_templates/test_fileutils/append_after_line_test.txt", "Line from check_source_type.txt. Line number: 3")}
19
19
  end
20
-
20
+
21
21
  should "fail because the target file does not exist" do
22
22
  assert_raises(Errno::ENOENT) {FileUtils.append_after_line("#{JumpStart::ROOT_PATH}/test/test_jumpstart_templates/test_fileutils/this_file_does_not_exist.txt", "Line from check_source_type.txt. Line number: 3", "Inserted by append_after_line method test.")}
23
23
  end
24
-
24
+
25
25
  end
26
-
26
+
27
27
  context "Testing JumpStart::FileUtils#append_to_end_of_file class method.\n" do
28
-
28
+
29
29
  setup do
30
30
  @file_path = "#{JumpStart::ROOT_PATH}/test/test_jumpstart_templates/test_fileutils/append_to_end_of_file_test.txt"
31
31
  FileUtils.remove_lines(@file_path, :pattern => "TEST LINE INSERTED")
32
32
  FileUtils.remove_lines(@file_path, :pattern => "TEST LINE INSERTED FROM FILE")
33
33
  end
34
-
34
+
35
35
  should "add the string passed in the method call to the specified file" do
36
36
  FileUtils.append_to_end_of_file("TEST LINE INSERTED", @file_path)
37
37
  file = IO.readlines(@file_path)
38
38
  assert_equal 6, (file.find_index("TEST LINE INSERTED\n").to_i + 1)
39
39
  end
40
-
40
+
41
41
  should "add the string passed in the method call to the specified file and remove the last line" do
42
42
  # Two appended lines so that the file doesn't lose all lines over time.
43
43
  FileUtils.append_to_end_of_file("TEST LINE INSERTED", @file_path)
@@ -46,13 +46,13 @@ class TestJumpstartFileTools < Test::Unit::TestCase
46
46
  assert_equal "TEST LINE INSERTED\n", file.last
47
47
  assert_equal 6, file.count
48
48
  end
49
-
49
+
50
50
  should "add the contents of the file passed in the method call to the specified file" do
51
51
  FileUtils.append_to_end_of_file("#{JumpStart::ROOT_PATH}/test/test_jumpstart_templates/test_fileutils/append_to_end_of_file_source.txt", @file_path)
52
52
  file = IO.readlines(@file_path)
53
53
  assert_equal 6, (file.find_index("TEST LINE INSERTED FROM FILE\n").to_i + 1)
54
54
  end
55
-
55
+
56
56
  should "add the contents of the file passed in the method call to the specified file and remove the last line" do
57
57
  # Two appended lines so that the file doesn't lose all lines over time.
58
58
  FileUtils.append_to_end_of_file("#{JumpStart::ROOT_PATH}/test/test_jumpstart_templates/test_fileutils/append_to_end_of_file_source.txt", @file_path)
@@ -61,52 +61,52 @@ class TestJumpstartFileTools < Test::Unit::TestCase
61
61
  assert_equal "TEST LINE INSERTED FROM FILE\n", file.last
62
62
  assert_equal 6, file.count
63
63
  end
64
-
64
+
65
65
  should "fail because no target file is specified" do
66
66
  assert_raises(ArgumentError) {FileUtils.append_to_end_of_file("TEST LINE INSERTED")}
67
67
  end
68
-
68
+
69
69
  should "fail because target file does not exist" do
70
70
  assert_raises(Errno::ENOENT) {FileUtils.append_to_end_of_file("TEST LINE INSERTED", "#{JumpStart::ROOT_PATH}/test/test_jumpstart_templates/does_not_exist/file.txt")}
71
71
  end
72
-
72
+
73
73
  end
74
-
74
+
75
75
  context "Testing JumpStart::FileUtils#insert_text_at_line_number class method.\n" do
76
-
76
+
77
77
  setup do
78
78
  @file_path = "#{JumpStart::ROOT_PATH}/test/test_jumpstart_templates/test_fileutils/insert_text_at_line_number_test.txt"
79
79
  @source_path = "#{JumpStart::ROOT_PATH}/test/test_jumpstart_templates/test_fileutils/insert_text_at_line_number_source.txt"
80
80
  FileUtils.remove_lines(@file_path, :pattern => "TEST LINE INSERTED")
81
81
  end
82
-
82
+
83
83
  should "insert text from string into target file at line 3" do
84
84
  FileUtils.insert_text_at_line_number("TEST LINE INSERTED", @file_path, 3)
85
85
  file = IO.readlines(@file_path)
86
86
  assert_equal "TEST LINE INSERTED\n", file[2]
87
87
  assert_equal 5, file.count
88
88
  end
89
-
89
+
90
90
  should "insert text from source file into target file at line 2" do
91
91
  FileUtils.insert_text_at_line_number(@source_path, @file_path, 2)
92
92
  file = IO.readlines(@file_path)
93
93
  assert_equal "TEST LINE INSERTED FROM FILE\n", file[1]
94
94
  assert_equal 5, file.count
95
95
  end
96
-
96
+
97
97
  should "raise an exception if a line number is not passed to the method" do
98
98
  assert_raises(ArgumentError) {FileUtils.insert_text_at_line_number(@source_path, @file_path)}
99
99
  end
100
-
100
+
101
101
  should "raise an exception if the line number is not 1 or higher" do
102
102
  assert_raises(ArgumentError) {FileUtils.insert_text_at_line_number(@source_path, @file_path, 0)}
103
103
  assert_raises(ArgumentError) {FileUtils.insert_text_at_line_number(@source_path, @file_path, -10)}
104
104
  end
105
-
105
+
106
106
  end
107
-
107
+
108
108
  context "Testing JumpStart::FileUtils#remove_files class method.\n" do
109
-
109
+
110
110
  setup do
111
111
  @file_path = "#{JumpStart::ROOT_PATH}/test/test_jumpstart_templates/test_fileutils"
112
112
  FileUtils.touch("#{@file_path}/remove_files_test_1.txt")
@@ -114,14 +114,14 @@ class TestJumpstartFileTools < Test::Unit::TestCase
114
114
  FileUtils.touch("#{@file_path}/remove_files_test_3.txt")
115
115
  @file_array = []
116
116
  end
117
-
117
+
118
118
  should "delete the file remove_files_test_1.txt" do
119
119
  file = FileUtils.join_paths(@file_path, "/remove_files_test_1.txt")
120
120
  @file_array << file
121
121
  FileUtils.remove_files(@file_array)
122
122
  assert !File.exists?("#{@file_path}/remove_files_test_1.txt")
123
123
  end
124
-
124
+
125
125
  should "delete all three test files" do
126
126
  @file_array << "/remove_files_test_1.txt" << "/remove_files_test_2.txt" << "/remove_files_test_3.txt"
127
127
  @file_array.map!{|x| FileUtils.join_paths(@file_path, x)}
@@ -130,15 +130,15 @@ class TestJumpstartFileTools < Test::Unit::TestCase
130
130
  assert !File.exists?("#{@file_path}/remove_files_test_2.txt")
131
131
  assert !File.exists?("#{@file_path}/remove_files_test_3.txt")
132
132
  end
133
-
133
+
134
134
  end
135
-
135
+
136
136
  context "Testing JumpStart::FileUtils#remove_lines class method.\n" do
137
-
137
+
138
138
  setup do
139
139
  @file_path = "#{JumpStart::ROOT_PATH}/test/test_jumpstart_templates/test_fileutils/remove_lines_test.txt"
140
140
  end
141
-
141
+
142
142
  should "remove line 5 from the test file using the :lines argument" do
143
143
  FileUtils.remove_lines(@file_path, :lines => [5])
144
144
  file = IO.readlines(@file_path)
@@ -146,7 +146,7 @@ class TestJumpstartFileTools < Test::Unit::TestCase
146
146
  assert_equal "6\n", file.fetch(4)
147
147
  FileUtils.insert_text_at_line_number("5", @file_path, 5)
148
148
  end
149
-
149
+
150
150
  should "remove lines 5 & 9 from the test file using the :lines argument" do
151
151
  FileUtils.remove_lines(@file_path, :lines => [1,10])
152
152
  file = IO.readlines(@file_path)
@@ -154,7 +154,7 @@ class TestJumpstartFileTools < Test::Unit::TestCase
154
154
  FileUtils.insert_text_at_line_number("1", @file_path, 1)
155
155
  FileUtils.insert_text_at_line_number("10", @file_path, 10)
156
156
  end
157
-
157
+
158
158
  should "remove line 5 from the test file using the :line argument" do
159
159
  FileUtils.remove_lines(@file_path, :line => 5)
160
160
  file = IO.readlines(@file_path)
@@ -162,11 +162,11 @@ class TestJumpstartFileTools < Test::Unit::TestCase
162
162
  assert_equal "6\n", file.fetch(4)
163
163
  FileUtils.insert_text_at_line_number("5", @file_path, 5)
164
164
  end
165
-
165
+
166
166
  should "return an argument error as :lines and :line cannot be specified at the same time." do
167
167
  assert_raises(ArgumentError) {FileUtils.remove_lines(@file_path, :line => 5, :lines => [6,7])}
168
168
  end
169
-
169
+
170
170
  should "remove line 5 from the test file using the :pattern argument" do
171
171
  FileUtils.remove_lines(@file_path, :pattern => "5")
172
172
  file = IO.readlines(@file_path)
@@ -174,7 +174,7 @@ class TestJumpstartFileTools < Test::Unit::TestCase
174
174
  assert_equal "6\n", file.fetch(4)
175
175
  FileUtils.insert_text_at_line_number("5", @file_path, 5)
176
176
  end
177
-
177
+
178
178
  should "remove line 5 from the test file using the pattern argument, and remove line 9 from the file using the :line argument" do
179
179
  FileUtils.remove_lines(@file_path, :pattern => "5", :line => 9)
180
180
  file = IO.readlines(@file_path)
@@ -184,7 +184,7 @@ class TestJumpstartFileTools < Test::Unit::TestCase
184
184
  FileUtils.insert_text_at_line_number("5", @file_path, 5)
185
185
  FileUtils.insert_text_at_line_number("9", @file_path, 9)
186
186
  end
187
-
187
+
188
188
  should "remove line 5 from the test file using the pattern argument, and remove line 9 from the file using the :lines argument" do
189
189
  FileUtils.remove_lines(@file_path, :pattern => "5", :lines => [8,9])
190
190
  file = IO.readlines(@file_path)
@@ -196,59 +196,61 @@ class TestJumpstartFileTools < Test::Unit::TestCase
196
196
  FileUtils.insert_text_at_line_number("8", @file_path, 8)
197
197
  FileUtils.insert_text_at_line_number("9", @file_path, 9)
198
198
  end
199
-
199
+
200
200
  end
201
-
201
+
202
202
  context "Testing JumpStart::FileUtils#config_nginx class method.\n" do
203
-
203
+
204
204
  setup do
205
205
  @source_path = "#{JumpStart::ROOT_PATH}/test/test_jumpstart_templates/test_fileutils/config_nginx_source.txt"
206
206
  @target_path = "#{JumpStart::ROOT_PATH}/test/test_jumpstart_templates/test_fileutils/config_nginx_test.txt"
207
207
  @project_name = "test_project"
208
208
  FileUtils.remove_lines(@target_path, :pattern => "LINE ADDED BY TEST")
209
209
  end
210
-
210
+
211
211
  should "copy nginx source file into target path" do
212
212
  FileUtils.config_nginx(@source_path, @target_path, @project_name)
213
213
  file = IO.readlines(@target_path)
214
214
  assert_equal "LINE ADDED BY TEST\n", file[80]
215
215
  end
216
-
216
+
217
217
  end
218
-
218
+
219
219
  context "Testing JumpStart::FileUtils#config_hosts class method.\n" do
220
-
220
+
221
221
  setup do
222
222
  @project_name = "test_project"
223
223
  @target_path = "#{JumpStart::ROOT_PATH}/test/test_jumpstart_templates/test_fileutils/hosts_test"
224
224
  FileUtils.remove_lines(@target_path, :pattern => "127.0.0.1 test_project.local")
225
225
  end
226
-
226
+
227
227
  should "add line for test_project.local to hosts_test file" do
228
228
  FileUtils.config_hosts(@target_path, @project_name)
229
229
  file = IO.readlines(@target_path)
230
230
  assert_equal "127.0.0.1 test_project.local\n", file[10]
231
231
  end
232
-
232
+
233
233
  end
234
234
 
235
- context "Testing JumpStart::FileUtils#replace_strings class method.\n" do
235
+ context "Testing JumpStart::FileUtils#replace_strings class method" do
236
236
 
237
237
  setup do
238
- @target_file_1 = "#{JumpStart::ROOT_PATH}/test/test_jumpstart_templates/test_fileutils/config_capistrano_test.rb"
238
+ @source_file = IO.readlines("#{JumpStart::ROOT_PATH}/test/test_jumpstart_templates/test_fileutils/config_capistrano_source.rb")
239
239
  @target_file_2 = "#{JumpStart::ROOT_PATH}/test/test_jumpstart_templates/test_fileutils/replace_strings_test_app_name.rb"
240
240
  @target_file_3 = "#{JumpStart::ROOT_PATH}/test/test_jumpstart_templates/test_fileutils/app_name/app_name_replace_strings_test.txt"
241
241
  @new_file_2 = "#{JumpStart::ROOT_PATH}/test/test_jumpstart_templates/test_fileutils/replace_strings_test_bungle.rb"
242
242
  @new_file_3 = "#{JumpStart::ROOT_PATH}/test/test_jumpstart_templates/test_fileutils/bungle/bungle_replace_strings_test.txt"
243
- @target_files = []
244
- @target_files << @target_file_1 << @target_file_2 << @target_file_3
245
- @source_file = IO.readlines("#{JumpStart::ROOT_PATH}/test/test_jumpstart_templates/test_fileutils/config_capistrano_source.rb")
243
+ @target_files = [@target_file_2, @target_file_3]
246
244
  FileUtils.mkdir_p("#{JumpStart::ROOT_PATH}/test/test_jumpstart_templates/test_fileutils/app_name")
247
- @target_files.each do |x|
248
- File.open(x, 'w+') do |file|
245
+ @target_files.each do |t|
246
+ File.open(t, 'w+') do |file|
249
247
  file.puts @source_file
250
248
  end
251
249
  end
250
+ @target_file_4 = "#{JumpStart::ROOT_PATH}/test/destination_dir/config_capistrano.rb"
251
+ File.open(@target_file_4, 'w+') do |file|
252
+ file.puts @source_file
253
+ end
252
254
  end
253
255
 
254
256
  teardown do
@@ -264,21 +266,6 @@ class TestJumpstartFileTools < Test::Unit::TestCase
264
266
  end
265
267
  end
266
268
 
267
- should "replace strings with replace_strings method if the path does not contain the replacement strings and only one replacement string is provided" do
268
- FileUtils.replace_strings(@target_file_1, :app_name => 'test_app')
269
- file = IO.readlines(@target_file_1)
270
- assert_equal "set :application, 'test_app'\n", file[0]
271
- assert_equal "run \"\#{sudo} nginx_auto_config /usr/local/bin/nginx.remote.conf /opt/nginx/conf/nginx.conf test_app\"\n", file[44]
272
- end
273
-
274
- should "replace strings with replace_strings method if the path does not contain the replacement strings and more than one replacement string is provided" do
275
- FileUtils.replace_strings(@target_file_1, :app_name => 'test_app', :REMOTE_SERVER => 'remote_box')
276
- file = IO.readlines(@target_file_1)
277
- assert_equal "set :application, 'test_app'\n", file[0]
278
- assert_equal "set :domain, 'remote_box'\n", file[1]
279
- assert_equal "run \"\#{sudo} nginx_auto_config /usr/local/bin/nginx.remote.conf /opt/nginx/conf/nginx.conf test_app\"\n", file[44]
280
- end
281
-
282
269
  should "replace strings inside the target path if the target is a file and there is more than one argument." do
283
270
  FileUtils.replace_strings(@target_file_2, :app_name => 'bungle', :remote_server => 'boxy')
284
271
  file = IO.readlines(@new_file_2)
@@ -288,7 +275,7 @@ class TestJumpstartFileTools < Test::Unit::TestCase
288
275
  assert File.exists?(@new_file_2)
289
276
  assert !File.exists?(@target_file_2)
290
277
  end
291
-
278
+
292
279
  should "replace strings inside the target path if the target is a file and there is more than one argument and the replacement string is found in the directory structure." do
293
280
  FileUtils.replace_strings(@target_file_3, :app_name => 'bungle', :remote_server => 'boxy')
294
281
  file = IO.readlines(@new_file_3)
@@ -298,7 +285,7 @@ class TestJumpstartFileTools < Test::Unit::TestCase
298
285
  assert File.exists?(@new_file_3)
299
286
  assert !File.exists?(@target_file_3)
300
287
  end
301
-
288
+
302
289
  should "replace strings that have _CLASS appended to them with a capitalised version of the replacement string." do
303
290
  FileUtils.replace_strings(@target_file_3, :app_name => 'bungle', :remote_server => 'boxy')
304
291
  file = IO.readlines(@new_file_3)
@@ -322,15 +309,15 @@ class TestJumpstartFileTools < Test::Unit::TestCase
322
309
  assert File.directory?("#{JumpStart::ROOT_PATH}/test/test_jumpstart_templates/test_fileutils/app_name")
323
310
  assert File.exists?(@new_file_3)
324
311
  end
325
-
312
+
326
313
  end
327
-
314
+
328
315
  context "Testing JumpStart::FileUtils#check_source_type class method.\n" do
329
-
316
+
330
317
  should "return source as a string" do
331
318
  assert_equal "source_as_a_string", FileUtils.check_source_type("source_as_a_string")
332
319
  end
333
-
320
+
334
321
  should "return source as an array" do
335
322
  assert_equal ["Line from check_source_type.txt. Line number: 1\n",
336
323
  "Line from check_source_type.txt. Line number: 2\n",
@@ -343,7 +330,7 @@ class TestJumpstartFileTools < Test::Unit::TestCase
343
330
  "Line from check_source_type.txt. Line number: 9\n",
344
331
  "Line from check_source_type.txt. Line number: 10"], FileUtils.check_source_type("#{JumpStart::ROOT_PATH}/test/test_jumpstart_templates/test_fileutils/check_source_type.txt")
345
332
  end
346
-
333
+
347
334
  should "return source as an array, even without a file extension." do
348
335
  assert_equal ["Line from check_source_type.txt. Line number: 1\n",
349
336
  "Line from check_source_type.txt. Line number: 2\n",
@@ -351,77 +338,77 @@ class TestJumpstartFileTools < Test::Unit::TestCase
351
338
  "Line from check_source_type.txt. Line number: 4\n",
352
339
  "Line from check_source_type.txt. Line number: 5"], FileUtils.check_source_type("#{JumpStart::ROOT_PATH}/test/test_jumpstart_templates/test_fileutils/check_source_type")
353
340
  end
354
-
341
+
355
342
  end
356
-
343
+
357
344
  context "Testing JumpStart::#join_paths class method.\n" do
358
-
345
+
359
346
  should "return the relative path passed to it unaltered." do
360
347
  assert_equal "path/to/file.txt", FileUtils.join_paths("path/to/file.txt")
361
348
  end
362
-
349
+
363
350
  should "return the absolute path passed to it unaltered." do
364
351
  assert_equal "/path/to/file.txt", FileUtils.join_paths("/path/to/file.txt")
365
352
  end
366
-
353
+
367
354
  should "return the path even if it is passed as a variable" do
368
355
  string = "/path/to/file.txt"
369
356
  assert_equal string, FileUtils.join_paths(string)
370
357
  end
371
-
358
+
372
359
  should "return a valid path if too many forward slashes are entered as an array" do
373
360
  a = %w[this/ //array/// /of/ /paths/ /has// /far/ //too/ ////many/ /forward// /slashes.txt]
374
361
  assert_equal "this/array/of/paths/has/far/too/many/forward/slashes.txt", FileUtils.join_paths(a)
375
362
  end
376
-
363
+
377
364
  should "return a valid path if too many forward slashes are entered as strings" do
378
365
  a,b,c,d,e,f,g,h,i,j = 'this/', '//array///', '/of/', '/paths/', '/has//', '/far/', '//too/', '////many/', '/forward//', '/slashes.txt'
379
366
  assert_equal "this/array/of/paths/has/far/too/many/forward/slashes.txt", FileUtils.join_paths(a,b,c,d,e,f,g,h,i,j)
380
367
  end
381
-
368
+
382
369
  should "return a valid path if paths are missing forward slashes and entered as an array" do
383
370
  a = %w[this array of paths has far too many forward slashes.txt]
384
371
  assert_equal "this/array/of/paths/has/far/too/many/forward/slashes.txt", FileUtils.join_paths(a)
385
372
  end
386
-
373
+
387
374
  should "return a valid path if paths are passed as strings and have no forward slashes" do
388
375
  a,b,c,d,e,f,g,h,i,j = 'this', 'array', 'of', 'paths', 'has', 'far', 'too', 'many', 'forward', 'slashes.txt'
389
376
  assert_equal "this/array/of/paths/has/far/too/many/forward/slashes.txt", FileUtils.join_paths(a,b,c,d,e,f,g,h,i,j)
390
377
  end
391
-
378
+
392
379
  should "return a valid path some paths have too many forward slashes and some don't. Some arguments are passed in arrays, some as strings" do
393
380
  a,b,c,d,e,f,g = 'this/', '//array///', %w[/of/], '/paths/', %w[/has// /far/], '//too/', %w[////many/ /forward// /slashes.txt]
394
381
  assert_equal "this/array/of/paths/has/far/too/many/forward/slashes.txt", FileUtils.join_paths(a,b,c,d,e,f,g)
395
382
  end
396
-
383
+
397
384
  should "return a valid path some paths have too many forward slashes and some don't. Some arguments are passed in arrays, some as strings, mixed with nil values" do
398
385
  a,b,c,d,e,f,g,h,i,j = 'this/', '//array///', nil, %w[/of/], '/paths/', %w[/has// /far/], nil, '//too/', nil, %w[////many/ /forward// /slashes.txt]
399
386
  assert_equal "this/array/of/paths/has/far/too/many/forward/slashes.txt", FileUtils.join_paths(a,b,c,d,e,f,g,h,i,j)
400
387
  end
401
-
388
+
402
389
  should "return a valid path, even if path ends with many forward slashes" do
403
390
  a,b,c,d,e,f,g,h,i,j,k = 'this/', '//array///', nil, %w[/of/], '/paths/', %w[/has// /far/], nil, '//too/', nil, %w[////many/ /forward// /slashes.txt/////]
404
391
  assert_equal "this/array/of/paths/has/far/too/many/forward/slashes.txt", FileUtils.join_paths(a,b,c,d,e,f,g,h,i,j)
405
392
  end
406
-
393
+
407
394
  should "return a valid path, even if the first path is all forward slashes and the supplied paths contain whitespace and line breaks" do
408
395
  a,b,c,d,e,f,g,h,i,j,k = "////", ' this/array///', nil, %w[/of/], '/paths/ ', %w[/has// /far/], nil, "//too/\n", nil, ["////many/\n", " /forward// ", "\n /slashes.txt\n\n\n"]
409
396
  assert_equal "/this/array/of/paths/has/far/too/many/forward/slashes.txt", FileUtils.join_paths(a,b,c,d,e,f,g,h,i,j,k)
410
397
  end
411
-
398
+
412
399
  should "return an absolute path with symbols included in the values entered." do
413
400
  a,b,c,d,e,f,g,h,i,j = "///this/\n", ' //array///', nil, %w[/of/], :paths, %w[/has// /far/], nil, "//too/\n", nil, ["////many/\n", :forward, "\n /slashes.txt\n\n\n"]
414
401
  assert_equal "/this/array/of/paths/has/far/too/many/forward/slashes.txt", FileUtils.join_paths(a,b,c,d,e,f,g,h,i,j)
415
402
  end
416
-
403
+
417
404
  end
418
-
405
+
419
406
  context "Testing JumpStart::FileUtils#sort_contained_files_and_dirs class method" do
420
-
407
+
421
408
  setup do
422
409
  @path = "#{JumpStart::ROOT_PATH}/test/test_jumpstart_templates/test_fileutils/sort_contained_files_and_dirs_test"
423
410
  end
424
-
411
+
425
412
  should "seperate files and dirs contained in the directory specified and output the collections in a hash" do
426
413
  results = FileUtils.sort_contained_files_and_dirs(@path)
427
414
  assert_equal ["/file_1.txt",
@@ -435,12 +422,12 @@ class TestJumpstartFileTools < Test::Unit::TestCase
435
422
  "/folder_1/folder_2/folder_3",
436
423
  "/folder_1/folder_2/folder_4"], results[:dirs].sort
437
424
  end
438
-
425
+
439
426
  should "return an empty hash when passed nil" do
440
427
  results = FileUtils.sort_contained_files_and_dirs(nil)
441
428
  assert_equal( {:files => [], :dirs => []}, results)
442
429
  end
443
-
430
+
444
431
  should "return an empty hash when passed a path that does not exist" do
445
432
  results = FileUtils.sort_contained_files_and_dirs("#{@path}/the_mighty_zargs_imaginary_path")
446
433
  assert_equal( {:files => [], :dirs => []}, results)
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 6
8
- - 3
9
- version: 0.6.3
8
+ - 4
9
+ version: 0.6.4
10
10
  platform: ruby
11
11
  authors:
12
12
  - Ian Alexander Wood (i0n)
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-08-31 00:00:00 +01:00
17
+ date: 2010-09-07 00:00:00 +01:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -64,6 +64,7 @@ files:
64
64
  - lib/jumpstart/stringtools.rb
65
65
  - lib/jumpstart.rb
66
66
  - source_templates/template_config.yml
67
+ - test/destination_dir/config_capistrano.rb
67
68
  - test/fake_nginx_path/local_nginx_1.conf
68
69
  - test/fake_nginx_path/remote_nginx_1.conf
69
70
  - test/helper.rb