development 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,18 @@
1
+
2
+ class ::Development::Exception::ExpressionError < ::Exception
3
+
4
+ ################
5
+ # initialize #
6
+ ################
7
+
8
+ def initialize( exception_string, configuration_line_number )
9
+
10
+ exception_string << ' on line ' << configuration_line_number.to_s << ' of configuration file' +
11
+ ' (' + ::File.expand_path( '~/' + ::Development::ConfigurationFileName ) +
12
+ ').'
13
+
14
+ super( exception_string )
15
+
16
+ end
17
+
18
+ end
@@ -0,0 +1,14 @@
1
+
2
+ class ::Development::Exception::ExpressionError::UnknownDirectoryName < ::Development::Exception::ExpressionError
3
+
4
+ ################
5
+ # initialize #
6
+ ################
7
+
8
+ def initialize( named_directory_name, configuration_line_number )
9
+
10
+ super( 'Unknown named directory "' << named_directory_name.to_s + '"', configuration_line_number )
11
+
12
+ end
13
+
14
+ end
@@ -0,0 +1,14 @@
1
+
2
+ class ::Development::Exception::ExpressionError::UnknownGemOrGemsetName < ::Development::Exception::ExpressionError
3
+
4
+ ################
5
+ # initialize #
6
+ ################
7
+
8
+ def initialize( gem_name, configuration_line_number )
9
+
10
+ super( 'Unknown gem or gemset name "' << gem_name.to_s + '"', configuration_line_number )
11
+
12
+ end
13
+
14
+ end
@@ -0,0 +1,16 @@
1
+
2
+ class ::Development::Exception::MalformedExpression < ::Development::Exception::ExpressionError
3
+
4
+ ################
5
+ # initialize #
6
+ ################
7
+
8
+ def initialize( expression_name_string, expression_string, configuration_line_number )
9
+
10
+ exception_string = 'Malformed ' << expression_name_string + ' expression "' << expression_string <<'"'
11
+
12
+ super( exception_string, configuration_line_number )
13
+
14
+ end
15
+
16
+ end
@@ -0,0 +1,15 @@
1
+
2
+ class ::Development::Exception::MalformedExpression::MalformedEnableDisableExpression <
3
+ ::Development::Exception::MalformedExpression
4
+
5
+ ################
6
+ # initialize #
7
+ ################
8
+
9
+ def initialize( expression_string, configuration_line_number )
10
+
11
+ super( 'enable/disable', expression_string, configuration_line_number )
12
+
13
+ end
14
+
15
+ end
@@ -0,0 +1,15 @@
1
+
2
+ class ::Development::Exception::MalformedExpression::MalformedGemsetExpression <
3
+ ::Development::Exception::MalformedExpression
4
+
5
+ ################
6
+ # initialize #
7
+ ################
8
+
9
+ def initialize( expression_string, configuration_line_number )
10
+
11
+ super( 'gemset', expression_string, configuration_line_number )
12
+
13
+ end
14
+
15
+ end
@@ -0,0 +1,15 @@
1
+
2
+ class ::Development::Exception::MalformedExpression::MalformedGeneralDirectoryExpression <
3
+ ::Development::Exception::MalformedExpression
4
+
5
+ ################
6
+ # initialize #
7
+ ################
8
+
9
+ def initialize( expression_string, configuration_line_number )
10
+
11
+ super( 'general directory', expression_string, configuration_line_number )
12
+
13
+ end
14
+
15
+ end
@@ -0,0 +1,15 @@
1
+
2
+ class ::Development::Exception::MalformedExpression::MalformedLocationExpression <
3
+ ::Development::Exception::MalformedExpression
4
+
5
+ ################
6
+ # initialize #
7
+ ################
8
+
9
+ def initialize( expression_string, configuration_line_number )
10
+
11
+ super( 'location', expression_string, configuration_line_number )
12
+
13
+ end
14
+
15
+ end
@@ -0,0 +1,15 @@
1
+
2
+ class ::Development::Exception::MalformedExpression::MalformedNamedDirectoryExpression <
3
+ ::Development::Exception::MalformedExpression
4
+
5
+ ################
6
+ # initialize #
7
+ ################
8
+
9
+ def initialize( expression_string, configuration_line_number )
10
+
11
+ super( 'named directory', expression_string, configuration_line_number )
12
+
13
+ end
14
+
15
+ end
@@ -0,0 +1,15 @@
1
+
2
+ class ::Development::Exception::MalformedExpression::MalformedRemoveGeneralDirectoryExpression <
3
+ ::Development::Exception::MalformedExpression
4
+
5
+ ################
6
+ # initialize #
7
+ ################
8
+
9
+ def initialize( expression_string, configuration_line_number )
10
+
11
+ super( 'remove general directory', expression_string, configuration_line_number )
12
+
13
+ end
14
+
15
+ end
@@ -0,0 +1,35 @@
1
+
2
+ ###
3
+ # @private
4
+ #
5
+ # Included in Object to override require functionality.
6
+ #
7
+ module ::Development::Require
8
+
9
+ #############
10
+ # require #
11
+ #############
12
+
13
+ ###
14
+ # Overrides default require functionality to include development paths
15
+ # instead of gems as specified by configuration file.
16
+ #
17
+ # @param gem_name_or_path
18
+ #
19
+ # Gem name or path to file.
20
+ #
21
+ # @return [true,false] Whether require loaded gem/file.
22
+ #
23
+ def require( gem_name_or_path )
24
+
25
+ did_load = false
26
+
27
+ unless did_load = ::Development.require( gem_name_or_path )
28
+ did_load = super
29
+ end
30
+
31
+ return did_load
32
+
33
+ end
34
+
35
+ end
@@ -0,0 +1,294 @@
1
+
2
+ require_relative '../lib/development.rb'
3
+
4
+ describe ::Development do
5
+
6
+ before :each do
7
+ ::Development.clear
8
+ end
9
+
10
+ ###########################################
11
+ # self.parse_named_directory_expression #
12
+ ###########################################
13
+
14
+ it 'can parse a named directory expression' do
15
+ ::Proc.new { ::Development.parse_named_directory_expression( '+directory_name' ) }.should raise_error( ::Development::Exception::MalformedExpression::MalformedNamedDirectoryExpression )
16
+ ::Development.parse_named_directory_expression( '+directory_name some/path/from/here' )
17
+ ::Development.directory( :directory_name ).should == ::File.expand_path( 'some/path/from/here' )
18
+ end
19
+
20
+ ##################################
21
+ # self.parse_gemset_expression #
22
+ ##################################
23
+
24
+ it 'can parse a gemset expression' do
25
+ ::Development.parse_gemset_expression( '=gemset' )
26
+ ::Development.gemset( :gemset ).should == [ ]
27
+ ::Development.parse_gemset_expression( '=another_gemset some_gem, +some_other_gem, another_gem, -another_gem' )
28
+ ::Development.gemset( :another_gemset ).should == [ :some_gem, :some_other_gem ]
29
+ ::Development.parse_gemset_expression( '=some_other_gemset some_gem +some_other_gem another_gem -another_gem' )
30
+ ::Development.gemset( :some_other_gemset ).should == [ :some_gem, :some_other_gem ]
31
+ end
32
+
33
+ ####################################
34
+ # self.parse_location_expression #
35
+ ####################################
36
+
37
+ it 'can parse a location expression' do
38
+ ::Development.parse_named_directory_expression( '+directory_name some/path/from/here' )
39
+ ::Development.directory( :directory_name ).should == ::File.expand_path( 'some/path/from/here' )
40
+ ::Development.parse_named_directory_expression( '+directory_name some/path/from/here' )
41
+ ::Development.parse_location_expression( '@directory_name gem_name, some_other_gem' )
42
+ ::Proc.new { ::Development.parse_location_expression( '@unknown_directory_name gem_name, some_other_gem' ) }.should raise_error( ::Development::Exception::MalformedExpression::UnknownDirectoryName )
43
+
44
+ end
45
+
46
+ ##########################################
47
+ # self.parse_enable_disable_expression #
48
+ ##########################################
49
+
50
+ it 'can parse an enable/disable expression' do
51
+
52
+ ::Development.parse_enable_disable_expression( '!enable some_gem, some_other_gem, some_gemset' )
53
+ ::Development.enabled_for_all?.should == false
54
+ ::Development.enabled_gems.should == [ :some_gem, :some_other_gem, :some_gemset ]
55
+ ::Development.disabled_gems.should == [ ]
56
+
57
+ ::Development.parse_enable_disable_expression( '!disable some_gem, some_other_gem' )
58
+ ::Development.enabled_for_all?.should == false
59
+ ::Development.enabled_gems.should == [ :some_gemset ]
60
+ ::Development.disabled_gems.should == [ :some_gem, :some_other_gem ]
61
+
62
+ ::Development.parse_enable_disable_expression( '!enable some_gem, some_other_gem' )
63
+ ::Development.enabled_for_all?.should == false
64
+ ::Development.enabled_gems.should == [ :some_gemset, :some_gem, :some_other_gem ]
65
+ ::Development.disabled_gems.should == [ ]
66
+
67
+ ::Development.parse_enable_disable_expression( '!disable' )
68
+ ::Development.enabled_for_all?.should == false
69
+ ::Development.enabled_gems.should == [ ]
70
+ ::Development.disabled_gems.should == [ :some_gemset, :some_gem, :some_other_gem ]
71
+
72
+ ::Development.parse_enable_disable_expression( '!enable' )
73
+ ::Development.enabled_for_all?.should == true
74
+ ::Development.enabled_gems.should == [ :some_gemset, :some_gem, :some_other_gem ]
75
+ ::Development.disabled_gems.should == [ ]
76
+
77
+ ::Development.parse_enable_disable_expression( '!disable' )
78
+ ::Development.enabled_for_all?.should == false
79
+ ::Development.enabled_gems.should == [ ]
80
+ ::Development.disabled_gems.should == [ :some_gemset, :some_gem, :some_other_gem ]
81
+
82
+ end
83
+
84
+ ####################################################
85
+ # self.parse_general_load_path_expression #
86
+ # self.parse_remove_general_load_path_expression #
87
+ ####################################################
88
+
89
+ it 'can parse a general load path expression or a remove-general load path expression' do
90
+
91
+ ::Development.parse_general_load_path_expression( '/path/to/somewhere' )
92
+ ::Development.general_load_paths.include?( '/path/to/somewhere' ).should == true
93
+ ::Development.parse_remove_general_load_path_expression( '-/path/to/somewhere' )
94
+ ::Development.general_load_paths.include?( '/path/to/somewhere' ).should == false
95
+
96
+ ::Development.parse_general_load_path_expression( '~/path/to/somewhere' )
97
+ ::Development.general_load_paths.include?( ::File.expand_path( '~/path/to/somewhere' ) ).should == true
98
+ ::Development.parse_remove_general_load_path_expression( '-~/path/to/somewhere' )
99
+ ::Development.general_load_paths.include?( ::File.expand_path( '~/path/to/somewhere' ) ).should == false
100
+
101
+ ::Development.parse_general_load_path_expression( ::File.expand_path( '../../path/to/somewhere' ) )
102
+ ::Development.general_load_paths.include?( ::File.expand_path( '../../path/to/somewhere' ) ).should == true
103
+ ::Development.parse_remove_general_load_path_expression( '-../../path/to/somewhere' )
104
+ ::Development.general_load_paths.include?( ::File.expand_path( '../../path/to/somewhere' ) ).should == false
105
+
106
+ ::Development.parse_general_load_path_expression( ::File.expand_path( 'path/to/somewhere' ) )
107
+ ::Development.general_load_paths.include?( ::File.expand_path( 'path/to/somewhere' ) ).should == true
108
+ ::Development.parse_remove_general_load_path_expression( '-path/to/somewhere' )
109
+ ::Development.general_load_paths.include?( ::File.expand_path( 'path/to/somewhere' ) ).should == false
110
+
111
+ end
112
+
113
+ #########################################################
114
+ # self.parse_general_directory_or_location_expression #
115
+ #########################################################
116
+
117
+ it 'can parse a general path or named directory expression' do
118
+
119
+ ::Development.parse_named_directory_expression( '+named_path ~/path/to/somewhere' )
120
+ ::Development.directory( :named_path ).should == ::File.expand_path( '~/path/to/somewhere' )
121
+
122
+ ::Development.parse_general_directory_or_location_expression( '@named_path some_gem, some_other_gem' )
123
+ ::Development.location( :named_path ).should == [ :some_gem, :some_other_gem ]
124
+
125
+ ::Development.parse_general_directory_or_location_expression( '@named_path/path/to/somewhere' )
126
+ ::Development.general_load_paths.include?( ::File.expand_path( '~/path/to/somewhere/path/to/somewhere' ) ).should == true
127
+
128
+ end
129
+
130
+ ########################################
131
+ # self.parse_configuration_file_line #
132
+ ########################################
133
+
134
+ it 'can parse a line from a file to create an expression from multiple lines' do
135
+
136
+ expression_string = ''
137
+
138
+ # empty expression, text at beginning of line
139
+ ::Development.parse_configuration_file_line( expression_string, '+named_path path/to/somewhere' ).should == false
140
+ expression_string.should == '+named_path path/to/somewhere'
141
+ ::Development.parse_configuration_file_line( expression_string, '@named_path some_gem' ).should == true
142
+ expression_string.should == '+named_path path/to/somewhere'
143
+
144
+ expression_string = ''
145
+ ::Development.parse_configuration_file_line( expression_string, '@named_path some_gem' ).should == false
146
+ expression_string.should == '@named_path some_gem'
147
+ ::Development.parse_configuration_file_line( expression_string, ' some_other_gem' ).should == false
148
+ expression_string.should == '@named_path some_gem some_other_gem'
149
+ ::Development.parse_configuration_file_line( expression_string, ' another_gem' ).should == false
150
+ expression_string.should == '@named_path some_gem some_other_gem another_gem'
151
+ ::Development.parse_configuration_file_line( expression_string, ' yet_another_gem' ).should == false
152
+ expression_string.should == '@named_path some_gem some_other_gem another_gem yet_another_gem'
153
+ ::Development.parse_configuration_file_line( expression_string, '@named_path a_gem' ).should == true
154
+ expression_string.should == '@named_path some_gem some_other_gem another_gem yet_another_gem'
155
+
156
+ # empty expression, comment
157
+ expression_string = ''
158
+ ::Development.parse_configuration_file_line( expression_string, '# blah blah blah blah' ).should == false
159
+ expression_string.should == ''
160
+
161
+ # part expression, indented text
162
+ ::Development.parse_configuration_file_line( expression_string, '@named_path some_gem' ).should == false
163
+ ::Development.parse_configuration_file_line( expression_string, ' some_other_gem' ).should == false
164
+
165
+ # part expression, comment
166
+ ::Development.parse_configuration_file_line( expression_string, '# blah blah blah blah' ).should == false
167
+ ::Development.parse_configuration_file_line( expression_string, ' another_gem' ).should == false
168
+ ::Development.parse_configuration_file_line( expression_string, ' # blah!' ).should == false
169
+ ::Development.parse_configuration_file_line( expression_string, ' yet_another_gem' ).should == false
170
+ ::Development.parse_configuration_file_line( expression_string, '@named_path some_unnamed_gem' ).should == true
171
+
172
+ end
173
+
174
+ #########################################
175
+ # self.parse_configuration_expression #
176
+ #########################################
177
+
178
+ it 'can parse a configuration expression assembled from configuration file line(s)' do
179
+
180
+ # + - named directory expression
181
+ ::Development.parse_configuration_expression( '+directory_name some/path/from/here' )
182
+ ::Development.directory( :directory_name ).should == ::File.expand_path( 'some/path/from/here' )
183
+
184
+ # = - gemset expression
185
+ ::Development.parse_configuration_expression( '=another_gemset some_gem, +some_other_gem, another_gem, -another_gem' )
186
+ ::Development.gemset( :another_gemset ).should == [ :some_gem, :some_other_gem ]
187
+
188
+ # @ - location expression
189
+ ::Development.parse_configuration_expression( '+directory_name some/path/from/here' )
190
+ ::Development.directory( :directory_name ).should == ::File.expand_path( 'some/path/from/here' )
191
+
192
+ # ! - enable/disable expression
193
+ ::Development.parse_configuration_expression( '!enable some_gem, some_other_gem, some_gemset' )
194
+ ::Development.enabled_for_all?.should == false
195
+ ::Development.enabled_gems.should == [ :some_gem, :some_other_gem, :some_gemset ]
196
+ ::Development.disabled_gems.should == [ ]
197
+
198
+ ::Development.parse_configuration_expression( '!disable' )
199
+ ::Development.enabled_for_all?.should == false
200
+ ::Development.enabled_gems.should == [ ]
201
+ ::Development.disabled_gems.should == [ :some_gem, :some_other_gem, :some_gemset ]
202
+
203
+ # general path expression
204
+ # - - remove general path
205
+ ::Development.parse_configuration_expression( '/path/to/somewhere' )
206
+ ::Development.general_load_paths.include?( '/path/to/somewhere' ).should == true
207
+ ::Development.parse_configuration_expression( '-/path/to/somewhere' )
208
+ ::Development.general_load_paths.include?( '/path/to/somewhere' ).should == false
209
+
210
+ end
211
+
212
+ #################################
213
+ # self.gem_name_at_load_path? #
214
+ #################################
215
+
216
+ it 'can find a gem name at a load path' do
217
+ ::Development.gem_name_at_load_path?( 'spec', 'mock_gem' ).should == true
218
+ ::Development.gem_name_at_load_path?( 'spec', 'mock_gem-subgem' ).should == true
219
+ end
220
+
221
+ #############################
222
+ # self.load_gem_from_path #
223
+ #############################
224
+
225
+ it 'can load a gem from a development path' do
226
+
227
+ defined?( ::Development::MockGem ).should == nil
228
+ ::Development.load_gem_from_path( 'spec', 'mock_gem' )
229
+ defined?( ::Development::MockGem ).should == 'constant'
230
+
231
+ defined?( ::Development::MockGem::Subgem ).should == nil
232
+ ::Development.load_gem_from_path( 'spec', 'mock_gem-subgem' )
233
+ defined?( ::Development::MockGem::Subgem ).should == 'constant'
234
+
235
+ end
236
+
237
+ ##################################
238
+ # self.load_configuration_file #
239
+ ##################################
240
+
241
+ it 'can load a configuration file' do
242
+
243
+ ::Development.load_configuration_file( 'example.development' )
244
+
245
+ ::Development.gemset( :ruby ).should == [ :"module-cluster" ]
246
+ ::Development.gemset( :hooked_objects ).should == [ :"hash-hooked", :"array-hooked", :"array-sorted", :"array-unique", :"array-sorted-unique" ]
247
+ ::Development.gemset( :compositing_objects ).should == [ :"hash-compositing", :"array-compositing", :"array-sorted-compositing", :"array-unique-compositing", :"array-sorted-unique-compositing" ]
248
+ ::Development.gemset( :ridiculous_power ).should == [ :"persistence", :"magnets" ]
249
+
250
+ ::Development.directory( :code ).should == ::File.expand_path( '~/Projects' )
251
+ ::Development.directory( :ridiculous_power ).should == ::File.expand_path( '~/Projects/rp' )
252
+ ::Development.directory( :ruby ).should == ::File.expand_path( '~/Projects/rp/ruby' )
253
+ ::Development.directory( :hooked_objects ).should == ::File.expand_path( '~/Projects/rp/ruby/hooked_objects' )
254
+ ::Development.directory( :compositing_objects ).should == ::File.expand_path( '~/Projects/rp/ruby/compositing_objects' )
255
+
256
+ ::Development.location( :hooked_objects ).should == [ :hooked_objects ]
257
+ ::Development.location( :compositing_objects ).should == [ :compositing_objects ]
258
+ ::Development.location( :ridiculous_power ).should == [ :ridiculous_power ]
259
+
260
+ ::Development.enabled_gems.should == [ ]
261
+ ::Development.enabled_for_all?.should == true
262
+
263
+ end
264
+
265
+ ####################
266
+ # Object.require #
267
+ ####################
268
+
269
+ it 'hooks require for registered gems' do
270
+
271
+ ::Development.parse_configuration_expression( '+directory_name ./spec' )
272
+ ::Development.parse_configuration_expression( '@directory_name require_mock' )
273
+ ::Development.parse_configuration_expression( '!enable require_mock' )
274
+
275
+ defined?( ::Development::RequireMock ).should == nil
276
+ require 'require_mock'
277
+ defined?( ::Development::RequireMock ).should == 'constant'
278
+
279
+ end
280
+
281
+ it 'hooks require for enable-all' do
282
+
283
+ ::Development.parse_configuration_expression( '+directory_name ./spec' )
284
+ ::Development.parse_configuration_expression( '@directory_name' )
285
+ ::Development.parse_configuration_expression( '!enable' )
286
+
287
+ defined?( ::Development::OtherRequireMock ).should == nil
288
+ require 'other_require_mock'
289
+ defined?( ::Development::OtherRequireMock ).should == 'constant'
290
+
291
+ end
292
+
293
+ end
294
+