reciper 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1 @@
1
+ pkg/*
@@ -4,6 +4,9 @@ module Reciper
4
4
  class NoTestOutput < RuntimeError
5
5
  end
6
6
 
7
+ class NoFileToBeOverriden < RuntimeError
8
+ end
9
+
7
10
  module Helpers
8
11
  def copy_file(filename, options={})
9
12
  destination_dir = @ruby_app_path + "/" + (options[:to] || "")
@@ -14,7 +17,13 @@ module Reciper
14
17
 
15
18
  FileUtils.cp(@recipe_path + "/" + filename, destination_dir)
16
19
 
17
- @operations << [:copy, (options[:to] || "") + filename]
20
+ new_filename = options[:as] || filename
21
+
22
+ if(options[:as])
23
+ FileUtils.mv(destination_dir + "/" + filename, destination_dir + "/" + new_filename)
24
+ end
25
+
26
+ @operations << [:copy, (options[:to] || "") + new_filename]
18
27
  end
19
28
 
20
29
  def run_tests(options={})
@@ -71,6 +80,8 @@ module Reciper
71
80
  spawn(operation[1]) if operation[1]
72
81
 
73
82
  Process.wait
83
+ elsif operation[0] == :override_file
84
+ FileUtils.cp(operation[1], @ruby_app_path + "/" + operation[2])
74
85
  end
75
86
  end
76
87
  end
@@ -89,5 +100,21 @@ module Reciper
89
100
  false
90
101
  end
91
102
  end
103
+
104
+ def override_file(file, file_to_be_overriden)
105
+ Dir.chdir(@ruby_app_path) do
106
+ fail NoFileToBeOverriden unless File.exists?(file_to_be_overriden)
107
+
108
+ FileUtils.mkdir_p("/tmp/reciper")
109
+ filename = File.basename(file_to_be_overriden)
110
+ tmp_file = "/tmp/reciper/#{filename}"
111
+
112
+ FileUtils.cp(file_to_be_overriden, tmp_file)
113
+
114
+ @operations << [:override_file, tmp_file, file_to_be_overriden]
115
+ end
116
+
117
+ FileUtils.cp(@recipe_path + "/" + file, @ruby_app_path + "/" + file_to_be_overriden)
118
+ end
92
119
  end
93
120
  end
@@ -1,3 +1,3 @@
1
1
  module Reciper
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
File without changes
@@ -0,0 +1 @@
1
+ some content
@@ -33,6 +33,16 @@ describe Reciper::Helpers do
33
33
  FileUtils.rm("spec/fixtures/ruby_app/lib/file.rb")
34
34
  end
35
35
 
36
+ it "copies the file with the name as in defined in as" do
37
+ File.exists?("spec/fixtures/ruby_app/file.rb").should_not be
38
+
39
+ copy_file("file.rb", :as => "another_file.rb")
40
+
41
+ File.exists?("spec/fixtures/ruby_app/another_file.rb").should be
42
+
43
+ FileUtils.rm("spec/fixtures/ruby_app/another_file.rb")
44
+ end
45
+
36
46
  it "if the dir doesn't exists, create it" do
37
47
  File.exists?("spec/fixtures/ruby_app/lib/file.rb").should_not be
38
48
 
@@ -187,5 +197,46 @@ EOF
187
197
 
188
198
  rollback
189
199
  end
200
+
201
+ it "runs the rollback command when the operation is override_file" do
202
+ begin
203
+ FileUtils.cp("spec/fixtures/ruby_app/README", "/tmp/README")
204
+ FileUtils.rm("spec/fixtures/ruby_app/README")
205
+
206
+ File.exists?("spec/fixtures/ruby_app/README").should_not be
207
+
208
+ @operations = [[:override_file, "/tmp/README", "README"]]
209
+
210
+ rollback
211
+
212
+ File.exists?("spec/fixtures/ruby_app/README").should be
213
+ ensure
214
+ FileUtils.cp("/tmp/README", "spec/fixtures/ruby_app/README") unless File.exists?("spec/fixtures/ruby_app/README")
215
+ end
216
+ end
217
+ end
218
+
219
+ describe ".override_file" do
220
+ it "overrides the file with another file" do
221
+ FileUtils.cp("spec/fixtures/ruby_app/README", "/tmp/README")
222
+
223
+ File.read("spec/fixtures/ruby_app/README").should == "some content"
224
+
225
+ override_file("README", "README")
226
+
227
+ File.read("spec/fixtures/ruby_app/README").should == ""
228
+
229
+ FileUtils.mv("/tmp/README", "spec/fixtures/ruby_app/README")
230
+ end
231
+
232
+ it "adds the operation to operations array" do
233
+ FileUtils.cp("spec/fixtures/ruby_app/README", "/tmp/README")
234
+
235
+ override_file("README", "README")
236
+
237
+ @operations.should include([:override_file, "/tmp/reciper/README", "README"])
238
+
239
+ FileUtils.mv("/tmp/README", "spec/fixtures/ruby_app/README")
240
+ end
190
241
  end
191
242
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: reciper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-04-10 00:00:00.000000000 Z
12
+ date: 2012-04-11 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: An awesome way to write recipes for a book chapter
15
15
  email:
@@ -18,6 +18,7 @@ executables: []
18
18
  extensions: []
19
19
  extra_rdoc_files: []
20
20
  files:
21
+ - .gitignore
21
22
  - Gemfile
22
23
  - Gemfile.lock
23
24
  - LICENSE
@@ -26,11 +27,13 @@ files:
26
27
  - lib/reciper/helpers.rb
27
28
  - lib/reciper/version.rb
28
29
  - reciper.gemspec
30
+ - spec/fixtures/recipe/README
29
31
  - spec/fixtures/recipe/failing_spec.rb
30
32
  - spec/fixtures/recipe/file.rb
31
33
  - spec/fixtures/recipe/my_name.rb
32
34
  - spec/fixtures/ruby_app/Gemfile
33
35
  - spec/fixtures/ruby_app/Gemfile.lock
36
+ - spec/fixtures/ruby_app/README
34
37
  - spec/fixtures/ruby_app/Rakefile
35
38
  - spec/fixtures/ruby_app/lib/my_class.rb
36
39
  - spec/fixtures/ruby_app/spec/true_spec.rb
@@ -61,11 +64,13 @@ signing_key:
61
64
  specification_version: 3
62
65
  summary: An awesome way to write recipes for a book chapter
63
66
  test_files:
67
+ - spec/fixtures/recipe/README
64
68
  - spec/fixtures/recipe/failing_spec.rb
65
69
  - spec/fixtures/recipe/file.rb
66
70
  - spec/fixtures/recipe/my_name.rb
67
71
  - spec/fixtures/ruby_app/Gemfile
68
72
  - spec/fixtures/ruby_app/Gemfile.lock
73
+ - spec/fixtures/ruby_app/README
69
74
  - spec/fixtures/ruby_app/Rakefile
70
75
  - spec/fixtures/ruby_app/lib/my_class.rb
71
76
  - spec/fixtures/ruby_app/spec/true_spec.rb