ninjs 0.13.4 → 0.13.5
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/README.md +1 -1
- data/VERSION +1 -1
- data/bin/ninjs +22 -21
- data/lib/ninjs/command.rb +15 -32
- data/lib/ninjs/configuration.rb +9 -3
- data/lib/ninjs/generator.rb +33 -24
- data/lib/ninjs/helpers.rb +1 -0
- data/lib/ninjs/notification.rb +1 -1
- data/lib/ninjs/project.rb +34 -18
- data/ninjs.gemspec +14 -5
- data/repository/ninjs/core/application.js +11 -20
- data/repository/ninjs/core/existence.js +37 -11
- data/repository/ninjs/core/extend.js +25 -34
- data/repository/ninjs/core/module.js +38 -49
- data/repository/ninjs/extensions/jquery.elements.js +60 -0
- data/repository/ninjs/utilities/array.js +8 -13
- data/repository/ninjs/utilities/string.js +6 -11
- data/repository/syntaxhighlighter/{default.js → all.js} +0 -0
- data/spec/helpers_spec.rb +11 -0
- data/spec/integration_spec.rb +257 -0
- data/spec/manifest_spec.rb +8 -0
- data/spec/ninjs_spec.rb +29 -250
- data/spec/notification_spec.rb +27 -0
- data/spec/spec_helper.rb +2 -1
- metadata +68 -60
- data/repository/ninjs/extensions/ninjs.jquery.js +0 -67
@@ -8,11 +8,7 @@
|
|
8
8
|
<NinjsModule>
|
9
9
|
*/
|
10
10
|
|
11
|
-
var NinjsApplication = function(base_url, tests_path) {
|
12
|
-
if (is_undefined(window.app)) {
|
13
|
-
window.app = this;
|
14
|
-
}
|
15
|
-
|
11
|
+
var NinjsApplication = function(base_url, tests_path) {
|
16
12
|
if(is_defined(tests_path)) {
|
17
13
|
this.tests_path = tests_path;
|
18
14
|
}
|
@@ -35,22 +31,17 @@ var NinjsApplication = function(base_url, tests_path) {
|
|
35
31
|
> myapp.add_module('my_module');
|
36
32
|
*/
|
37
33
|
NinjsApplication.method('add_module', function(name) {
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
}
|
34
|
+
if (is_undefined(name)) {
|
35
|
+
throw new SyntaxError("NinjsApplication.add_module(name): name is undefined");
|
36
|
+
}
|
42
37
|
|
43
|
-
|
44
|
-
|
45
|
-
}
|
46
|
-
|
47
|
-
if (this.name === name) {
|
48
|
-
throw new SyntaxError("NinjsApplication.add_module(name): a module cannot have the same name as the application");
|
49
|
-
}
|
50
|
-
|
51
|
-
return this[name] = new NinjsModule(name);
|
38
|
+
if (is_defined(this[name])) {
|
39
|
+
throw new SyntaxError("NinjsApplication.add_module(name): '" + name + "' already declared");
|
52
40
|
}
|
53
|
-
|
54
|
-
|
41
|
+
|
42
|
+
if (this.name === name) {
|
43
|
+
throw new SyntaxError("NinjsApplication.add_module(name): a module cannot have the same name as the application");
|
55
44
|
}
|
45
|
+
|
46
|
+
return this[name] = new NinjsModule(name);
|
56
47
|
});
|
@@ -61,19 +61,14 @@ if (is_undefined(is_typeof)) {
|
|
61
61
|
<is_regex>
|
62
62
|
*/
|
63
63
|
var is_typeof = function(type, suspect) {
|
64
|
-
|
65
|
-
|
66
|
-
throw new SyntaxError("is_typeof(Type, suspect): type is undefined");
|
67
|
-
}
|
68
|
-
if (is_undefined(suspect)) {
|
69
|
-
throw new SyntaxError("is_typeof(Type, suspect): suspect is undefined");
|
70
|
-
}
|
71
|
-
|
72
|
-
return (suspect.constructor == type) ? true : false;
|
64
|
+
if (is_undefined(type)) {
|
65
|
+
throw new SyntaxError("is_typeof(Type, suspect): type is undefined");
|
73
66
|
}
|
74
|
-
|
75
|
-
|
67
|
+
if (is_undefined(suspect)) {
|
68
|
+
throw new SyntaxError("is_typeof(Type, suspect): suspect is undefined");
|
76
69
|
}
|
70
|
+
|
71
|
+
return (suspect.constructor == type) ? true : false;
|
77
72
|
};
|
78
73
|
}
|
79
74
|
|
@@ -249,3 +244,34 @@ if (is_undefined(is_regex)) {
|
|
249
244
|
return is_typeof(RegExp, suspect);
|
250
245
|
};
|
251
246
|
}
|
247
|
+
|
248
|
+
|
249
|
+
if (is_undefined(is_empty)) {
|
250
|
+
/*
|
251
|
+
Function: is_empty
|
252
|
+
Determined if the suspect's length is less than one.
|
253
|
+
|
254
|
+
Parameters:
|
255
|
+
suspect - suspect variable to test
|
256
|
+
|
257
|
+
Returns: bool
|
258
|
+
*/
|
259
|
+
var is_empty = function(suspect) {
|
260
|
+
return suspect.length === 0;
|
261
|
+
};
|
262
|
+
}
|
263
|
+
|
264
|
+
if (is_undefined(is_not_empty)) {
|
265
|
+
/*
|
266
|
+
Function: is_not_empty
|
267
|
+
Determined if the suspect's length is greater than one.
|
268
|
+
|
269
|
+
Parameters:
|
270
|
+
suspect - suspect variable to test
|
271
|
+
|
272
|
+
Returns: bool
|
273
|
+
*/
|
274
|
+
var is_not_empty = function(suspect) {
|
275
|
+
return suspect.length >= 1;
|
276
|
+
};
|
277
|
+
}
|
@@ -20,21 +20,17 @@ if (is_undefined(Function.prototype['method'])) {
|
|
20
20
|
> "hello".custom_method();
|
21
21
|
*/
|
22
22
|
Function.prototype.method = function(name, func) {
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
}
|
30
|
-
|
31
|
-
if (is_undefined(this.prototype[name])) {
|
32
|
-
this.prototype[name] = func;
|
33
|
-
return this;
|
34
|
-
}
|
23
|
+
if (is_undefined(name)) {
|
24
|
+
throw new SyntaxError("Object.method(name, func): name is undefined");
|
25
|
+
}
|
26
|
+
|
27
|
+
if (is_undefined(func)) {
|
28
|
+
throw new SyntaxError("Object.method(name, func): func is undefined");
|
35
29
|
}
|
36
|
-
|
37
|
-
|
30
|
+
|
31
|
+
if (is_undefined(this.prototype[name])) {
|
32
|
+
this.prototype[name] = func;
|
33
|
+
return this;
|
38
34
|
}
|
39
35
|
};
|
40
36
|
}
|
@@ -62,25 +58,20 @@ if (is_undefined(unless)) {
|
|
62
58
|
> );
|
63
59
|
*/
|
64
60
|
var unless = function(expression, callback, fallback) {
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
}
|
81
|
-
}
|
82
|
-
catch(error) {
|
83
|
-
alert(error.message);
|
84
|
-
}
|
61
|
+
if (is_undefined(expression)) {
|
62
|
+
throw new SyntaxError("unless(expression, callback[, fallback]): expression is undefined");
|
63
|
+
}
|
64
|
+
|
65
|
+
if (is_undefined(callback)) {
|
66
|
+
throw new SyntaxError("unless(expression, callback[, fallback]): callback is undefined");
|
67
|
+
}
|
68
|
+
|
69
|
+
// This kind of expression is exactly why we NEED unless
|
70
|
+
if (!expression) {
|
71
|
+
callback.call(this);
|
72
|
+
}
|
73
|
+
else if (is_defined(fallback)) {
|
74
|
+
fallback.call(this);
|
75
|
+
}
|
85
76
|
};
|
86
77
|
}
|
@@ -40,63 +40,52 @@ NinjsModule.method('execute', function() {
|
|
40
40
|
});
|
41
41
|
|
42
42
|
NinjsModule.method('elements', function(elements) {
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
}
|
51
|
-
}
|
52
|
-
|
53
|
-
// If first argument is a string, retrieve the element
|
54
|
-
if (is_string(elements)) {
|
55
|
-
var name = elements;
|
56
|
-
return is_defined(this.dom[name]) ? this.dom[name] : undefined;
|
57
|
-
}
|
58
|
-
// Set elements
|
59
|
-
else {
|
60
|
-
this.call_on_ready(function() {
|
61
|
-
for(var key in elements) {
|
62
|
-
if (elements.hasOwnProperty(key)) {
|
63
|
-
this.dom[key] = elements[key];
|
64
|
-
}
|
65
|
-
}
|
66
|
-
});
|
67
|
-
}
|
68
|
-
}
|
69
|
-
catch(error) {
|
70
|
-
alert(error.message);
|
43
|
+
if (is_undefined(elements)) {
|
44
|
+
if (is_typeof(Object, elements)) {
|
45
|
+
throw new SyntaxError("NinjsModule.elements(elements): elements is undefined");
|
46
|
+
}
|
47
|
+
else if (is_string(elements)) {
|
48
|
+
throw new SyntaxError("NinjsModule.elements(name): name is undefined");
|
49
|
+
}
|
71
50
|
}
|
72
51
|
|
52
|
+
// If first argument is a string, retrieve the element
|
53
|
+
if (is_string(elements)) {
|
54
|
+
var name = elements;
|
55
|
+
return is_defined(this.dom[name]) ? this.dom[name] : undefined;
|
56
|
+
}
|
57
|
+
// Set elements
|
58
|
+
else {
|
59
|
+
this.call_on_ready(function() {
|
60
|
+
for(var key in elements) {
|
61
|
+
if (elements.hasOwnProperty(key)) {
|
62
|
+
this.dom[key] = elements[key];
|
63
|
+
}
|
64
|
+
}
|
65
|
+
});
|
66
|
+
}
|
73
67
|
});
|
74
68
|
|
75
69
|
NinjsModule.method('set_data', function(key, value) {
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
}
|
84
|
-
|
85
|
-
if (is_typeof(String, key)) {
|
86
|
-
this.data[key] = value;
|
87
|
-
}
|
88
|
-
else if (is_typeof(Object, key)) {
|
89
|
-
var data = key;
|
90
|
-
for(var property in data) {
|
91
|
-
this.data[property] = data[property];
|
92
|
-
}
|
93
|
-
}
|
70
|
+
if (is_undefined(key)) {
|
71
|
+
throw new SyntaxError('NinjsModule.set_data(key, value): key is undefined');
|
72
|
+
}
|
73
|
+
|
74
|
+
if (is_typeof(String, key) && is_undefined(value)) {
|
75
|
+
throw new SyntaxError('NinjsModule.set_data(key, value): value is undefined');
|
76
|
+
}
|
94
77
|
|
95
|
-
|
78
|
+
if (is_typeof(String, key)) {
|
79
|
+
this.data[key] = value;
|
96
80
|
}
|
97
|
-
|
98
|
-
|
81
|
+
else if (is_typeof(Object, key)) {
|
82
|
+
var data = key;
|
83
|
+
for(var property in data) {
|
84
|
+
this.data[property] = data[property];
|
85
|
+
}
|
99
86
|
}
|
87
|
+
|
88
|
+
return this;
|
100
89
|
});
|
101
90
|
|
102
91
|
NinjsModule.method('add_test', function(test_file) {
|
@@ -0,0 +1,60 @@
|
|
1
|
+
(function($) {
|
2
|
+
NinjsModule.prototype.elements = function(elements, force) {
|
3
|
+
var self = this;
|
4
|
+
|
5
|
+
unless(is_defined(force), function() {
|
6
|
+
force = false;
|
7
|
+
});
|
8
|
+
|
9
|
+
if (is_string(elements)) {
|
10
|
+
var key = elements;
|
11
|
+
if (is_undefined(self.dom[key])) {
|
12
|
+
throw new SyntaxError("NinjsModule.elements('" + key + "'): " + self.name + ".dom." + key + " is undefined");
|
13
|
+
}
|
14
|
+
|
15
|
+
if (is_string(self.dom[key])) {
|
16
|
+
var selection = $(self.dom[key]);
|
17
|
+
|
18
|
+
unless(selection.length === 0, function() {
|
19
|
+
return self.dom[key] = selection;
|
20
|
+
}, function() {
|
21
|
+
return self.dom[key];
|
22
|
+
});
|
23
|
+
}
|
24
|
+
else {
|
25
|
+
if (self.dom[key].length === 0 || force) {
|
26
|
+
|
27
|
+
var return_obj = undefined;
|
28
|
+
|
29
|
+
if (is_string(force)) {
|
30
|
+
var selector = self.dom[key].selector;
|
31
|
+
self.dom[key] = $(force).find(selector);
|
32
|
+
self.dom[key].selector = selector;
|
33
|
+
|
34
|
+
return_obj = self.dom[key];
|
35
|
+
}
|
36
|
+
|
37
|
+
var selection = $(self.dom[key].selector);
|
38
|
+
|
39
|
+
unless(selection.length === 0, function() {
|
40
|
+
return_obj = selection;
|
41
|
+
});
|
42
|
+
|
43
|
+
return return_obj;
|
44
|
+
}
|
45
|
+
else {
|
46
|
+
return self.dom[key];
|
47
|
+
}
|
48
|
+
}
|
49
|
+
}
|
50
|
+
else if (is_typeof(Object, elements)) {
|
51
|
+
self.call_on_ready(function() {
|
52
|
+
for(var key in elements) {
|
53
|
+
if (elements.hasOwnProperty(key)) {
|
54
|
+
self.dom[key] = elements[key];
|
55
|
+
}
|
56
|
+
}
|
57
|
+
});
|
58
|
+
}
|
59
|
+
};
|
60
|
+
})(jQuery);
|
@@ -1,24 +1,19 @@
|
|
1
1
|
Array.method('is_empty', function() {
|
2
|
-
return (this
|
2
|
+
return is_empty(this);
|
3
3
|
});
|
4
4
|
|
5
5
|
Array.method('not_empty', function() {
|
6
|
-
return (this
|
6
|
+
return is_not_empty(this);
|
7
7
|
});
|
8
8
|
|
9
9
|
Array.method('each', function(callback) {
|
10
|
-
|
11
|
-
|
12
|
-
throw new SyntaxError("Array.each(callback): callback is undefined");
|
13
|
-
}
|
14
|
-
|
15
|
-
for (var i = 0; i < this.length; i++) {
|
16
|
-
var args = [this[i], i];
|
17
|
-
callback.apply(this, args);
|
18
|
-
}
|
10
|
+
if(is_undefined(callback)) {
|
11
|
+
throw new SyntaxError("Array.each(callback): callback is undefined");
|
19
12
|
}
|
20
|
-
|
21
|
-
|
13
|
+
|
14
|
+
for (var i = 0; i < this.length; i++) {
|
15
|
+
var args = [this[i], i];
|
16
|
+
callback.apply(this, args);
|
22
17
|
}
|
23
18
|
});
|
24
19
|
|
@@ -24,18 +24,13 @@ String.method('rtrim', function() {
|
|
24
24
|
});
|
25
25
|
|
26
26
|
String.method('each', function(callback) {
|
27
|
-
|
28
|
-
|
29
|
-
throw new SyntaxError("String.each(callback): callback is undefined");
|
30
|
-
}
|
31
|
-
|
32
|
-
for (var i = 0; i < this.length; i++) {
|
33
|
-
var args = [this.charAt(i), i];
|
34
|
-
callback.apply(this, args);
|
35
|
-
}
|
27
|
+
if(is_undefined(callback)) {
|
28
|
+
throw new SyntaxError("String.each(callback): callback is undefined");
|
36
29
|
}
|
37
|
-
|
38
|
-
|
30
|
+
|
31
|
+
for (var i = 0; i < this.length; i++) {
|
32
|
+
var args = [this.charAt(i), i];
|
33
|
+
callback.apply(this, args);
|
39
34
|
}
|
40
35
|
});
|
41
36
|
|
File without changes
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Ninjs::Helpers do
|
4
|
+
it 'should create a module filename from a POSIX path' do
|
5
|
+
Ninjs::Helpers.create_module_filename('/some/path/some.module.js').should === 'some'
|
6
|
+
end
|
7
|
+
|
8
|
+
it 'should create a module filename from a Windows path' do
|
9
|
+
Ninjs::Helpers.create_module_filename('D:\\\\some\path\some.module.js').should === 'some'
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,257 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Ninjs do
|
4
|
+
context 'When instantiating a new project' do
|
5
|
+
before :each do
|
6
|
+
@spec_dir = File.expand_path(File.join(File.dirname(__FILE__))) + '/'
|
7
|
+
@project_path = @spec_dir + 'js/'
|
8
|
+
@new_project = Ninjs::Project.new 'spec/js', 'MyApplication'
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'should have the correct app_filename' do
|
12
|
+
@new_project.config.app_filename.should === 'myapplication'
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'should have the correct project_path' do
|
16
|
+
@new_project.project_path.should === @project_path
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'should have a @config property' do
|
20
|
+
@new_project.config.should_not be_nil
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'should have the correct @config.name' do
|
24
|
+
@new_project.config.name.should === 'MyApplication'
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'should have the correct @config.output' do
|
28
|
+
@new_project.config.output.should === 'expanded'
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'should have the correct @config.dependencies' do
|
32
|
+
@new_project.config.dependencies.should == ["<jquery/latest>"]
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'should have the correct @config.autoload' do
|
36
|
+
@new_project.config.autoload.should == ["<ninjs/utilities/all>"]
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'should have the corect @config.base_url' do
|
40
|
+
@new_project.config.base_url.should == 'http://www.example.com/'
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'should have the correct @config.test_path' do
|
44
|
+
@new_project.config.test_path.should == 'tests/'
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'should respond to create' do
|
48
|
+
@new_project.should respond_to :create
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'should create the project directory' do
|
52
|
+
@new_project.create
|
53
|
+
File.exists?('/Volumes/Storage/Development/ninjs/spec/js').should be_true
|
54
|
+
end
|
55
|
+
|
56
|
+
it 'should have created the Ninjs::Manifest directories' do
|
57
|
+
Ninjs::Manifest.directories.each do |folder|
|
58
|
+
File.exists?("#{@project_path}#{folder}").should be_true
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
it 'should have created a config file' do
|
63
|
+
File.exists?("#{@project_path}ninjs.conf").should be_true
|
64
|
+
end
|
65
|
+
|
66
|
+
it 'should have created the application file' do
|
67
|
+
File.exists?("#{@project_path}application/myapplication.js").should be_true
|
68
|
+
end
|
69
|
+
|
70
|
+
it 'should have created the /lib/nin.js file' do
|
71
|
+
File.exists?("#{@project_path}lib/nin.js")
|
72
|
+
end
|
73
|
+
|
74
|
+
it 'should have created the /lib/utilities.js file' do
|
75
|
+
File.exists?("#{@project_path}lib/utilities.js").should be_true
|
76
|
+
end
|
77
|
+
|
78
|
+
it 'should have created the /tests/index.html file' do
|
79
|
+
File.exists?("#{@project_path}tests/index.html").should be_true
|
80
|
+
end
|
81
|
+
|
82
|
+
it 'should have created the /tests/ninjs.test.js file' do
|
83
|
+
File.exists?("#{@project_path}tests/ninjs.test.js").should be_true
|
84
|
+
end
|
85
|
+
|
86
|
+
it 'should have created the /tests/ninjs.utilties.test.js file' do
|
87
|
+
File.exists?("#{@project_path}tests/ninjs.utilities.test.js").should be_true
|
88
|
+
end
|
89
|
+
|
90
|
+
it 'should have the correct config file content' do
|
91
|
+
expected_conf_file = File.open('/Volumes/Storage/Development/ninjs/spec/fixtures/ninjs.conf', 'r')
|
92
|
+
expected_conf_content = expected_conf_file.readlines
|
93
|
+
expected_conf_file.close
|
94
|
+
|
95
|
+
ninjs_conf_file = File.open("#{@project_path}ninjs.conf", 'r')
|
96
|
+
ninjs_conf_content = ninjs_conf_file.readlines
|
97
|
+
ninjs_conf_file.close
|
98
|
+
|
99
|
+
ninjs_conf_content.should === expected_conf_content
|
100
|
+
end
|
101
|
+
|
102
|
+
it 'should have the correct application file content' do
|
103
|
+
expected_file = File.open('/Volumes/Storage/Development/ninjs/spec/fixtures/myapplication.js', 'r')
|
104
|
+
expected_content = expected_file.readlines
|
105
|
+
|
106
|
+
# .shift is to remove the generated comment which should never match
|
107
|
+
expected_content.shift
|
108
|
+
expected_file.close
|
109
|
+
|
110
|
+
actual_file = File.open("#{@project_path}application/myapplication.js", 'r')
|
111
|
+
actual_content = actual_file.readlines
|
112
|
+
actual_content.shift
|
113
|
+
actual_file.close
|
114
|
+
|
115
|
+
actual_content.should === expected_content
|
116
|
+
end
|
117
|
+
|
118
|
+
it 'should have the correct /lib/nin.js content' do
|
119
|
+
expected_ninjs_lib_file = File.open('/Volumes/Storage/Development/ninjs/spec/fixtures/nin.js', "r")
|
120
|
+
expected_ninjs_lib_content= expected_ninjs_lib_file.readlines
|
121
|
+
expected_ninjs_lib_file.close
|
122
|
+
|
123
|
+
ninjs_lib_file = File.open("#{@project_path}lib/nin.js", "r")
|
124
|
+
ninjs_lib_content = ninjs_lib_file.readlines
|
125
|
+
ninjs_lib_file.close
|
126
|
+
|
127
|
+
ninjs_lib_content.should === expected_ninjs_lib_content
|
128
|
+
end
|
129
|
+
|
130
|
+
it 'should have the correct /lib/utilities.js' do
|
131
|
+
expected_utility_lib_file = File.open("/Volumes/Storage/Development/ninjs/spec/fixtures/utilities.js", "r")
|
132
|
+
expected_utility_lib_content = expected_utility_lib_file.readlines
|
133
|
+
expected_utility_lib_file.close
|
134
|
+
|
135
|
+
utility_lib_file = File.open("#{@project_path}lib/utilities.js", "r")
|
136
|
+
utility_lib_content = utility_lib_file.readlines
|
137
|
+
utility_lib_file.close
|
138
|
+
|
139
|
+
utility_lib_content.should === expected_utility_lib_content
|
140
|
+
end
|
141
|
+
|
142
|
+
context 'and a project is updated' do
|
143
|
+
|
144
|
+
before :each do
|
145
|
+
@path = Dir.getwd
|
146
|
+
@project = Ninjs::Project.new 'spec/js/'
|
147
|
+
|
148
|
+
FileUtils.cp("#{@path}/spec/fixtures/global.module.js", "#{@path}/spec/js/modules") unless File.exists?("#{@path}/spec/js/modules/global.module.js")
|
149
|
+
FileUtils.cp("#{@path}/spec/fixtures/test.module.js", "#{@path}/spec/js/modules") unless File.exists?("#{@path}/spec/js/modules/test.module.js")
|
150
|
+
FileUtils.cp("#{@path}/spec/fixtures/test.elements.js", "#{@path}/spec/js/elements") unless File.exists?("#{@path}/spec/js/elements/test.elements.js")
|
151
|
+
FileUtils.cp("#{@path}/spec/fixtures/test.model.js", "#{@path}/spec/js/models") unless File.exists?("#{@path}/spec/js/models/test.model.js")
|
152
|
+
@project.update
|
153
|
+
end
|
154
|
+
|
155
|
+
it 'should have created the /application/global.js module' do
|
156
|
+
File.exists?("#{@path}/spec/js/application/global.js").should be_true
|
157
|
+
end
|
158
|
+
|
159
|
+
it 'should have created the /application/test.js module' do
|
160
|
+
File.exists?("#{@path}/spec/js/application/test.js").should be_true
|
161
|
+
end
|
162
|
+
|
163
|
+
it 'should have the correct /application/global.js content' do
|
164
|
+
expected_global_file = File.open("#{@path}/spec/fixtures/global.js", "r")
|
165
|
+
expected_global_content = expected_global_file.readlines
|
166
|
+
expected_global_file.close
|
167
|
+
|
168
|
+
actual_global_file = File.open("#{@path}/spec/js/application/global.js", "r")
|
169
|
+
actual_global_content = actual_global_file.readlines
|
170
|
+
actual_global_file.close
|
171
|
+
|
172
|
+
actual_global_content.should == expected_global_content
|
173
|
+
end
|
174
|
+
|
175
|
+
it 'should have the correct /application/test.js content' do
|
176
|
+
expected_test_file = File.open("#{@path}/spec/fixtures/test.js", "r")
|
177
|
+
expected_test_content = expected_test_file.readlines
|
178
|
+
expected_test_file.close
|
179
|
+
|
180
|
+
actual_test_file = File.open("#{@path}/spec/js/application/test.js", "r")
|
181
|
+
actual_test_content = actual_test_file.readlines
|
182
|
+
actual_test_file.close
|
183
|
+
|
184
|
+
actual_test_content.should == expected_test_content
|
185
|
+
end
|
186
|
+
end
|
187
|
+
|
188
|
+
end# context When instantiating a new project
|
189
|
+
|
190
|
+
context 'When instantiating a project from a config file' do
|
191
|
+
before :each do
|
192
|
+
@spec_dir = File.expand_path(File.join(File.dirname(__FILE__))) + '/'
|
193
|
+
@project_path = @spec_dir + 'js/'
|
194
|
+
@existing_project = Ninjs::Project.new 'spec/js'
|
195
|
+
end
|
196
|
+
|
197
|
+
it 'should have the correct app_filename' do
|
198
|
+
@existing_project.config.app_filename.should === 'myapplication'
|
199
|
+
end
|
200
|
+
|
201
|
+
it 'should have the correct project_path' do
|
202
|
+
@existing_project.project_path.should === @project_path
|
203
|
+
end
|
204
|
+
|
205
|
+
it 'should have the correct @config.name' do
|
206
|
+
@existing_project.config.name.should === 'MyApplication'
|
207
|
+
end
|
208
|
+
|
209
|
+
it 'should have the correct @config.output' do
|
210
|
+
@existing_project.config.output === 'expanded'
|
211
|
+
end
|
212
|
+
|
213
|
+
it 'should have the correct @config.dependencies' do
|
214
|
+
@existing_project.config.dependencies.should == ["<jquery/latest>"]
|
215
|
+
end
|
216
|
+
|
217
|
+
it 'should have the correct @config.autoload' do
|
218
|
+
@existing_project.config.autoload.should == ["<ninjs/utilities/all>"]
|
219
|
+
end
|
220
|
+
|
221
|
+
it 'should have the corect @config.base_url' do
|
222
|
+
@existing_project.config.base_url == 'http://www.example.com/'
|
223
|
+
end
|
224
|
+
|
225
|
+
it 'should have the correct @config.test_path' do
|
226
|
+
@existing_project.config.test_path == 'tests/'
|
227
|
+
end
|
228
|
+
|
229
|
+
it 'should not need a hack to delete all the files' do
|
230
|
+
File.delete("#{@project_path}ninjs.conf") if File.exists?("#{@project_path}ninjs.conf")
|
231
|
+
File.delete("#{@project_path}application/myapplication.js") if File.exists?("#{@project_path}application/myapplication.js")
|
232
|
+
File.delete("#{@project_path}application/global.js") if File.exists?("#{@project_path}application/global.js")
|
233
|
+
File.delete("#{@project_path}application/test.js") if File.exists?("#{@project_path}application/test.js")
|
234
|
+
File.delete("#{@project_path}elements/test.elements.js") if File.exists?("#{@project_path}elements/test.elements.js")
|
235
|
+
File.delete("#{@project_path}models/test.model.js") if File.exists?("#{@project_path}models/test.model.js")
|
236
|
+
File.delete("#{@project_path}lib/nin.js") if File.exists?("#{@project_path}lib/nin.js")
|
237
|
+
File.delete("#{@project_path}lib/utilities.js") if File.exists?("#{@project_path}lib/utilities.js")
|
238
|
+
File.delete("#{@project_path}tests/index.html") if File.exists?("#{@project_path}tests/index.html")
|
239
|
+
File.delete("#{@project_path}tests/ninjs.test.js") if File.exists?("#{@project_path}tests/ninjs.test.js")
|
240
|
+
File.delete("#{@project_path}tests/ninjs.utilities.test.js") if File.exists?("#{@project_path}tests/ninjs.utilities.test.js")
|
241
|
+
File.delete("#{@project_path}tests/qunit/qunit.css") if File.exists?("#{@project_path}tests/qunit/qunit.css")
|
242
|
+
File.delete("#{@project_path}tests/qunit/qunit.js") if File.exists?("#{@project_path}tests/qunit/qunit.js")
|
243
|
+
Dir.delete("#{@project_path}tests/qunit") if File.exists?("#{@project_path}tests/qunit")
|
244
|
+
File.delete("#{@project_path}modules/global.module.js") if File.exists?("#{@project_path}modules/global.module.js")
|
245
|
+
File.delete("#{@project_path}modules/test.module.js") if File.exists?("#{@project_path}modules/test.module.js")
|
246
|
+
|
247
|
+
Ninjs::Manifest.directories.each do |folder|
|
248
|
+
Dir.delete("#{@project_path}#{folder}") if File.exists? "#{@project_path}#{folder}"
|
249
|
+
end
|
250
|
+
|
251
|
+
Dir.delete('/Volumes/Storage/Development/ninjs/spec/js') if File.exists?('/Volumes/Storage/Development/ninjs/spec/js')
|
252
|
+
true.should be_true
|
253
|
+
end
|
254
|
+
|
255
|
+
end
|
256
|
+
|
257
|
+
end
|