reciper 0.1.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +2 -0
- data/.travis.yml +6 -0
- data/Changelog.md +10 -0
- data/Gemfile +5 -2
- data/Gemfile.lock +11 -1
- data/README.md +9 -9
- data/Rakefile +5 -0
- data/lib/reciper.rb +48 -1
- data/lib/reciper/helpers.rb +15 -53
- data/lib/reciper/version.rb +2 -2
- data/reciper.gemspec +2 -0
- data/spec/reciper/helpers_spec.rb +101 -184
- data/spec/reciper/reciper_spec.rb +49 -0
- metadata +26 -5
data/.gitignore
CHANGED
data/.travis.yml
ADDED
data/Changelog.md
ADDED
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,13 +1,20 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
reciper (0.1
|
4
|
+
reciper (0.2.1)
|
5
|
+
activesupport (= 3.2.5)
|
5
6
|
|
6
7
|
GEM
|
7
8
|
remote: https://rubygems.org/
|
8
9
|
specs:
|
10
|
+
activesupport (3.2.5)
|
11
|
+
i18n (~> 0.6)
|
12
|
+
multi_json (~> 1.0)
|
9
13
|
diff-lcs (1.1.3)
|
14
|
+
i18n (0.6.0)
|
15
|
+
multi_json (1.3.6)
|
10
16
|
rake (0.9.2.2)
|
17
|
+
redcarpet (2.1.1)
|
11
18
|
rspec (2.8.0)
|
12
19
|
rspec-core (~> 2.8.0)
|
13
20
|
rspec-expectations (~> 2.8.0)
|
@@ -16,6 +23,7 @@ GEM
|
|
16
23
|
rspec-expectations (2.8.0)
|
17
24
|
diff-lcs (~> 1.1.2)
|
18
25
|
rspec-mocks (2.8.0)
|
26
|
+
yard (0.7.5)
|
19
27
|
|
20
28
|
PLATFORMS
|
21
29
|
ruby
|
@@ -23,4 +31,6 @@ PLATFORMS
|
|
23
31
|
DEPENDENCIES
|
24
32
|
rake
|
25
33
|
reciper!
|
34
|
+
redcarpet
|
26
35
|
rspec
|
36
|
+
yard
|
data/README.md
CHANGED
@@ -4,7 +4,7 @@ Suppose you're writing a book containing some programming recipes. It would be g
|
|
4
4
|
|
5
5
|
Reciper is a collection of helpers that helps you write tests for your book recipes. It should be included on your described class and used whenever you need to copy files, copy line ranges, run tests, overwrite files, among other things.
|
6
6
|
|
7
|
-
##
|
7
|
+
## Installation
|
8
8
|
|
9
9
|
On your `Gemfile`, just do this:
|
10
10
|
|
@@ -12,14 +12,14 @@ On your `Gemfile`, just do this:
|
|
12
12
|
gem "reciper"
|
13
13
|
```
|
14
14
|
|
15
|
-
Run `bundle install` and
|
15
|
+
Run `bundle install` and you're ready to go!
|
16
16
|
|
17
|
-
|
18
|
-
describe "My awesome recipe" do
|
19
|
-
include Reciper::Helpers
|
20
|
-
# (...)
|
21
|
-
end
|
22
|
-
```
|
17
|
+
## Usage
|
23
18
|
|
24
|
-
|
19
|
+
Usage is really simple:
|
25
20
|
|
21
|
+
```ruby
|
22
|
+
Recipe.new("My recipe name", "recipe_path/code", "ruby_app_template").execute do
|
23
|
+
copy_file("file.rb", :as => "user.rb", :to => "app/models")
|
24
|
+
end
|
25
|
+
```
|
data/Rakefile
CHANGED
data/lib/reciper.rb
CHANGED
@@ -1,3 +1,50 @@
|
|
1
|
-
|
1
|
+
require "active_support"
|
2
|
+
require "active_support/core_ext/string"
|
3
|
+
|
4
|
+
class Reciper
|
2
5
|
require "reciper/helpers"
|
6
|
+
include Reciper::Helpers
|
7
|
+
|
8
|
+
attr_reader :name, :recipe_path, :ruby_app_path
|
9
|
+
|
10
|
+
# Initialize the recipe with the paths. It will clone the ruby_app_template_path to a path that we will run the migration.
|
11
|
+
#
|
12
|
+
# name - the recipe name
|
13
|
+
# recipe_path - the recipe path (absolute or relative to the current path)
|
14
|
+
# ruby_app_template_path - the ruby app template path (it will be cloned and it will run the migrations on this copy)
|
15
|
+
#
|
16
|
+
# Examples
|
17
|
+
#
|
18
|
+
# Recipe.new("My freaking awesome recipe", "~/Code/recipe", "~/Code/rails_app/path")
|
19
|
+
#
|
20
|
+
# Returns a recipe instance with all paths configured
|
21
|
+
def initialize(name, recipe_path, ruby_app_template_path)
|
22
|
+
@name = name
|
23
|
+
@recipe_path = recipe_path
|
24
|
+
@ruby_app_path = File.join(".", "tmp", name.parameterize("_"))
|
25
|
+
|
26
|
+
if File.directory?(@ruby_app_path)
|
27
|
+
FileUtils.rm_rf(@ruby_app_path)
|
28
|
+
end
|
29
|
+
|
30
|
+
FileUtils.mkdir_p("tmp")
|
31
|
+
|
32
|
+
FileUtils.cp_r(ruby_app_template_path, @ruby_app_path)
|
33
|
+
end
|
34
|
+
|
35
|
+
# Executes a recipe inside the block.
|
36
|
+
#
|
37
|
+
# Examples
|
38
|
+
#
|
39
|
+
# recipe.execute do
|
40
|
+
# run_rake_task("db:migrate")
|
41
|
+
# copy_file("file.rb", :as => "user.rb")
|
42
|
+
# end
|
43
|
+
#
|
44
|
+
# Returns nothing.
|
45
|
+
def execute(&block)
|
46
|
+
if block_given?
|
47
|
+
instance_eval(&block)
|
48
|
+
end
|
49
|
+
end
|
3
50
|
end
|
data/lib/reciper/helpers.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
require "fileutils"
|
2
2
|
|
3
|
-
|
3
|
+
class Reciper
|
4
4
|
class NoTestOutput < RuntimeError
|
5
5
|
end
|
6
6
|
|
@@ -11,10 +11,10 @@ module Reciper
|
|
11
11
|
end
|
12
12
|
|
13
13
|
module Helpers
|
14
|
-
# Copies the file from recipe to ruby_app.
|
14
|
+
# Copies the file from recipe to ruby_app.
|
15
15
|
#
|
16
|
-
#
|
17
|
-
#
|
16
|
+
# filename - The file to be copied relative to the recipe_path
|
17
|
+
# options - The hash options to configure the copy (default: {}):
|
18
18
|
# :as - The copy name (default: the file name).
|
19
19
|
# :to - The destination dir relative to the ruby_app_path. If the directory doesn't exists, it will be created (default: ruby_app_path root path).
|
20
20
|
#
|
@@ -31,14 +31,12 @@ module Reciper
|
|
31
31
|
destination = File.join(destination_dir , destination_file_name)
|
32
32
|
global_destination = File.join(@ruby_app_path, destination)
|
33
33
|
|
34
|
-
create_directory_if_not_exists(File.join(@ruby_app_path, destination_dir))
|
34
|
+
create_directory_if_not_exists(File.join(@ruby_app_path, destination_dir)) unless options[:to].blank?
|
35
35
|
|
36
36
|
FileUtils.cp(File.join(@recipe_path, filename), global_destination)
|
37
|
-
|
38
|
-
@operations << [:copy_file, { :destination => destination }]
|
39
37
|
end
|
40
38
|
|
41
|
-
# Run the tests on the ruby app.
|
39
|
+
# Run the tests on the ruby app.
|
42
40
|
#
|
43
41
|
# Examples
|
44
42
|
#
|
@@ -57,9 +55,9 @@ module Reciper
|
|
57
55
|
end
|
58
56
|
end
|
59
57
|
|
60
|
-
# Run a rake task on the ruby app.
|
58
|
+
# Run a rake task on the ruby app.
|
61
59
|
#
|
62
|
-
#
|
60
|
+
# task - the desired task
|
63
61
|
#
|
64
62
|
# Examples
|
65
63
|
#
|
@@ -73,11 +71,11 @@ module Reciper
|
|
73
71
|
run_command("bundle exec rake #{task}")
|
74
72
|
end
|
75
73
|
|
76
|
-
# Copies a range of lines from a file on the recipe path to a file on the ruby app path.
|
74
|
+
# Copies a range of lines from a file on the recipe path to a file on the ruby app path.
|
77
75
|
#
|
78
|
-
#
|
79
|
-
#
|
80
|
-
#
|
76
|
+
# from - the file, relative to the recipe path, that contains the file with the lines that will be copied
|
77
|
+
# to - the file, relative to the ruby app path, that contains the file that will receive the files. You can also specify a suffix like *.rb and if it matches only one file, it will insert the lines to it, otherwise it will raise a NoFileOrMultipleFilesFound exception
|
78
|
+
# options - some options related to the line copy (default: {})
|
81
79
|
# :to_line - The line where the content will be inserted (default: raises an exception)
|
82
80
|
# :lines - A range that specifies the lines that will be copied (default: whole file (0..-1))
|
83
81
|
#
|
@@ -103,35 +101,9 @@ module Reciper
|
|
103
101
|
File.open(original_file, "w") do |file|
|
104
102
|
file.write(original.flatten.join("\n"))
|
105
103
|
end
|
106
|
-
|
107
|
-
@operations << [:copy_line_range, { :original_content => original_content, :original_file => original_file }]
|
108
104
|
end
|
109
105
|
|
110
|
-
#
|
111
|
-
#
|
112
|
-
# Examples
|
113
|
-
#
|
114
|
-
# rollback
|
115
|
-
#
|
116
|
-
# Returns nothing
|
117
|
-
def rollback
|
118
|
-
@operations.reverse.each do |operation|
|
119
|
-
operation_name, arguments = operation
|
120
|
-
|
121
|
-
case operation_name
|
122
|
-
when :copy_file
|
123
|
-
then remove_file(arguments[:destination])
|
124
|
-
when :copy_range
|
125
|
-
then write_content_to_file(arguments[:original_file], arguments[:original_content])
|
126
|
-
when :run_command
|
127
|
-
then run_command(arguments[:rollback_command]) if arguments[:rollback_command]
|
128
|
-
when :override_file
|
129
|
-
then FileUtils.cp(arguments[:tmp_file], File.join(@ruby_app_path, arguments[:overriden_file]))
|
130
|
-
end
|
131
|
-
end
|
132
|
-
end
|
133
|
-
|
134
|
-
# Runs a command using bundle exec on the ruby app path. If you specify a rollback command, it is reversible.
|
106
|
+
# Runs a command using bundle exec on the ruby app path.
|
135
107
|
#
|
136
108
|
# command - the command. It will run inside a bundle exec.
|
137
109
|
# rollback_command - the command which rollbacks the command (default: nil)
|
@@ -146,7 +118,7 @@ module Reciper
|
|
146
118
|
# # => { :successful => false, response => "file a.rb doesn't exists" }
|
147
119
|
#
|
148
120
|
# Returns a command execution hash
|
149
|
-
def run_command(command
|
121
|
+
def run_command(command)
|
150
122
|
response = ""
|
151
123
|
successful = ""
|
152
124
|
|
@@ -158,15 +130,13 @@ module Reciper
|
|
158
130
|
successful = ($?.exitstatus == 0)
|
159
131
|
end
|
160
132
|
|
161
|
-
@operations << [:run_command, { :rollback_command => rollback_command }]
|
162
|
-
|
163
133
|
{
|
164
134
|
:successful => successful,
|
165
135
|
:response => response
|
166
136
|
}
|
167
137
|
end
|
168
138
|
|
169
|
-
# Overrides a file of the ruby app with a file from the recipe path.
|
139
|
+
# Overrides a file of the ruby app with a file from the recipe path.
|
170
140
|
#
|
171
141
|
# file - The file that will override relative to the recipe path
|
172
142
|
# file_to_be_overriden - The file that will be overriden
|
@@ -179,14 +149,6 @@ module Reciper
|
|
179
149
|
def override_file(file, file_to_be_overriden)
|
180
150
|
run_on_app_path do
|
181
151
|
fail NoFileToBeOverriden unless File.exists?(file_to_be_overriden)
|
182
|
-
|
183
|
-
FileUtils.mkdir_p("/tmp/reciper")
|
184
|
-
filename = File.basename(file_to_be_overriden)
|
185
|
-
tmp_file = "/tmp/reciper/#{filename}"
|
186
|
-
|
187
|
-
FileUtils.cp(file_to_be_overriden, tmp_file)
|
188
|
-
|
189
|
-
@operations << [:override_file, { :tmp_file => tmp_file, :overriden_file => file_to_be_overriden }]
|
190
152
|
end
|
191
153
|
|
192
154
|
FileUtils.cp(File.join(@recipe_path,file), File.join(@ruby_app_path, file_to_be_overriden))
|
data/lib/reciper/version.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
|
2
|
-
VERSION = "0.1
|
1
|
+
class Reciper
|
2
|
+
VERSION = "0.2.1"
|
3
3
|
end
|
data/reciper.gemspec
CHANGED
@@ -1,57 +1,57 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
|
3
3
|
describe Reciper::Helpers do
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
@recipe_path = "spec/fixtures/recipe"
|
4
|
+
before do
|
5
|
+
File.stub!(:directory?).with("./tmp/a_random_recipe").and_return(false)
|
6
|
+
FileUtils.stub!(:cp_r)
|
7
|
+
FileUtils.stub!(:mkdir_p).with("tmp")
|
9
8
|
end
|
10
9
|
|
11
|
-
|
12
|
-
|
10
|
+
let(:recipe) do
|
11
|
+
Reciper.new("a random recipe", "spec/fixtures/recipe", "spec/fixtures/ruby_app")
|
13
12
|
end
|
14
13
|
|
15
|
-
describe ".
|
14
|
+
describe ".copy_file" do
|
16
15
|
it "copies the file from the recipe path to the ruby app root path " do
|
17
|
-
FileUtils.should_receive(:cp).with("spec/fixtures/recipe/file.rb", "
|
16
|
+
FileUtils.should_receive(:cp).with("spec/fixtures/recipe/file.rb", "./tmp/a_random_recipe/file.rb")
|
18
17
|
|
19
|
-
|
18
|
+
recipe.execute do
|
19
|
+
copy_file("file.rb")
|
20
|
+
end
|
20
21
|
end
|
21
22
|
|
22
23
|
it "copies the file from the recipe path to the ruby app" do
|
23
|
-
FileUtils.should_receive(:cp).with("spec/fixtures/recipe/file.rb", "
|
24
|
+
FileUtils.should_receive(:cp).with("spec/fixtures/recipe/file.rb", "./tmp/a_random_recipe/lib/file.rb")
|
25
|
+
|
26
|
+
File.stub!(:directory?).with("./tmp/a_random_recipe/lib").and_return(true)
|
24
27
|
|
25
|
-
|
28
|
+
recipe.execute do
|
29
|
+
copy_file("file.rb", :to => "lib")
|
30
|
+
end
|
26
31
|
end
|
27
32
|
|
28
33
|
it "copies the file with the name as in defined in as" do
|
29
|
-
FileUtils.should_receive(:cp).with("spec/fixtures/recipe/file.rb", "
|
34
|
+
FileUtils.should_receive(:cp).with("spec/fixtures/recipe/file.rb", "./tmp/a_random_recipe/another_file.rb")
|
30
35
|
|
31
|
-
|
36
|
+
recipe.execute do
|
37
|
+
copy_file("file.rb", :as => "another_file.rb")
|
38
|
+
end
|
32
39
|
end
|
33
40
|
|
34
41
|
it "if the dir doesn't exists, create it" do
|
35
|
-
|
36
|
-
|
37
|
-
FileUtils.should_receive(:
|
38
|
-
FileUtils.should_receive(:cp).with("spec/fixtures/recipe/file.rb", "spec/fixtures/ruby_app/my_awesome_dir/file.rb")
|
39
|
-
|
40
|
-
copy_file("file.rb", :to => "my_awesome_dir")
|
41
|
-
end
|
42
|
-
|
43
|
-
it "adds the operation to @operation array" do
|
44
|
-
FileUtils.should_receive(:cp).with("spec/fixtures/recipe/file.rb", "spec/fixtures/ruby_app/file.rb")
|
45
|
-
|
46
|
-
copy_file("file.rb")
|
42
|
+
File.should_receive(:directory?).with("./tmp/a_random_recipe/my_awesome_dir").and_return(false)
|
43
|
+
FileUtils.should_receive(:mkdir_p).with("./tmp/a_random_recipe/my_awesome_dir")
|
44
|
+
FileUtils.should_receive(:cp).with("spec/fixtures/recipe/file.rb", "./tmp/a_random_recipe/my_awesome_dir/file.rb")
|
47
45
|
|
48
|
-
|
46
|
+
recipe.execute do
|
47
|
+
copy_file("file.rb", :to => "my_awesome_dir")
|
48
|
+
end
|
49
49
|
end
|
50
50
|
end
|
51
51
|
|
52
52
|
describe ".run_tests" do
|
53
53
|
it "returns 0 if all tests pass" do
|
54
|
-
Dir.should_receive(:chdir).with("
|
54
|
+
Dir.should_receive(:chdir).with("./tmp/a_random_recipe").and_yield
|
55
55
|
|
56
56
|
test_output = <<-EOF
|
57
57
|
....
|
@@ -63,11 +63,13 @@ describe Reciper::Helpers do
|
|
63
63
|
io = double(:io, :read => test_output)
|
64
64
|
IO.should_receive(:popen).with("bundle exec rspec spec").and_yield(io)
|
65
65
|
|
66
|
-
|
66
|
+
recipe.execute do
|
67
|
+
run_tests.should == 0
|
68
|
+
end
|
67
69
|
end
|
68
70
|
|
69
71
|
it "returns 1 if there is only one failure" do
|
70
|
-
Dir.should_receive(:chdir).with("
|
72
|
+
Dir.should_receive(:chdir).with("./tmp/a_random_recipe").and_yield
|
71
73
|
|
72
74
|
test_output = <<-EOF
|
73
75
|
FE..
|
@@ -79,7 +81,9 @@ describe Reciper::Helpers do
|
|
79
81
|
io = double(:io, :read => test_output)
|
80
82
|
IO.should_receive(:popen).with("bundle exec rspec spec").and_yield(io)
|
81
83
|
|
82
|
-
|
84
|
+
recipe.execute do
|
85
|
+
run_tests.should == 2
|
86
|
+
end
|
83
87
|
end
|
84
88
|
end
|
85
89
|
|
@@ -87,7 +91,7 @@ describe Reciper::Helpers do
|
|
87
91
|
it "returns a hash with successful as true when the rake task has been run successfully" do
|
88
92
|
output = ""
|
89
93
|
|
90
|
-
Dir.should_receive(:chdir).with("
|
94
|
+
Dir.should_receive(:chdir).with("./tmp/a_random_recipe").and_yield
|
91
95
|
|
92
96
|
io = double(:io)
|
93
97
|
io.stub!(:read).and_return("")
|
@@ -97,10 +101,12 @@ describe Reciper::Helpers do
|
|
97
101
|
|
98
102
|
$?.should_receive(:exitstatus).and_return(0)
|
99
103
|
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
+
recipe.execute do
|
105
|
+
run_rake_task("puts_something").should == {
|
106
|
+
:response => "",
|
107
|
+
:successful => true
|
108
|
+
}
|
109
|
+
end
|
104
110
|
end
|
105
111
|
|
106
112
|
it "returns a hash with successful as false when the rake task hasn't been run successfully" do
|
@@ -109,16 +115,18 @@ describe Reciper::Helpers do
|
|
109
115
|
io = double(:io)
|
110
116
|
io.stub!(:read).and_return("")
|
111
117
|
|
112
|
-
Dir.should_receive(:chdir).with("
|
118
|
+
Dir.should_receive(:chdir).with("./tmp/a_random_recipe").and_yield
|
113
119
|
|
114
120
|
IO.should_receive(:popen).
|
115
121
|
with("bundle exec rake puts_something").and_yield(io)
|
116
122
|
$?.should_receive(:exitstatus).and_return(1)
|
117
123
|
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
124
|
+
recipe.execute do
|
125
|
+
run_rake_task("puts_something").should == {
|
126
|
+
:response => "",
|
127
|
+
:successful => false
|
128
|
+
}
|
129
|
+
end
|
122
130
|
end
|
123
131
|
end
|
124
132
|
|
@@ -136,20 +144,23 @@ c
|
|
136
144
|
f
|
137
145
|
EOF
|
138
146
|
|
139
|
-
Dir.should_receive(:glob).with("
|
140
|
-
and_return(["
|
147
|
+
Dir.should_receive(:glob).with("./tmp/a_random_recipe/README.md").
|
148
|
+
and_return(["./tmp/a_random_recipe/README.md"])
|
149
|
+
|
150
|
+
File.should_receive(:read).with("./tmp/a_random_recipe/README.md").
|
151
|
+
and_return(original)
|
141
152
|
|
142
153
|
File.should_receive(:read).with("spec/fixtures/recipe/README").
|
143
154
|
and_return(readme)
|
144
155
|
|
145
|
-
File.should_receive(:read).with("spec/fixtures/ruby_app/README.md").
|
146
|
-
and_return(original)
|
147
|
-
|
148
156
|
file = double(:file)
|
149
157
|
file.should_receive(:write).with("a\nb\nc\nd\ne\nf")
|
150
|
-
File.should_receive(:open).with("spec/fixtures/ruby_app/README.md", "w").and_yield(file)
|
151
158
|
|
152
|
-
|
159
|
+
recipe.execute do
|
160
|
+
File.should_receive(:open).with("./tmp/a_random_recipe/README.md", "w").and_yield(file)
|
161
|
+
|
162
|
+
copy_line_range("README", "README.md", :to_line => 3)
|
163
|
+
end
|
153
164
|
end
|
154
165
|
|
155
166
|
it "copies only specified lines" do
|
@@ -168,54 +179,23 @@ c
|
|
168
179
|
f
|
169
180
|
EOF
|
170
181
|
|
171
|
-
Dir.should_receive(:glob).with("
|
172
|
-
and_return(["
|
182
|
+
Dir.should_receive(:glob).with("./tmp/a_random_recipe/README.md").
|
183
|
+
and_return(["./tmp/a_random_recipe/README.md"])
|
173
184
|
|
174
185
|
File.should_receive(:read).with("spec/fixtures/recipe/README").
|
175
186
|
and_return(readme)
|
176
187
|
|
177
|
-
File.should_receive(:read).with("
|
188
|
+
File.should_receive(:read).with("./tmp/a_random_recipe/README.md").
|
178
189
|
and_return(original)
|
179
190
|
|
180
191
|
file = double(:file)
|
181
192
|
file.should_receive(:write).with("a\nb\nc\nd\ne\nf")
|
182
|
-
File.should_receive(:open).with("spec/fixtures/ruby_app/README.md", "w").and_yield(file)
|
183
|
-
|
184
|
-
copy_line_range("README", "README.md", :to_line => 3, :lines => (1..2))
|
185
|
-
end
|
186
|
-
|
187
|
-
it "adds an entry to operations" do
|
188
|
-
readme = <<-EOF
|
189
|
-
a
|
190
|
-
d
|
191
|
-
e
|
192
|
-
f
|
193
|
-
g
|
194
|
-
EOF
|
195
193
|
|
196
|
-
|
197
|
-
|
198
|
-
b
|
199
|
-
c
|
200
|
-
f
|
201
|
-
EOF
|
202
|
-
|
203
|
-
Dir.stub!(:glob).with("spec/fixtures/ruby_app/README.md").
|
204
|
-
and_return(["spec/fixtures/ruby_app/README.md"])
|
205
|
-
|
206
|
-
File.stub!(:read).with("spec/fixtures/recipe/README").
|
207
|
-
and_return(readme)
|
208
|
-
|
209
|
-
File.stub!(:read).with("spec/fixtures/ruby_app/README.md").
|
210
|
-
and_return(original)
|
194
|
+
recipe.execute do
|
195
|
+
File.should_receive(:open).with("./tmp/a_random_recipe/README.md", "w").and_yield(file)
|
211
196
|
|
212
|
-
|
213
|
-
|
214
|
-
File.stub!(:open).with("spec/fixtures/ruby_app/README.md", "w").and_yield(file)
|
215
|
-
|
216
|
-
copy_line_range("README", "README.md", :to_line => 3, :lines => (1..2))
|
217
|
-
|
218
|
-
@operations.should include([:copy_line_range, { :original_content => original, :original_file => "spec/fixtures/ruby_app/README.md"}])
|
197
|
+
copy_line_range("README", "README.md", :to_line => 3, :lines => (1..2))
|
198
|
+
end
|
219
199
|
end
|
220
200
|
|
221
201
|
context "suffix copy" do
|
@@ -223,31 +203,36 @@ EOF
|
|
223
203
|
readme = ""
|
224
204
|
original = ""
|
225
205
|
|
226
|
-
Dir.should_receive(:glob).with("
|
227
|
-
and_return(["
|
206
|
+
Dir.should_receive(:glob).with("./tmp/a_random_recipe/*.md").
|
207
|
+
and_return(["./tmp/a_random_recipe/README.md"])
|
228
208
|
|
229
209
|
File.stub!(:read).with("spec/fixtures/recipe/README").
|
230
210
|
and_return(readme)
|
231
211
|
|
232
|
-
File.should_receive(:read).with("
|
212
|
+
File.should_receive(:read).with("./tmp/a_random_recipe/README.md").
|
233
213
|
and_return(original)
|
234
214
|
|
235
215
|
file = double(:file)
|
236
216
|
file.stub!(:write)
|
237
|
-
File.stub!(:open).with("spec/fixtures/ruby_app/README.md", "w").and_yield(file)
|
238
217
|
|
239
|
-
|
218
|
+
recipe.execute do
|
219
|
+
File.stub!(:open).with("./tmp/a_random_recipe/README.md", "w").and_yield(file)
|
220
|
+
|
221
|
+
copy_line_range("README", "*.md", :to_line => 0)
|
222
|
+
end
|
240
223
|
end
|
241
224
|
|
242
225
|
it "raises an exception when given only the suffix of the file when there is more than one file" do
|
243
226
|
readme = ""
|
244
227
|
original = ""
|
245
228
|
|
246
|
-
Dir.should_receive(:glob).with("
|
229
|
+
Dir.should_receive(:glob).with("./tmp/a_random_recipe/*.md").
|
247
230
|
and_return(["spec/fixtures/ruby_app/README.md", "spec/fixtures/ruby_app/README2.md"])
|
248
231
|
|
249
232
|
lambda {
|
250
|
-
|
233
|
+
recipe.execute do
|
234
|
+
copy_line_range("README", "*.md", :to_line => 0)
|
235
|
+
end
|
251
236
|
}.should raise_error(Reciper::NoFileOrMultipleFilesFound)
|
252
237
|
end
|
253
238
|
end
|
@@ -255,7 +240,7 @@ EOF
|
|
255
240
|
|
256
241
|
describe ".run_command" do
|
257
242
|
it "runs a command on projects folder and returns the command hash with the response and true when successful" do
|
258
|
-
Dir.should_receive(:chdir).with("
|
243
|
+
Dir.should_receive(:chdir).with("./tmp/a_random_recipe").and_yield
|
259
244
|
|
260
245
|
output = <<EOF
|
261
246
|
a
|
@@ -270,14 +255,16 @@ EOF
|
|
270
255
|
IO.should_receive(:popen).with("ls").and_yield(io)
|
271
256
|
$?.should_receive(:exitstatus).and_return(0)
|
272
257
|
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
258
|
+
recipe.execute do
|
259
|
+
run_command("ls").should == {
|
260
|
+
:response => "a\nb\n",
|
261
|
+
:successful => true
|
262
|
+
}
|
263
|
+
end
|
277
264
|
end
|
278
265
|
|
279
266
|
it "runs a command on projects folder and returns the command hash with the response and false when not successful" do
|
280
|
-
Dir.should_receive(:chdir).with("
|
267
|
+
Dir.should_receive(:chdir).with("./tmp/a_random_recipe").and_yield
|
281
268
|
|
282
269
|
output = <<EOF
|
283
270
|
a
|
@@ -292,106 +279,36 @@ EOF
|
|
292
279
|
IO.should_receive(:popen).with("ls").and_yield(io)
|
293
280
|
$?.should_receive(:exitstatus).and_return(1)
|
294
281
|
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
it "receives the rollback command together with the command and store it on @operations array" do
|
302
|
-
run_command("ls", "ls -a")
|
303
|
-
|
304
|
-
@operations.should include([:run_command, { :rollback_command => "ls -a" }])
|
305
|
-
end
|
306
|
-
|
307
|
-
it "doesn't require the rollback command to be informed" do
|
308
|
-
run_command("ls")
|
309
|
-
|
310
|
-
@operations.should include([:run_command, { :rollback_command => nil}])
|
282
|
+
recipe.execute do
|
283
|
+
run_command("ls").should == {
|
284
|
+
:response => "a\nb\n",
|
285
|
+
:successful => false
|
286
|
+
}
|
287
|
+
end
|
311
288
|
end
|
312
289
|
end
|
313
290
|
|
314
291
|
describe ".override_file" do
|
315
292
|
it "overrides the file with another file" do
|
316
|
-
Dir.should_receive(:chdir).with(
|
293
|
+
Dir.should_receive(:chdir).with("./tmp/a_random_recipe").and_yield
|
317
294
|
File.should_receive(:exists?).with("README").and_return(true)
|
318
|
-
FileUtils.should_receive(:mkdir_p).with("/tmp/reciper")
|
319
|
-
|
320
|
-
FileUtils.should_receive(:cp).with("README", "/tmp/reciper/README")
|
321
295
|
FileUtils.should_receive(:cp).with("spec/fixtures/recipe/README",
|
322
|
-
"
|
296
|
+
"./tmp/a_random_recipe/README")
|
323
297
|
|
324
|
-
|
298
|
+
recipe.execute do
|
299
|
+
override_file("README", "README")
|
300
|
+
end
|
325
301
|
end
|
326
302
|
|
327
303
|
it "raises an error when file doesn't exists" do
|
328
|
-
Dir.stub!(:chdir).with(
|
304
|
+
Dir.stub!(:chdir).with("./tmp/a_random_recipe").and_yield
|
329
305
|
File.should_receive(:exists?).with("README").and_return(false)
|
330
306
|
|
331
307
|
lambda {
|
332
|
-
|
308
|
+
recipe.execute do
|
309
|
+
override_file("README", "README")
|
310
|
+
end
|
333
311
|
}.should raise_error(Reciper::NoFileToBeOverriden)
|
334
312
|
end
|
335
|
-
|
336
|
-
it "adds the operation to operations array" do
|
337
|
-
Dir.stub!(:chdir).with(@ruby_app_path).and_yield
|
338
|
-
File.stub!(:exists?).with("README").and_return(true)
|
339
|
-
FileUtils.stub!(:mkdir_p).with("/tmp/reciper")
|
340
|
-
|
341
|
-
FileUtils.stub!(:cp).with("README", "/tmp/reciper/README")
|
342
|
-
FileUtils.stub!(:cp).with("spec/fixtures/recipe/README",
|
343
|
-
"spec/fixtures/ruby_app/README")
|
344
|
-
|
345
|
-
override_file("README", "README")
|
346
|
-
@operations.should include([:override_file, { :tmp_file => "/tmp/reciper/README", :overriden_file => "README"}])
|
347
|
-
end
|
348
|
-
end
|
349
|
-
|
350
|
-
describe ".rollback" do
|
351
|
-
it "removes the file when the operation is copy_file" do
|
352
|
-
@operations = [[:copy_file, { :destination => "README" }]]
|
353
|
-
|
354
|
-
Dir.should_receive(:chdir).with("spec/fixtures/ruby_app").and_yield
|
355
|
-
|
356
|
-
FileUtils.should_receive(:rm).with("README")
|
357
|
-
|
358
|
-
rollback
|
359
|
-
end
|
360
|
-
|
361
|
-
it "restores the old file when the operation is copy_range" do
|
362
|
-
@operations = [[:copy_range, { :original_content => "Not OK", :original_file => "an_added_file.rb"}]]
|
363
|
-
|
364
|
-
file = double(:file)
|
365
|
-
file.should_receive(:write).with("Not OK")
|
366
|
-
File.should_receive(:open).with("an_added_file.rb", "w").and_yield(file)
|
367
|
-
|
368
|
-
rollback
|
369
|
-
end
|
370
|
-
|
371
|
-
it "runs the rollback command when the operation is run_command and we have a rollback command" do
|
372
|
-
@operations = [[:run_command, { :rollback_command => "ls"}]]
|
373
|
-
|
374
|
-
Dir.should_receive(:chdir).with("spec/fixtures/ruby_app").and_yield
|
375
|
-
|
376
|
-
output = ""
|
377
|
-
|
378
|
-
io = double(:io)
|
379
|
-
io.should_receive(:read) do
|
380
|
-
""
|
381
|
-
end
|
382
|
-
|
383
|
-
IO.should_receive(:popen).with("ls").and_yield(io)
|
384
|
-
$?.should_receive(:exitstatus).and_return(0)
|
385
|
-
|
386
|
-
rollback
|
387
|
-
end
|
388
|
-
|
389
|
-
it "runs the rollback command when the operation is override_file" do
|
390
|
-
@operations = [[:override_file, { :tmp_file => "/tmp/reciper/my_file.rb", :overriden_file => "ola.rb"}]]
|
391
|
-
|
392
|
-
FileUtils.should_receive(:cp).with("/tmp/reciper/my_file.rb", "spec/fixtures/ruby_app/ola.rb")
|
393
|
-
|
394
|
-
rollback
|
395
|
-
end
|
396
313
|
end
|
397
314
|
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Reciper do
|
4
|
+
describe "#initialize" do
|
5
|
+
before do
|
6
|
+
File.stub!(:directory?).and_return(false)
|
7
|
+
FileUtils.stub!(:cp_r)
|
8
|
+
FileUtils.stub!(:mkdir_p).with("tmp")
|
9
|
+
end
|
10
|
+
|
11
|
+
it "assigns the paths" do
|
12
|
+
reciper = described_class.new("Awesome recipe", "~/Code/source_path", "~/Code/rails_app")
|
13
|
+
|
14
|
+
reciper.ruby_app_path.should == "./tmp/awesome_recipe"
|
15
|
+
reciper.recipe_path.should == "~/Code/source_path"
|
16
|
+
end
|
17
|
+
|
18
|
+
it "removes the temp directory if it exists and copies a new version" do
|
19
|
+
File.should_receive(:directory?).
|
20
|
+
with("./tmp/awesome_recipe").and_return(true)
|
21
|
+
|
22
|
+
FileUtils.should_receive(:rm_rf).with("./tmp/awesome_recipe")
|
23
|
+
|
24
|
+
described_class.new("Awesome recipe", "~/Code/source_path", "~/Code/rails_app")
|
25
|
+
end
|
26
|
+
|
27
|
+
it "creates the temp directory" do
|
28
|
+
FileUtils.should_receive(:cp_r).with("~/Code/rails_app", "./tmp/awesome_recipe")
|
29
|
+
FileUtils.should_receive(:mkdir_p).with("tmp")
|
30
|
+
|
31
|
+
described_class.new("Awesome recipe", "~/Code/source_path", "~/Code/rails_app")
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
describe "#execute" do
|
36
|
+
it "run an instance eval with all paths" do
|
37
|
+
File.stub!(:directory?).and_return(false)
|
38
|
+
FileUtils.stub!(:cp_r)
|
39
|
+
FileUtils.stub!(:mkdir_p).with("tmp")
|
40
|
+
|
41
|
+
reciper = described_class.new("Awesome recipe", "~/Code/source_path", "~/Code/rails_app")
|
42
|
+
|
43
|
+
reciper.execute do
|
44
|
+
@ruby_app_path.should == "./tmp/awesome_recipe"
|
45
|
+
@recipe_path.should == "~/Code/source_path"
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
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.1
|
4
|
+
version: 0.2.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,8 +9,24 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-06-
|
13
|
-
dependencies:
|
12
|
+
date: 2012-06-12 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: activesupport
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - '='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 3.2.5
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - '='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 3.2.5
|
14
30
|
description: An awesome way to write recipes for a book chapter
|
15
31
|
email:
|
16
32
|
- mail@rodrigoflores.org
|
@@ -19,6 +35,8 @@ extensions: []
|
|
19
35
|
extra_rdoc_files: []
|
20
36
|
files:
|
21
37
|
- .gitignore
|
38
|
+
- .travis.yml
|
39
|
+
- Changelog.md
|
22
40
|
- Gemfile
|
23
41
|
- Gemfile.lock
|
24
42
|
- LICENSE
|
@@ -29,6 +47,7 @@ files:
|
|
29
47
|
- lib/reciper/version.rb
|
30
48
|
- reciper.gemspec
|
31
49
|
- spec/reciper/helpers_spec.rb
|
50
|
+
- spec/reciper/reciper_spec.rb
|
32
51
|
- spec/spec_helper.rb
|
33
52
|
homepage: http://github.com/rodrigoflores/reciper
|
34
53
|
licenses: []
|
@@ -44,7 +63,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
44
63
|
version: '0'
|
45
64
|
segments:
|
46
65
|
- 0
|
47
|
-
hash:
|
66
|
+
hash: 2404720825968194926
|
48
67
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
49
68
|
none: false
|
50
69
|
requirements:
|
@@ -53,7 +72,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
53
72
|
version: '0'
|
54
73
|
segments:
|
55
74
|
- 0
|
56
|
-
hash:
|
75
|
+
hash: 2404720825968194926
|
57
76
|
requirements: []
|
58
77
|
rubyforge_project:
|
59
78
|
rubygems_version: 1.8.23
|
@@ -62,4 +81,6 @@ specification_version: 3
|
|
62
81
|
summary: An awesome way to write recipes for a book chapter
|
63
82
|
test_files:
|
64
83
|
- spec/reciper/helpers_spec.rb
|
84
|
+
- spec/reciper/reciper_spec.rb
|
65
85
|
- spec/spec_helper.rb
|
86
|
+
has_rdoc:
|