Skip to content

Commit 24391e6

Browse files
committed
Eschew use of sed
At least on the Mac, the `sed` command silently fails, not replacing `LOCALUSERNAME`. There, a correct invocation is something like: ``` sh "sed -i '' -e 's/LOCALUSERNAME/#{ENV['USER']}/' #{dst_path}" ``` Rather than comprehensively account for differences in `sed` on various platforms, use Ruby's File class to manipulate the files.
1 parent 71a0058 commit 24391e6

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

tasks/rspec.rake

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,26 @@ file 'spec/configuration.yml' => 'spec/configuration.yml.example' do |task|
3636
CLEAN.exclude task.name
3737
src_path = File.expand_path("../../#{task.prerequisites.first}", __FILE__)
3838
dst_path = File.expand_path("../../#{task.name}", __FILE__)
39-
cp src_path, dst_path
40-
sh "sed -i 's/LOCALUSERNAME/#{ENV['USER']}/' #{dst_path}"
39+
40+
dst_file = File.open(dst_path, 'w')
41+
File.open(src_path) do |f|
42+
f.each_line do |line|
43+
dst_file.write line.gsub(/LOCALUSERNAME/, ENV['USER'])
44+
end
45+
end
4146
end
4247

4348
file 'spec/my.cnf' => 'spec/my.cnf.example' do |task|
4449
CLEAN.exclude task.name
4550
src_path = File.expand_path("../../#{task.prerequisites.first}", __FILE__)
4651
dst_path = File.expand_path("../../#{task.name}", __FILE__)
47-
cp src_path, dst_path
48-
sh "sed -i 's/LOCALUSERNAME/#{ENV['USER']}/' #{dst_path}"
52+
53+
dst_file = File.open(dst_path, 'w')
54+
File.open(src_path) do |f|
55+
f.each_line do |line|
56+
dst_file.write line.gsub(/LOCALUSERNAME/, ENV['USER'])
57+
end
58+
end
4959
end
5060

5161
Rake::Task[:spec].prerequisites << :'spec/configuration.yml'

0 commit comments

Comments
 (0)