rapid-core 0.1 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/Gemfile.lock +35 -2
- data/Rakefile +77 -48
- data/doc/server.txt +15 -0
- data/features/settings/double-nested/default.feature +2 -2
- data/features/settings/double-nested/validates/presence_of.feature +1 -1
- data/features/settings/nested/default.feature +1 -1
- data/features/settings/nested/validates/presence_of.feature +1 -1
- data/features/settings/not_found.feature +2 -2
- data/features/step_definitions/settings_steps.rb +7 -3
- data/features/step_definitions/template_steps.rb +3 -1
- data/lib/rapid/check.rb +30 -23
- data/lib/rapid/core.rb +12 -0
- data/lib/rapid/error.rb +1 -0
- data/lib/rapid/module.rb +10 -1
- data/lib/rapid/railtie.rb +6 -0
- data/lib/rapid/setting/base.rb +31 -8
- data/lib/rapid/setting/boolean_setting.rb +20 -1
- data/lib/rapid/setting/definer.rb +11 -47
- data/lib/rapid/setting/integer_setting.rb +7 -7
- data/lib/rapid/setting/module.rb +56 -0
- data/lib/rapid/setting/namespace/base.rb +35 -60
- data/lib/rapid/setting/namespace/instance.rb +195 -28
- data/lib/rapid/setting/string_setting.rb +7 -1
- data/lib/rapid/settings.rb +51 -65
- data/lib/rapid/skeleton/base.rb +39 -18
- data/lib/rapid/skeleton/helpers/directory.rb +5 -6
- data/lib/rapid/skeleton/helpers/files.rb +62 -0
- data/lib/rapid/skeleton/helpers/gem.rb +43 -32
- data/lib/rapid/skeleton/helpers/if_setting.rb +44 -0
- data/lib/rapid/skeleton/helpers/migration.rb +102 -32
- data/lib/rapid/skeleton/helpers/route.rb +8 -12
- data/lib/rapid/skeleton/helpers/script.rb +1 -2
- data/lib/rapid/skeleton/helpers/template.rb +23 -25
- data/lib/rapid/skeleton/helpers/view.rb +7 -7
- data/lib/rapid/spec/template.rb +1 -1
- data/lib/rapid/version.rb +1 -1
- data/lib/rapid/web/base.rb +35 -0
- data/lib/rapid/web/bootstrap.rb +98 -0
- data/lib/rapid/web/controller_helpers.rb +60 -0
- data/lib/rapid/web/navigator.rb +18 -0
- data/lib/rapid/web/select_helpers.rb +63 -0
- data/lib/rapid/web/settings_form_builder.rb +205 -0
- data/lib/rapid/web/static_helpers.rb +28 -0
- data/lib/rapid/web/tasks.rb +10 -0
- data/public/rapid/core/bootstrap-collapse.js +136 -0
- data/public/rapid/core/bootstrap-responsive.min.css +3 -0
- data/public/rapid/core/bootstrap.min.css +556 -0
- data/public/rapid/core/jquery-1.7.1.js +9253 -0
- data/public/rapid/core/prettify.css +30 -0
- data/public/rapid/core/prettify.js +28 -0
- data/rapid-core.gemspec +5 -0
- data/spec/rapid/check_spec.rb +11 -4
- data/spec/rapid/module_spec.rb +18 -0
- data/spec/rapid/setting/base_spec.rb +71 -0
- data/spec/rapid/setting/boolean_setting_spec.rb +95 -0
- data/spec/rapid/setting/definer_spec.rb +7 -13
- data/spec/rapid/setting/integer_setting_spec.rb +49 -0
- data/spec/rapid/setting/module_spec.rb +25 -0
- data/spec/rapid/setting/namespace/base_spec.rb +88 -54
- data/spec/rapid/setting/namespace/instance_spec.rb +308 -5
- data/spec/rapid/setting/string_setting_spec.rb +43 -0
- data/spec/rapid/settings_spec.rb +65 -17
- data/spec/rapid/skeleton/base_spec.rb +113 -7
- data/spec/rapid/skeleton/helpers/directory_spec.rb +8 -6
- data/spec/rapid/skeleton/helpers/files_spec.rb +93 -0
- data/spec/rapid/skeleton/helpers/gem_spec.rb +65 -36
- data/spec/rapid/skeleton/helpers/if_setting_spec.rb +110 -0
- data/spec/rapid/skeleton/helpers/migration_spec.rb +190 -1
- data/spec/rapid/skeleton/helpers/route_spec.rb +13 -12
- data/spec/rapid/skeleton/helpers/script_spec.rb +2 -1
- data/spec/rapid/skeleton/helpers/template_spec.rb +22 -35
- data/spec/rapid/spec/template_spec.rb +1 -1
- data/spec/rapid/web/base_spec.rb +33 -0
- data/spec/rapid/web/bootstrap_spec.rb +72 -0
- data/spec/rapid/web/controller_helpers_spec.rb +86 -0
- data/spec/rapid/web/navigator_spec.rb +17 -0
- data/spec/rapid/web/select_helpers_spec.rb +71 -0
- data/spec/rapid/web/settings_form_builder_spec.rb +255 -0
- data/spec/rapid/web/static_helpers_spec.rb +26 -0
- data/spec/spec_helper.rb +3 -0
- data/views/index.erb +11 -0
- data/views/layout.erb +9 -0
- metadata +107 -12
- data/lib/rapid.rb +0 -37
- data/lib/rapid/setting/class_hash.rb +0 -34
- data/lib/rapid/setting/instance_hash.rb +0 -132
- data/lib/rapid/setting/instance_root.rb +0 -107
- data/spec/rapid/setting/instance_root_spec.rb +0 -161
@@ -55,7 +55,7 @@ describe Rapid::Skeleton::Base do
|
|
55
55
|
|
56
56
|
it "should accept a hash and load the settings with it" do
|
57
57
|
@settings = mock('settings')
|
58
|
-
@settings.should_receive(:
|
58
|
+
@settings.should_receive(:load).with(:foo => "bar")
|
59
59
|
|
60
60
|
@skeleton = Rapid::Skeleton::Base.new @settings
|
61
61
|
@skeleton.settings = {:foo => "bar"}
|
@@ -63,6 +63,35 @@ describe Rapid::Skeleton::Base do
|
|
63
63
|
|
64
64
|
end
|
65
65
|
|
66
|
+
describe "check" do
|
67
|
+
|
68
|
+
before do
|
69
|
+
@check = Rapid::Check.new ""
|
70
|
+
Rapid::Check.current = @check
|
71
|
+
|
72
|
+
@skeleton = Rapid::Skeleton::Base.new
|
73
|
+
end
|
74
|
+
|
75
|
+
it "should accept a check from options" do
|
76
|
+
@check2 = Rapid::Check.new ""
|
77
|
+
|
78
|
+
@skeleton = Rapid::Skeleton::Base.new nil, :check => @check2
|
79
|
+
@skeleton.check.should == @check2
|
80
|
+
end
|
81
|
+
|
82
|
+
it "should use the current check" do
|
83
|
+
@skeleton = Rapid::Skeleton::Base.new nil
|
84
|
+
@skeleton.check.should == Rapid::Check.current
|
85
|
+
end
|
86
|
+
|
87
|
+
it "should build a check" do
|
88
|
+
Rapid::Check.current = nil
|
89
|
+
@skeleton = Rapid::Skeleton::Base.new nil, :console => true
|
90
|
+
@skeleton.check.console.should == true
|
91
|
+
end
|
92
|
+
|
93
|
+
end
|
94
|
+
|
66
95
|
describe "push" do
|
67
96
|
|
68
97
|
it "should know whether it's pushing" do
|
@@ -71,6 +100,16 @@ describe Rapid::Skeleton::Base do
|
|
71
100
|
@skeleton.send(:pushing?).should == false
|
72
101
|
end
|
73
102
|
|
103
|
+
it "should accept settings as a parameter" do
|
104
|
+
@settings = mock('settings', :valid? => true)
|
105
|
+
@settings.should_receive(:load, :foo => 'bar')
|
106
|
+
|
107
|
+
@skeleton = Rapid::Skeleton::Base.new @settings
|
108
|
+
@skeleton.should_receive(:bones)
|
109
|
+
|
110
|
+
@skeleton.push :foo => 'bar'
|
111
|
+
end
|
112
|
+
|
74
113
|
it "should raise a not implemented error" do
|
75
114
|
@skeleton = Rapid::Skeleton::Base.new
|
76
115
|
lambda { @skeleton.push }.should raise_error(NotImplementedError)
|
@@ -95,6 +134,16 @@ describe Rapid::Skeleton::Base do
|
|
95
134
|
@skeleton.push!
|
96
135
|
end
|
97
136
|
|
137
|
+
it "should accept settings as a parameter" do
|
138
|
+
@settings = mock('settings', :valid? => true)
|
139
|
+
@settings.should_receive(:load, :foo => 'bar')
|
140
|
+
|
141
|
+
@skeleton = Rapid::Skeleton::Base.new @settings
|
142
|
+
@skeleton.should_receive(:bones)
|
143
|
+
|
144
|
+
@skeleton.push! :foo => 'bar'
|
145
|
+
end
|
146
|
+
|
98
147
|
end
|
99
148
|
|
100
149
|
describe "pull" do
|
@@ -119,11 +168,73 @@ describe Rapid::Skeleton::Base do
|
|
119
168
|
|
120
169
|
it "should return false if it does not encounter an error" do
|
121
170
|
@skeleton = Rapid::Skeleton::Base.new
|
122
|
-
|
171
|
+
@skeleton.check.should_receive(:encounters_error?).and_return(true)
|
123
172
|
|
124
173
|
@skeleton.pull.should == false
|
125
174
|
end
|
126
175
|
|
176
|
+
it "should log values" do
|
177
|
+
@settings = mock('settings')
|
178
|
+
@settings.should_receive(:[]=).with('foo', 'bar')
|
179
|
+
@skeleton = Rapid::Skeleton::Base.new @settings
|
180
|
+
|
181
|
+
@skeleton.check.should_receive(:log_value).with(:info, "foo", "bar")
|
182
|
+
@skeleton["foo"] = "bar"
|
183
|
+
end
|
184
|
+
|
185
|
+
it "should warn when setting to a different value during a pull" do
|
186
|
+
@settings = {'foo' => 'bar'}
|
187
|
+
@skeleton = Rapid::Skeleton::Base.new @settings
|
188
|
+
|
189
|
+
@skeleton.check.should_receive(:log_value).with(:warning, 'foo', 'baz')
|
190
|
+
@skeleton.instance_variable_set(:@pulled_settings, ['foo'])
|
191
|
+
|
192
|
+
@skeleton['foo'] = 'baz'
|
193
|
+
end
|
194
|
+
|
195
|
+
it "should just log when a boolean setting from true to 'true'" do
|
196
|
+
@settings = mock('settings')
|
197
|
+
@settings.should_receive(:[]).with('foo').twice.and_return(true)
|
198
|
+
@settings.should_receive(:[]=).with('foo', 'true')
|
199
|
+
|
200
|
+
@skeleton = Rapid::Skeleton::Base.new @settings
|
201
|
+
|
202
|
+
@skeleton.check.should_receive(:log_value).with(:info, 'foo', 'true')
|
203
|
+
@skeleton.instance_variable_set(:@pulled_settings, ['foo'])
|
204
|
+
|
205
|
+
@skeleton['foo'] = 'true'
|
206
|
+
end
|
207
|
+
|
208
|
+
it "should log a warning when a namespace previously turned off is set to on" do
|
209
|
+
@ns = mock('namespace', :namespaces => [], :scalars => [])
|
210
|
+
@namespace = Rapid::Setting::Namespace::Instance.new @ns, @parent
|
211
|
+
|
212
|
+
@settings = mock('settings')
|
213
|
+
@settings.should_receive(:[]).with('foo').twice.and_return(@namespace)
|
214
|
+
@settings.should_receive(:[]=).with('foo', 'true')
|
215
|
+
|
216
|
+
# goes from on to off
|
217
|
+
@namespace.should_receive(:on?).and_return(true)
|
218
|
+
@namespace.should_receive(:on?).and_return(false)
|
219
|
+
|
220
|
+
@skeleton = Rapid::Skeleton::Base.new @settings
|
221
|
+
|
222
|
+
@skeleton.check.should_receive(:log_value).with(:warning, 'foo', 'true')
|
223
|
+
@skeleton.instance_variable_set(:@pulled_settings, ['foo'])
|
224
|
+
|
225
|
+
@skeleton['foo'] = 'true'
|
226
|
+
end
|
227
|
+
|
228
|
+
it "should just log info when setting it to the same value" do
|
229
|
+
@settings = {'foo' => 'bar'}
|
230
|
+
@skeleton = Rapid::Skeleton::Base.new @settings
|
231
|
+
|
232
|
+
@skeleton.check.should_receive(:log_value).with(:info, 'foo', 'bar')
|
233
|
+
@skeleton.instance_variable_set(:@pulled_settings, ['foo'])
|
234
|
+
|
235
|
+
@skeleton['foo'] = 'bar'
|
236
|
+
end
|
237
|
+
|
127
238
|
end
|
128
239
|
|
129
240
|
describe "pull!" do
|
@@ -157,11 +268,6 @@ describe Rapid::Skeleton::Base do
|
|
157
268
|
Rapid::Check.current = nil
|
158
269
|
end
|
159
270
|
|
160
|
-
it "should raise an error if Rapid::Check.current is nil" do
|
161
|
-
Rapid::Check.current = nil
|
162
|
-
lambda { @skeleton.send(:ok, 'foo', 'bar') }.should raise_error
|
163
|
-
end
|
164
|
-
|
165
271
|
it "should delegate ok to Rapid::Check.current" do
|
166
272
|
@check.should_receive(:ok).with('foo', 'bar')
|
167
273
|
@skeleton.send(:ok, 'foo', 'bar')
|
@@ -5,6 +5,8 @@ describe Rapid::Skeleton::Helpers::Directory do
|
|
5
5
|
before do
|
6
6
|
Object.class_eval do
|
7
7
|
class MyClass
|
8
|
+
include Rapid::Skeleton::Helpers::IfSetting
|
9
|
+
include Rapid::Skeleton::Helpers::Files
|
8
10
|
include Rapid::Skeleton::Helpers::Directory
|
9
11
|
|
10
12
|
attr_accessor :templates_path, :project_path, :get_binding
|
@@ -32,17 +34,17 @@ describe Rapid::Skeleton::Helpers::Directory do
|
|
32
34
|
@instance.send :directory, 'foo/bar'
|
33
35
|
end
|
34
36
|
|
35
|
-
it "
|
36
|
-
|
37
|
+
it "should push the directory if the setting is true" do
|
38
|
+
@instance.should_receive(:make_project_directory).with('foo/bar')
|
37
39
|
|
38
|
-
@instance.should_receive(:set?).with('foo').and_return(
|
40
|
+
@instance.should_receive(:set?).with('foo').and_return(true)
|
39
41
|
@instance.send :directory, 'foo/bar', :if => 'foo'
|
40
42
|
end
|
41
43
|
|
42
|
-
it "should
|
43
|
-
|
44
|
+
it "should delete the directory if setting is false" do
|
45
|
+
@instance.should_receive(:delete_project_directory).with('foo/bar')
|
44
46
|
|
45
|
-
@instance.should_receive(:set?).with('foo').and_return(
|
47
|
+
@instance.should_receive(:set?).with('foo').and_return(false)
|
46
48
|
@instance.send :directory, 'foo/bar', :if => 'foo'
|
47
49
|
end
|
48
50
|
|
@@ -0,0 +1,93 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper')
|
2
|
+
|
3
|
+
describe Rapid::Skeleton::Helpers::Files do
|
4
|
+
|
5
|
+
before do
|
6
|
+
Object.class_eval do
|
7
|
+
class MyClass
|
8
|
+
include Rapid::Skeleton::Helpers::Files
|
9
|
+
|
10
|
+
attr_accessor :templates_path, :project_path
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
@instance = MyClass.new
|
15
|
+
@instance.templates_path = 'tmp/test/templates'
|
16
|
+
@instance.project_path = 'tmp/test/project'
|
17
|
+
|
18
|
+
FileUtils.mkdir_p @instance.templates_path
|
19
|
+
FileUtils.mkdir_p @instance.project_path
|
20
|
+
end
|
21
|
+
|
22
|
+
after do
|
23
|
+
Object.send(:remove_const, :MyClass) rescue nil
|
24
|
+
FileUtils.rm_rf 'tmp/test'
|
25
|
+
end
|
26
|
+
|
27
|
+
def create_file path, content
|
28
|
+
File.open(path, 'w') {|f| f.write content }
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should read a template file" do
|
32
|
+
create_file 'tmp/test/templates/foo.rb', 'foo'
|
33
|
+
@instance.send(:read_template_file, 'foo.rb').should == 'foo'
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should raise an error when reading a template file that doesn't exist" do
|
37
|
+
lambda { @instance.send(:read_template_file, 'foo.rb') }.should raise_error(Rapid::TemplateNotFoundError)
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should know if a project file exists" do
|
41
|
+
@instance.send(:project_file_exists?, "foo.rb").should == false
|
42
|
+
|
43
|
+
create_file 'tmp/test/project/foo.rb', 'hi'
|
44
|
+
@instance.send(:project_file_exists?, "foo.rb").should == true
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should make a project directory" do
|
48
|
+
FileUtils.should_receive(:mkdir_p).with('tmp/foo')
|
49
|
+
@instance.project_path = 'tmp'
|
50
|
+
@instance.send(:make_project_directory, "foo")
|
51
|
+
end
|
52
|
+
|
53
|
+
it "should delete a project directory" do
|
54
|
+
FileUtils.should_receive(:rm_rf).with('tmp/test')
|
55
|
+
FileUtils.should_receive(:rm_rf).with('tmp/foo')
|
56
|
+
@instance.project_path = 'tmp'
|
57
|
+
@instance.send(:delete_project_directory, "foo")
|
58
|
+
end
|
59
|
+
|
60
|
+
it "should read a project file" do
|
61
|
+
create_file 'tmp/test/project/foo.rb', 'hi'
|
62
|
+
@instance.send(:read_project_file, "foo.rb").should == 'hi'
|
63
|
+
end
|
64
|
+
|
65
|
+
it "should raise an error when reading a project file that doesn't exist" do
|
66
|
+
lambda { @instance.send(:read_project_file, "foo.rb") }.should raise_error(Rapid::ProjectFileNotFoundError)
|
67
|
+
end
|
68
|
+
|
69
|
+
it "should write a project file" do
|
70
|
+
@instance.send(:write_project_file, "config/foo.rb", "hi")
|
71
|
+
@instance.send(:read_project_file, "config/foo.rb").should == "hi"
|
72
|
+
end
|
73
|
+
|
74
|
+
it "should delete a project file" do
|
75
|
+
create_file "tmp/test/project/foo.rb", "hi"
|
76
|
+
@instance.send(:delete_project_file, "foo.rb")
|
77
|
+
File.exists?("tmp/test/project/foo.rb").should == false
|
78
|
+
end
|
79
|
+
|
80
|
+
it "should not raise an error when deleting a project file that doesn't exist" do
|
81
|
+
@instance.send(:delete_project_file, "foo.rb")
|
82
|
+
end
|
83
|
+
|
84
|
+
it "should chmod a file" do
|
85
|
+
File.should_receive(:chmod).with(0755, "tmp/test/project/foo.rb")
|
86
|
+
@instance.send(:chmod_project_file, 0755, "foo.rb")
|
87
|
+
end
|
88
|
+
|
89
|
+
it "should raise an error when chmodding a file that doesn't exist" do
|
90
|
+
lambda { @instance.send(:chmod_project_file, 0755, "foo.rb") }.should raise_error(Rapid::ProjectFileNotFoundError)
|
91
|
+
end
|
92
|
+
|
93
|
+
end
|
@@ -6,6 +6,7 @@ describe Rapid::Skeleton::Helpers::Gem do
|
|
6
6
|
Object.class_eval do
|
7
7
|
class MyClass
|
8
8
|
include ActiveModel::Validations
|
9
|
+
include Rapid::Skeleton::Helpers::IfSetting
|
9
10
|
include Rapid::Skeleton::Helpers::Gem
|
10
11
|
|
11
12
|
attr_accessor :templates_path, :project_path, :get_binding
|
@@ -18,7 +19,8 @@ describe Rapid::Skeleton::Helpers::Gem do
|
|
18
19
|
end
|
19
20
|
|
20
21
|
def gemfile content
|
21
|
-
@
|
22
|
+
@instance.stub!(:project_file_exists?).with("Gemfile").and_return(true)
|
23
|
+
@instance.stub!(:read_project_file).with("Gemfile").and_return(content)
|
22
24
|
end
|
23
25
|
|
24
26
|
it "should not be valid if the Gemfile does not exist" do
|
@@ -26,6 +28,7 @@ describe Rapid::Skeleton::Helpers::Gem do
|
|
26
28
|
|
27
29
|
@instance = MyClass.new
|
28
30
|
@instance.project_path = "tmp"
|
31
|
+
@instance.should_receive(:project_file_exists?).with("Gemfile").and_return(false)
|
29
32
|
|
30
33
|
@instance.valid?
|
31
34
|
@instance.errors[:gem].should == ["file does not exist"]
|
@@ -35,11 +38,9 @@ describe Rapid::Skeleton::Helpers::Gem do
|
|
35
38
|
|
36
39
|
def push *args
|
37
40
|
@instance.send :gem, *args
|
38
|
-
@gemfile = File.open(@instance.gemfile_path) {|f| f.read }
|
39
41
|
end
|
40
42
|
|
41
43
|
before do
|
42
|
-
FileUtils.mkdir_p 'tmp/test'
|
43
44
|
@instance = MyClass.new
|
44
45
|
@instance.project_path = 'tmp/test'
|
45
46
|
|
@@ -47,72 +48,90 @@ describe Rapid::Skeleton::Helpers::Gem do
|
|
47
48
|
@instance.stub!(:pulling?).and_return(false)
|
48
49
|
end
|
49
50
|
|
50
|
-
after do
|
51
|
-
FileUtils.rm_rf 'tmp/test'
|
52
|
-
end
|
53
|
-
|
54
51
|
it "should append the gem to the existing list" do
|
55
|
-
|
52
|
+
@instance.should_receive(:write_project_file).with("Gemfile", %(\ngem 'rails', '3.1.0'\ngem 'kaminari'))
|
53
|
+
gemfile %(\ngem 'rails', '3.1.0')
|
56
54
|
push 'kaminari'
|
57
|
-
@gemfile.should == %(gem 'rails', '3.1.0'\ngem 'kaminari')
|
58
55
|
end
|
59
56
|
|
60
57
|
it "should push a version" do
|
61
|
-
|
58
|
+
@instance.should_receive(:write_project_file).with("Gemfile", %(\ngem 'rails', '3.1.0'\ngem 'kaminari', '1.0'))
|
59
|
+
|
60
|
+
gemfile %(\ngem 'rails', '3.1.0')
|
62
61
|
push 'kaminari', '1.0'
|
63
|
-
@gemfile.should == %(gem 'rails', '3.1.0'\ngem 'kaminari', '1.0')
|
64
62
|
end
|
65
63
|
|
66
64
|
it "should push options" do
|
67
|
-
|
65
|
+
@instance.should_receive(:write_project_file).with("Gemfile", %(\ngem 'rails', '3.1.0'\ngem 'kaminari', :git => "git://somewhere"))
|
66
|
+
|
67
|
+
gemfile %(\ngem 'rails', '3.1.0')
|
68
68
|
push 'kaminari', :git => 'git://somewhere'
|
69
|
-
@gemfile.should == %(gem 'rails', '3.1.0'\ngem 'kaminari', :git => "git://somewhere")
|
70
69
|
end
|
71
70
|
|
72
71
|
it "should not append the gem if it already exists" do
|
73
|
-
|
72
|
+
@instance.should_receive(:write_project_file).with("Gemfile", %(\ngem 'rails', '3.1.0'))
|
73
|
+
gemfile %(\ngem 'rails', '3.1.0')
|
74
74
|
push 'rails'
|
75
|
-
|
75
|
+
|
76
|
+
@instance.should_receive(:write_project_file).with("Gemfile", %(\ngem 'rails', '3.1.0'))
|
77
|
+
push 'rails', '3.1.0'
|
76
78
|
end
|
77
79
|
|
78
80
|
it "should append to group block if available" do
|
79
|
-
|
81
|
+
@instance.should_receive(:write_project_file).with("Gemfile", %(\ngem 'rails', '3.1.0'\n\ngroup :development do\n gem 'capistrano'\n gem 'capistrano-ext'\nend))
|
82
|
+
gemfile %(\ngem 'rails', '3.1.0'\n\ngroup :development do\n gem 'capistrano'\nend)
|
80
83
|
push 'capistrano-ext', :group => 'development'
|
81
|
-
@gemfile.should == %(gem 'rails', '3.1.0'\n\ngroup :development do\n gem 'capistrano'\n gem 'capistrano-ext'\nend)
|
82
84
|
end
|
83
85
|
|
84
86
|
it "should append with group option if group does not exist" do
|
85
|
-
|
87
|
+
@instance.should_receive(:write_project_file).with("Gemfile", %(\ngem 'rails', '3.1.0'\ngem 'capistrano-ext', :group => :development))
|
88
|
+
gemfile %(\ngem 'rails', '3.1.0')
|
86
89
|
push 'capistrano-ext', :group => 'development'
|
87
|
-
@gemfile.should == %(gem 'rails', '3.1.0'\ngem 'capistrano-ext', :group => :development)
|
88
90
|
end
|
89
91
|
|
90
92
|
it "should append to multiple groups block if available" do
|
91
|
-
|
93
|
+
@instance.should_receive(:write_project_file).with("Gemfile", %(\ngem 'rails', '3.1.0'\n\ngroup :development, :test do\n gem 'capistrano'\n gem 'capistrano-ext'\nend))
|
94
|
+
gemfile %(\ngem 'rails', '3.1.0'\n\ngroup :development, :test do\n gem 'capistrano'\nend)
|
92
95
|
push 'capistrano-ext', :groups => ['development', 'test']
|
93
|
-
@gemfile.should == %(gem 'rails', '3.1.0'\n\ngroup :development, :test do\n gem 'capistrano'\n gem 'capistrano-ext'\nend)
|
94
96
|
end
|
95
97
|
|
96
98
|
it "should append with multiple groups option if group does not exist" do
|
97
|
-
|
99
|
+
@instance.should_receive(:write_project_file).with("Gemfile", %(\ngem 'rails', '3.1.0'\ngem 'capistrano-ext', :groups => [:development, :test]))
|
100
|
+
|
101
|
+
gemfile %(\ngem 'rails', '3.1.0')
|
98
102
|
push 'capistrano-ext', :groups => ['development', 'test']
|
99
|
-
@gemfile.should == %(gem 'rails', '3.1.0'\ngem 'capistrano-ext', :groups => [:development, :test])
|
100
103
|
end
|
101
104
|
|
102
105
|
it "should push when :if is true" do
|
106
|
+
@instance.should_receive(:write_project_file).with("Gemfile", %(\ngem 'rails', '3.1.0'\ngem 'capistrano-ext'))
|
103
107
|
@instance.should_receive(:set?).with('foo').and_return(true)
|
104
|
-
gemfile %(gem 'rails', '3.1.0')
|
105
108
|
|
109
|
+
gemfile %(\ngem 'rails', '3.1.0')
|
106
110
|
push 'capistrano-ext', :if => 'foo'
|
107
|
-
@gemfile.should == %(gem 'rails', '3.1.0'\ngem 'capistrano-ext')
|
108
111
|
end
|
109
112
|
|
110
|
-
it "should
|
113
|
+
it "should remove the gem :if is false" do
|
114
|
+
@instance.should_receive(:write_project_file).with("Gemfile", %(\ngem 'rails', '3.1.0'))
|
111
115
|
@instance.should_receive(:set?).with('foo').and_return(false)
|
112
|
-
gemfile %(gem 'rails', '3.1.0')
|
113
116
|
|
117
|
+
gemfile %(\ngem 'rails', '3.1.0'\ngem 'capistrano-ext')
|
114
118
|
push 'capistrano-ext', :if => 'foo'
|
115
|
-
|
119
|
+
end
|
120
|
+
|
121
|
+
it "should remove the gem :if is false and the gem is in a group" do
|
122
|
+
@instance.should_receive(:write_project_file).with("Gemfile", %(\ngem 'rails', '3.1.0'))
|
123
|
+
@instance.should_receive(:set?).with('foo').and_return(false)
|
124
|
+
|
125
|
+
gemfile %(\ngem 'rails', '3.1.0'\ngem 'capistrano-ext', :group => :development)
|
126
|
+
push 'capistrano-ext', :group => :development, :if => 'foo'
|
127
|
+
end
|
128
|
+
|
129
|
+
it "should remove the gem :if is false and the gem is in a group block" do
|
130
|
+
@instance.should_receive(:write_project_file).with("Gemfile", %(\ngem 'rails', '3.1.0'\n\ngroup :development do\n gem 'capistrano'\nend))
|
131
|
+
@instance.should_receive(:set?).with('foo').and_return(false)
|
132
|
+
|
133
|
+
gemfile %(\ngem 'rails', '3.1.0'\n\ngroup :development do\n gem 'capistrano'\n gem 'capistrano-ext'\nend)
|
134
|
+
push 'capistrano-ext', :group => :development, :if => 'foo'
|
116
135
|
end
|
117
136
|
|
118
137
|
end
|
@@ -120,7 +139,6 @@ describe Rapid::Skeleton::Helpers::Gem do
|
|
120
139
|
describe "pull_gem" do
|
121
140
|
|
122
141
|
before do
|
123
|
-
FileUtils.mkdir_p 'tmp/test'
|
124
142
|
@instance = MyClass.new
|
125
143
|
@instance.project_path = 'tmp/test'
|
126
144
|
|
@@ -128,10 +146,6 @@ describe Rapid::Skeleton::Helpers::Gem do
|
|
128
146
|
@instance.stub!(:pulling?).and_return(true)
|
129
147
|
end
|
130
148
|
|
131
|
-
after do
|
132
|
-
FileUtils.rm_rf 'tmp/test'
|
133
|
-
end
|
134
|
-
|
135
149
|
it "should report an error it doesn't know where the Gemfile is" do
|
136
150
|
@instance.project_path = nil
|
137
151
|
@instance.should_receive(:error).with("kaminari", "Unknown Gemfile location")
|
@@ -140,20 +154,35 @@ describe Rapid::Skeleton::Helpers::Gem do
|
|
140
154
|
end
|
141
155
|
|
142
156
|
it "should report an error when the gemfile doesn't exist" do
|
157
|
+
@instance.should_receive(:project_file_exists?).with("Gemfile").and_return(false)
|
143
158
|
@instance.should_receive(:error).with("kaminari", "Gemfile doesn't exist")
|
144
159
|
|
145
160
|
@instance.send :gem, 'kaminari'
|
146
161
|
end
|
147
162
|
|
148
163
|
it "should report an error when the gem isn't in the gem file" do
|
149
|
-
gemfile %()
|
164
|
+
gemfile %(\n)
|
150
165
|
@instance.should_receive(:error).with("kaminari", "isn't in your Gemfile")
|
151
166
|
|
152
167
|
@instance.send :gem, 'kaminari'
|
153
168
|
end
|
154
169
|
|
170
|
+
it "should report an error when the gem is in the Gemfile, but commented out" do
|
171
|
+
gemfile %(\n# gem 'kaminari')
|
172
|
+
@instance.should_receive(:error).with("kaminari", "isn't in your Gemfile")
|
173
|
+
|
174
|
+
@instance.send :gem, 'kaminari'
|
175
|
+
end
|
176
|
+
|
177
|
+
it "should not be tricked by the same gem in the file twice, once commented, once not" do
|
178
|
+
gemfile %(\n# gem 'kaminari'\ngem 'kaminari')
|
179
|
+
@instance.should_receive(:ok).with("kaminari", "is in your Gemfile")
|
180
|
+
|
181
|
+
@instance.send :gem, 'kaminari'
|
182
|
+
end
|
183
|
+
|
155
184
|
it "should report ok when the gem is in the gem file" do
|
156
|
-
gemfile %(
|
185
|
+
gemfile %(\ngem 'kaminari')
|
157
186
|
@instance.should_receive(:ok).with("kaminari", "is in your Gemfile")
|
158
187
|
|
159
188
|
@instance.send :gem, 'kaminari'
|
@@ -168,7 +197,7 @@ describe Rapid::Skeleton::Helpers::Gem do
|
|
168
197
|
end
|
169
198
|
|
170
199
|
it "should set the 'if' setting true" do
|
171
|
-
gemfile %(
|
200
|
+
gemfile %(\ngem 'kaminari')
|
172
201
|
@instance.should_receive(:ok).with('kaminari', "is in your Gemfile")
|
173
202
|
@instance.should_receive(:[]=).with('foo', true)
|
174
203
|
|