wizard 0.0.1
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/.gitignore +22 -0
- data/CHANGELOG.md +5 -0
- data/README.md +0 -0
- data/Rakefile +44 -0
- data/VERSION +1 -0
- data/lib/wizard.rb +12 -0
- data/lib/wizard/formula.rb +23 -0
- data/lib/wizard/helpers.rb +63 -0
- data/lib/wizard/spells.rb +12 -0
- data/lib/wizard/spells/base.rb +84 -0
- data/lib/wizard/spells/compile_template.rb +27 -0
- data/lib/wizard/spells/execute_shell.rb +22 -0
- data/lib/wizard/spells/make_dir.rb +47 -0
- data/lib/wizard/spells/make_file.rb +69 -0
- data/lib/wizard/spells/update_file.rb +95 -0
- data/spec/helpers_spec.rb +55 -0
- data/spec/spec_helper.rb +71 -0
- data/spec/spells/compile_template_spec.rb +60 -0
- data/spec/spells/execute_shell_spec.rb +58 -0
- data/spec/spells/make_dir_spec.rb +77 -0
- data/spec/spells/make_file_spec.rb +125 -0
- data/spec/spells/update_file_spec.rb +209 -0
- data/spec/spells_spec.rb +142 -0
- metadata +125 -0
@@ -0,0 +1,209 @@
|
|
1
|
+
require File.expand_path("../../spec_helper", __FILE__)
|
2
|
+
|
3
|
+
describe Wizard::Spells::UpdateFile do
|
4
|
+
subject do
|
5
|
+
Wizard::Spells::UpdateFile
|
6
|
+
end
|
7
|
+
|
8
|
+
describe "#initialize" do
|
9
|
+
it "should set given filename" do
|
10
|
+
subject.new("/path/to/file").filename.should == "/path/to/file"
|
11
|
+
end
|
12
|
+
|
13
|
+
context "given content" do
|
14
|
+
it "should be set" do
|
15
|
+
subject.new("/path/to/file", "hello world!").content.should == "hello world!"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should set default chmod" do
|
20
|
+
subject.new("/path/to/file").chmod.should == 644
|
21
|
+
end
|
22
|
+
|
23
|
+
context "given :mode option" do
|
24
|
+
it "should set it" do
|
25
|
+
subject.new("/path/to/file", nil, :mode => 755).chmod.should == 755
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
context "given :force option" do
|
30
|
+
it "should run in force mode" do
|
31
|
+
subject.new("/path/to/file", nil, :force => true).should be_forced
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
context "given :before option" do
|
36
|
+
it "should set it" do
|
37
|
+
subject.new("/path/to/file", nil, :before => /test/).before.should == /test/
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
context "given :after option" do
|
42
|
+
it "should set it" do
|
43
|
+
subject.new("/path/to/file", nil, :after => /test/).after.should == /test/
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
context "given :replace option" do
|
48
|
+
it "should set it" do
|
49
|
+
subject.new("/path/to/file", nil, :replace => /test/).replace.should == /test/
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
describe "#perform" do
|
55
|
+
context "when specified file doesn't exist" do
|
56
|
+
context "and given content only" do
|
57
|
+
subject do
|
58
|
+
Wizard::Spells::UpdateFile.new("/path/to/file", "testing")
|
59
|
+
end
|
60
|
+
|
61
|
+
it "should create this file" do
|
62
|
+
spell = subject
|
63
|
+
File.expects(:exist?).with("/path/to/file").returns(false)
|
64
|
+
spell.expects(:perform_without_content_update).returns(:created)
|
65
|
+
spell.perform.should == :created
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
context "and given :before option" do
|
70
|
+
subject do
|
71
|
+
Wizard::Spells::UpdateFile.new("/path/to/file", "testing", :before => /test/)
|
72
|
+
end
|
73
|
+
|
74
|
+
it "should create this file" do
|
75
|
+
spell = subject
|
76
|
+
File.expects(:exist?).with("/path/to/file").returns(false)
|
77
|
+
spell.perform.should == :missing
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
context "and given :after option" do
|
82
|
+
subject do
|
83
|
+
Wizard::Spells::UpdateFile.new("/path/to/file", "testing", :after => /test/)
|
84
|
+
end
|
85
|
+
|
86
|
+
it "should create this file" do
|
87
|
+
spell = subject
|
88
|
+
File.expects(:exist?).with("/path/to/file").returns(false)
|
89
|
+
spell.perform.should == :missing
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
context "and given :replace option" do
|
94
|
+
subject do
|
95
|
+
Wizard::Spells::UpdateFile.new("/path/to/file", "testing", :replace => /test/)
|
96
|
+
end
|
97
|
+
|
98
|
+
it "should create this file" do
|
99
|
+
spell = subject
|
100
|
+
File.expects(:exist?).with("/path/to/file").returns(false)
|
101
|
+
spell.perform.should == :missing
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
context "when some error has been raised" do
|
107
|
+
subject do
|
108
|
+
Wizard::Spells::UpdateFile.new("/path/to/file", "testing")
|
109
|
+
end
|
110
|
+
|
111
|
+
it "should set :error status" do
|
112
|
+
spell = subject
|
113
|
+
File.expects(:exist?).with("/path/to/file").raises(Exception)
|
114
|
+
spell.perform.should == :error
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
context "when specified file exists" do
|
119
|
+
context "and given content only" do
|
120
|
+
subject do
|
121
|
+
Wizard::Spells::UpdateFile.new("/path/to/file", "testing")
|
122
|
+
end
|
123
|
+
|
124
|
+
it "should replace file content" do
|
125
|
+
spell = subject
|
126
|
+
File.expects(:exist?).with("/path/to/file").returns(true)
|
127
|
+
spell.expects(:perform_without_content_update).returns(:updated)
|
128
|
+
spell.perform.should == :updated
|
129
|
+
spell.content.should == "testing"
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
context "and given :replace option" do
|
134
|
+
subject do
|
135
|
+
Wizard::Spells::UpdateFile.new("/path/to/file", "Sparta", :replace => /persia/i)
|
136
|
+
end
|
137
|
+
|
138
|
+
it "should replace file content" do
|
139
|
+
spell = subject
|
140
|
+
File.expects(:exist?).with("/path/to/file").returns(true)
|
141
|
+
File.expects(:read).with("/path/to/file").returns("This is Persia!")
|
142
|
+
spell.expects(:perform_without_content_update).returns(:updated)
|
143
|
+
spell.perform.should == :updated
|
144
|
+
spell.content.should == "This is Sparta!"
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
context "and given :after option" do
|
149
|
+
subject do
|
150
|
+
Wizard::Spells::UpdateFile.new("/path/to/file", "not", :after => /^is$/i)
|
151
|
+
end
|
152
|
+
|
153
|
+
it "should put given content after matching line" do
|
154
|
+
spell = subject
|
155
|
+
File.expects(:exist?).with("/path/to/file").returns(true)
|
156
|
+
File.expects(:read).with("/path/to/file").returns("This\nis\nPersia!")
|
157
|
+
spell.expects(:perform_without_content_update).returns(:updated)
|
158
|
+
spell.perform.should == :updated
|
159
|
+
spell.content.should == "This\nis\nnot\nPersia!"
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
163
|
+
context "and given :after is :BOF" do
|
164
|
+
subject do
|
165
|
+
Wizard::Spells::UpdateFile.new("/path/to/file", "This", :after => :BOF)
|
166
|
+
end
|
167
|
+
|
168
|
+
it "should put given content at the begining of file" do
|
169
|
+
spell = subject
|
170
|
+
File.expects(:exist?).with("/path/to/file").returns(true)
|
171
|
+
File.expects(:read).with("/path/to/file").returns("is\nSparta!")
|
172
|
+
spell.expects(:perform_without_content_update).returns(:updated)
|
173
|
+
spell.perform.should == :updated
|
174
|
+
spell.content.should == "This\nis\nSparta!"
|
175
|
+
end
|
176
|
+
end
|
177
|
+
|
178
|
+
context "and given :before option" do
|
179
|
+
subject do
|
180
|
+
Wizard::Spells::UpdateFile.new("/path/to/file", "not", :before => /^persia/i)
|
181
|
+
end
|
182
|
+
|
183
|
+
it "should put given content before matching line" do
|
184
|
+
spell = subject
|
185
|
+
File.expects(:exist?).with("/path/to/file").returns(true)
|
186
|
+
File.expects(:read).with("/path/to/file").returns("This\nis\nPersia!")
|
187
|
+
spell.expects(:perform_without_content_update).returns(:updated)
|
188
|
+
spell.perform.should == :updated
|
189
|
+
spell.content.should == "This\nis\nnot\nPersia!"
|
190
|
+
end
|
191
|
+
end
|
192
|
+
|
193
|
+
context "and given :before is :EOF" do
|
194
|
+
subject do
|
195
|
+
Wizard::Spells::UpdateFile.new("/path/to/file", "Sparta!", :before => :EOF)
|
196
|
+
end
|
197
|
+
|
198
|
+
it "should put given content at the end of file" do
|
199
|
+
spell = subject
|
200
|
+
File.expects(:exist?).with("/path/to/file").returns(true)
|
201
|
+
File.expects(:read).with("/path/to/file").returns("This\nis")
|
202
|
+
spell.expects(:perform_without_content_update).returns(:updated)
|
203
|
+
spell.perform.should == :updated
|
204
|
+
spell.content.should == "This\nis\nSparta!"
|
205
|
+
end
|
206
|
+
end
|
207
|
+
end
|
208
|
+
end
|
209
|
+
end
|
data/spec/spells_spec.rb
ADDED
@@ -0,0 +1,142 @@
|
|
1
|
+
require File.expand_path("../spec_helper", __FILE__)
|
2
|
+
|
3
|
+
describe Wizard::Spells do
|
4
|
+
|
5
|
+
end
|
6
|
+
|
7
|
+
describe Wizard::Spells::Base do
|
8
|
+
subject do
|
9
|
+
Wizard::Spells::Base
|
10
|
+
end
|
11
|
+
|
12
|
+
describe ".all_forced?" do
|
13
|
+
it "should return false by default" do
|
14
|
+
subject.should_not be_all_forced
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe ".force_all!" do
|
19
|
+
it "should set force mode for all Spells" do
|
20
|
+
subject.force_all!
|
21
|
+
subject.should be_all_forced
|
22
|
+
end
|
23
|
+
|
24
|
+
after do
|
25
|
+
subject.send(:class_variable_set, "@@force_all", false)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
describe "#force!" do
|
30
|
+
it "should set force mode for current action" do
|
31
|
+
base = subject.new
|
32
|
+
base.force!
|
33
|
+
base.instance_variable_get("@force").should == true
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
describe "#force?" do
|
38
|
+
context "when local force mode is enabled" do
|
39
|
+
context "and global disabled" do
|
40
|
+
it "should return true" do
|
41
|
+
base = subject.new
|
42
|
+
base.force!
|
43
|
+
base.should be_forced
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
context "when local force mode is disabled" do
|
49
|
+
context "and global disabled" do
|
50
|
+
it "should return false" do
|
51
|
+
base = subject.new
|
52
|
+
base.should_not be_forced
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
context "and global enabled" do
|
57
|
+
it "should return true" do
|
58
|
+
base = subject.new
|
59
|
+
base.force_all!
|
60
|
+
base.should be_forced
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
after do
|
65
|
+
subject.send(:class_variable_set, "@@force_all", false)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
describe "#status" do
|
71
|
+
it "should be nil by default" do
|
72
|
+
subject.new.status.should == nil
|
73
|
+
end
|
74
|
+
|
75
|
+
it "should return actual status" do
|
76
|
+
base = subject.new
|
77
|
+
base.instance_variable_set("@status", :test)
|
78
|
+
base.status.should == :test
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
it "#status! should set actual status" do
|
83
|
+
base = subject.new
|
84
|
+
base.send(:status!, :test)
|
85
|
+
base.status.should == :test
|
86
|
+
end
|
87
|
+
|
88
|
+
describe "#status?" do
|
89
|
+
before do
|
90
|
+
@base = subject.new
|
91
|
+
@base.send(:status!, :test)
|
92
|
+
end
|
93
|
+
|
94
|
+
it "should return true when given status is the same as actual" do
|
95
|
+
@base.should be_status(:test)
|
96
|
+
end
|
97
|
+
|
98
|
+
it "should return false when given status is different than actual" do
|
99
|
+
@base.should_not be_status(:invalid)
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
describe ".attr_status" do
|
104
|
+
before do
|
105
|
+
klass = Class.new(subject)
|
106
|
+
klass.attr_status :testing
|
107
|
+
@test = klass.new
|
108
|
+
end
|
109
|
+
|
110
|
+
it "should define shortcut for setting given status" do
|
111
|
+
@test.should respond_to(:testing!)
|
112
|
+
end
|
113
|
+
|
114
|
+
it "should define shortcut for checking given status" do
|
115
|
+
@test.should respond_to(:testing?)
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
describe "shortcuts created by .status" do
|
120
|
+
before do
|
121
|
+
klass = Class.new(subject)
|
122
|
+
klass.attr_status :testing
|
123
|
+
@test = klass.new
|
124
|
+
end
|
125
|
+
|
126
|
+
context "for setting status" do
|
127
|
+
it "should work properly" do
|
128
|
+
@test.send :testing!
|
129
|
+
@test.should be_status(:testing)
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
context "for checking status" do
|
134
|
+
it "should work properly" do
|
135
|
+
@test.send :testing!
|
136
|
+
@test.should be_testing
|
137
|
+
@test.send :status!, :another
|
138
|
+
@test.should_not be_testing
|
139
|
+
end
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
metadata
ADDED
@@ -0,0 +1,125 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: wizard
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 29
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 0.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Kriss 'nu7hatch' Kowalik
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2010-10-31 00:00:00 +02:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: rspec
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 3
|
30
|
+
segments:
|
31
|
+
- 2
|
32
|
+
- 0
|
33
|
+
version: "2.0"
|
34
|
+
type: :development
|
35
|
+
version_requirements: *id001
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: mocha
|
38
|
+
prerelease: false
|
39
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
40
|
+
none: false
|
41
|
+
requirements:
|
42
|
+
- - ~>
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
hash: 25
|
45
|
+
segments:
|
46
|
+
- 0
|
47
|
+
- 9
|
48
|
+
version: "0.9"
|
49
|
+
type: :development
|
50
|
+
version_requirements: *id002
|
51
|
+
description: " Projects generator...\n"
|
52
|
+
email: chris@nu7hat.ch
|
53
|
+
executables: []
|
54
|
+
|
55
|
+
extensions: []
|
56
|
+
|
57
|
+
extra_rdoc_files:
|
58
|
+
- README.md
|
59
|
+
files:
|
60
|
+
- .gitignore
|
61
|
+
- CHANGELOG.md
|
62
|
+
- README.md
|
63
|
+
- Rakefile
|
64
|
+
- VERSION
|
65
|
+
- lib/wizard.rb
|
66
|
+
- lib/wizard/formula.rb
|
67
|
+
- lib/wizard/helpers.rb
|
68
|
+
- lib/wizard/spells.rb
|
69
|
+
- lib/wizard/spells/base.rb
|
70
|
+
- lib/wizard/spells/compile_template.rb
|
71
|
+
- lib/wizard/spells/execute_shell.rb
|
72
|
+
- lib/wizard/spells/make_dir.rb
|
73
|
+
- lib/wizard/spells/make_file.rb
|
74
|
+
- lib/wizard/spells/update_file.rb
|
75
|
+
- spec/helpers_spec.rb
|
76
|
+
- spec/spec_helper.rb
|
77
|
+
- spec/spells/compile_template_spec.rb
|
78
|
+
- spec/spells/execute_shell_spec.rb
|
79
|
+
- spec/spells/make_dir_spec.rb
|
80
|
+
- spec/spells/make_file_spec.rb
|
81
|
+
- spec/spells/update_file_spec.rb
|
82
|
+
- spec/spells_spec.rb
|
83
|
+
has_rdoc: true
|
84
|
+
homepage: http://github.com/nu7hatch/wizard
|
85
|
+
licenses: []
|
86
|
+
|
87
|
+
post_install_message:
|
88
|
+
rdoc_options:
|
89
|
+
- --charset=UTF-8
|
90
|
+
require_paths:
|
91
|
+
- lib
|
92
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
93
|
+
none: false
|
94
|
+
requirements:
|
95
|
+
- - ">="
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
hash: 3
|
98
|
+
segments:
|
99
|
+
- 0
|
100
|
+
version: "0"
|
101
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
102
|
+
none: false
|
103
|
+
requirements:
|
104
|
+
- - ">="
|
105
|
+
- !ruby/object:Gem::Version
|
106
|
+
hash: 3
|
107
|
+
segments:
|
108
|
+
- 0
|
109
|
+
version: "0"
|
110
|
+
requirements: []
|
111
|
+
|
112
|
+
rubyforge_project:
|
113
|
+
rubygems_version: 1.3.7
|
114
|
+
signing_key:
|
115
|
+
specification_version: 3
|
116
|
+
summary: Projects generator and recipes compiler.
|
117
|
+
test_files:
|
118
|
+
- spec/helpers_spec.rb
|
119
|
+
- spec/spec_helper.rb
|
120
|
+
- spec/spells/make_file_spec.rb
|
121
|
+
- spec/spells/compile_template_spec.rb
|
122
|
+
- spec/spells/execute_shell_spec.rb
|
123
|
+
- spec/spells/make_dir_spec.rb
|
124
|
+
- spec/spells/update_file_spec.rb
|
125
|
+
- spec/spells_spec.rb
|