ninjs-framework 0.1.0
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/.DS_Store +0 -0
- data/.bundle/config +2 -0
- data/.travis.yml +2 -0
- data/Gemfile +10 -0
- data/Gemfile.lock +47 -0
- data/LICENSE.txt +20 -0
- data/README.md +4 -0
- data/Rakefile +76 -0
- data/VERSION +1 -0
- data/lib/.DS_Store +0 -0
- data/lib/ninjs-framework.rb +164 -0
- data/lib/ninjs-framework/assets/jasmine/jasmine-html.js +190 -0
- data/lib/ninjs-framework/assets/jasmine/jasmine.css +166 -0
- data/lib/ninjs-framework/assets/jasmine/jasmine.js +2476 -0
- data/lib/ninjs-framework/assets/jasmine/jasmine_favicon.png +0 -0
- data/lib/ninjs-framework/core/.core.pdoc.yaml +0 -0
- data/lib/ninjs-framework/core/.existence.pdoc.yaml +12 -0
- data/lib/ninjs-framework/core/.extend.pdoc.yaml +0 -0
- data/lib/ninjs-framework/core/.nin.pdoc.yaml +0 -0
- data/lib/ninjs-framework/core/application.js +17 -0
- data/lib/ninjs-framework/core/dom.js +164 -0
- data/lib/ninjs-framework/core/existence.js +60 -0
- data/lib/ninjs-framework/core/extend.js +14 -0
- data/lib/ninjs-framework/core/module.js +66 -0
- data/lib/ninjs-framework/core/nin.js +5 -0
- data/lib/ninjs-framework/extensions/jquery.elements.js +60 -0
- data/lib/ninjs-framework/templates/application.js.erb +3 -0
- data/lib/ninjs-framework/templates/autoload.js.erb +3 -0
- data/lib/ninjs-framework/templates/core.js.erb +3 -0
- data/lib/ninjs-framework/templates/dependency.js.erb +3 -0
- data/lib/ninjs-framework/templates/jasmine.yml.erb +75 -0
- data/lib/ninjs-framework/templates/test-index.html.erb +51 -0
- data/lib/ninjs-framework/utilities/all.js +5 -0
- data/lib/ninjs-framework/utilities/array.js +29 -0
- data/lib/ninjs-framework/utilities/cookie.js +59 -0
- data/lib/ninjs-framework/utilities/css.js +51 -0
- data/lib/ninjs-framework/utilities/number.js +11 -0
- data/lib/ninjs-framework/utilities/string.js +61 -0
- data/spec/fixtures/myapp.js +530 -0
- data/spec/fixtures/nin.js +297 -0
- data/spec/fixtures/ninjs.conf +9 -0
- data/spec/fixtures/test.elements.js +3 -0
- data/spec/fixtures/test.js +14 -0
- data/spec/fixtures/test.model.js +3 -0
- data/spec/fixtures/test.module.js +10 -0
- data/spec/fixtures/utilities.js +211 -0
- data/spec/javascripts/application_spec.js +22 -0
- data/spec/javascripts/array_utility_spec.js +49 -0
- data/spec/javascripts/existence_spec.js +71 -0
- data/spec/javascripts/extension_spec.js +22 -0
- data/spec/javascripts/helpers/SpecHelper.js +3 -0
- data/spec/javascripts/module_spec.js +30 -0
- data/spec/javascripts/string_utility_spec.js +85 -0
- data/spec/javascripts/support/jasmine.yml +75 -0
- data/spec/javascripts/support/jasmine_config.rb +23 -0
- data/spec/javascripts/support/jasmine_runner.rb +32 -0
- data/spec/ninjs_framework_spec.rb +121 -0
- data/spec/spec_helper.rb +41 -0
- data/spec/tmp/Rakefile +76 -0
- data/spec/tmp/application/myapp.js +530 -0
- data/spec/tmp/application/test.js +14 -0
- data/spec/tmp/elements/test.elements.js +3 -0
- data/spec/tmp/lib/nin.js +297 -0
- data/spec/tmp/lib/utilities.js +211 -0
- data/spec/tmp/models/test.model.js +3 -0
- data/spec/tmp/modules/test.module.js +10 -0
- data/spec/tmp/ninjs.conf +9 -0
- data/spec/tmp/spec/index.html +51 -0
- data/spec/tmp/spec/javascripts/application_spec.js +22 -0
- data/spec/tmp/spec/javascripts/array_utility_spec.js +49 -0
- data/spec/tmp/spec/javascripts/existence_spec.js +71 -0
- data/spec/tmp/spec/javascripts/extension_spec.js +22 -0
- data/spec/tmp/spec/javascripts/module_spec.js +30 -0
- data/spec/tmp/spec/javascripts/string_utility_spec.js +85 -0
- data/spec/tmp/spec/javascripts/support/jasmine-html.js +190 -0
- data/spec/tmp/spec/javascripts/support/jasmine.css +166 -0
- data/spec/tmp/spec/javascripts/support/jasmine.js +2476 -0
- data/spec/tmp/spec/javascripts/support/jasmine.yml.erb +75 -0
- data/spec/tmp/spec/javascripts/support/jasmine_config.rb +23 -0
- data/spec/tmp/spec/javascripts/support/jasmine_favicon.png +0 -0
- data/spec/tmp/spec/javascripts/support/jasmine_runner.rb +32 -0
- metadata +285 -0
@@ -0,0 +1,22 @@
|
|
1
|
+
describe("NinjsApplication", function() {
|
2
|
+
var app;
|
3
|
+
|
4
|
+
beforeEach(function() {
|
5
|
+
app = new NinjsApplication('myapp');
|
6
|
+
});
|
7
|
+
|
8
|
+
afterEach(function() {
|
9
|
+
app = undefined;
|
10
|
+
});
|
11
|
+
|
12
|
+
it("should create a ninjs application object", function() {
|
13
|
+
expect(is_defined(app)).toBeTruthy();
|
14
|
+
expect(is_typeof(NinjsApplication, app)).toBeTruthy();
|
15
|
+
});
|
16
|
+
|
17
|
+
it("should create a NinjsModule", function() {
|
18
|
+
app.add_module('mymod');
|
19
|
+
expect(is_typeof(NinjsModule, app.mymod)).toBeTruthy();
|
20
|
+
});
|
21
|
+
|
22
|
+
});
|
@@ -0,0 +1,49 @@
|
|
1
|
+
describe("Array Extensions", function() {
|
2
|
+
|
3
|
+
it("should test for emptiness with is_empty and not_empty", function() {
|
4
|
+
expect([].is_empty()).toBeTruthy();
|
5
|
+
expect(['one', 'two', 'three'].is_empty()).toBeFalsy();
|
6
|
+
expect(['one', 'two', 'three'].not_empty()).toBeTruthy();
|
7
|
+
expect([].not_empty()).toBeFalsy();
|
8
|
+
});
|
9
|
+
|
10
|
+
it("should iterate over each element with each", function() {
|
11
|
+
var iteration_count = 0,
|
12
|
+
test_array_values = [],
|
13
|
+
test_array_indices = [];
|
14
|
+
|
15
|
+
['one', 'two', 'three'].each(function(value, index) {
|
16
|
+
iteration_count++;
|
17
|
+
test_array_values.push(value);
|
18
|
+
test_array_indices.push(index);
|
19
|
+
});
|
20
|
+
|
21
|
+
expect(test_array_values[0]).toEqual('one');
|
22
|
+
expect(test_array_values[1]).toEqual('two');
|
23
|
+
expect(test_array_values[2]).toEqual('three');
|
24
|
+
|
25
|
+
expect(test_array_indices[0]).toEqual(0);
|
26
|
+
expect(test_array_indices[1]).toEqual(1);
|
27
|
+
expect(test_array_indices[2]).toEqual(2);
|
28
|
+
|
29
|
+
expect(iteration_count).toEqual(3);
|
30
|
+
});
|
31
|
+
|
32
|
+
it("should test if an array contains an element", function() {
|
33
|
+
var array = ['one', 'two', 'three'],
|
34
|
+
string = 'hello',
|
35
|
+
object = {
|
36
|
+
name: 'some object'
|
37
|
+
},
|
38
|
+
number = 45,
|
39
|
+
date = new Date(),
|
40
|
+
test_array = [array, string, object, number, date];
|
41
|
+
|
42
|
+
expect(test_array.contains(array)).toBeTruthy();
|
43
|
+
expect(test_array.contains(string)).toBeTruthy();
|
44
|
+
expect(test_array.contains(object)).toBeTruthy();
|
45
|
+
expect(test_array.contains(number)).toBeTruthy();
|
46
|
+
expect(test_array.contains(date)).toBeTruthy();
|
47
|
+
expect(test_array.contains('not in there')).toBeFalsy();
|
48
|
+
});
|
49
|
+
});
|
@@ -0,0 +1,71 @@
|
|
1
|
+
describe("Existence:", function() {
|
2
|
+
|
3
|
+
it("should test for existence with is_defined", function() {
|
4
|
+
var nonexistent;
|
5
|
+
var existent = 'I think';
|
6
|
+
expect(is_defined(existent)).toBeTruthy();
|
7
|
+
expect(is_defined(nonexistent)).toBeFalsy();
|
8
|
+
});
|
9
|
+
|
10
|
+
it("should test for non-existence with is_undefined", function() {
|
11
|
+
var existent = 'I think';
|
12
|
+
var nonexistent;
|
13
|
+
expect(is_undefined(nonexistent)).toBeTruthy();
|
14
|
+
expect(is_undefined(existent)).toBeFalsy();
|
15
|
+
});
|
16
|
+
|
17
|
+
it("should check for type strictly with is_typeof", function() {
|
18
|
+
var foo = function(){};
|
19
|
+
var bar = {
|
20
|
+
name: 'SomeObject',
|
21
|
+
method: function() {}
|
22
|
+
};
|
23
|
+
var SomeClass = function(){};
|
24
|
+
var some_instance = new SomeClass();
|
25
|
+
|
26
|
+
expect(is_typeof(Number, 4)).toBeTruthy();
|
27
|
+
expect(is_typeof(String, 'Hello World')).toBeTruthy();
|
28
|
+
expect(is_typeof(Array, ['one', 'two', 'three'])).toBeTruthy();
|
29
|
+
expect(is_typeof(Function, foo)).toBeTruthy();
|
30
|
+
expect(is_typeof(Object, bar)).toBeTruthy();
|
31
|
+
expect(is_typeof(RegExp, /pattern/)).toBeTruthy();
|
32
|
+
expect(is_typeof(SomeClass, some_instance)).toBeTruthy();
|
33
|
+
|
34
|
+
expect(is_typeof(Object, 4)).toBeFalsy();
|
35
|
+
expect(is_typeof(Object, 'Hello World')).toBeFalsy();
|
36
|
+
expect(is_typeof(Object, ['one', 'two', 'three'])).toBeFalsy();
|
37
|
+
expect(is_typeof(Object, foo)).toBeFalsy();
|
38
|
+
expect(is_typeof(Function, bar)).toBeFalsy();
|
39
|
+
expect(is_typeof(Object, some_instance)).toBeFalsy();
|
40
|
+
expect(is_typeof(Function, some_instance)).toBeFalsy();
|
41
|
+
});
|
42
|
+
|
43
|
+
it("should check for default types with convenience methods", function() {
|
44
|
+
var today = new Date();
|
45
|
+
var easy_as = [1,2,3];
|
46
|
+
var pattern = new RegExp(/pattern/);
|
47
|
+
|
48
|
+
expect(is_string('hello')).toBeTruthy();
|
49
|
+
expect(is_number(42)).toBeTruthy();
|
50
|
+
expect(is_array(easy_as)).toBeTruthy();
|
51
|
+
expect(is_bool(false)).toBeTruthy();
|
52
|
+
expect(is_date(today)).toBeTruthy();
|
53
|
+
expect(is_regex(pattern)).toBeTruthy();
|
54
|
+
|
55
|
+
expect(is_regex('hello')).toBeFalsy();
|
56
|
+
expect(is_date(42)).toBeFalsy();
|
57
|
+
expect(is_bool(easy_as)).toBeFalsy();
|
58
|
+
expect(is_array(today)).toBeFalsy();
|
59
|
+
expect(is_number(true)).toBeFalsy();
|
60
|
+
expect(is_string(pattern)).toBeFalsy();
|
61
|
+
});
|
62
|
+
|
63
|
+
it("should determine if a given string is numerical", function() {
|
64
|
+
expect(is_numeric(2)).toBeTruthy();
|
65
|
+
expect(is_numeric(-2)).toBeTruthy();
|
66
|
+
expect(is_numeric(45.6)).toBeTruthy();
|
67
|
+
expect(is_numeric(-45.6)).toBeTruthy();
|
68
|
+
expect(is_numeric('45.6')).toBeTruthy();
|
69
|
+
expect(is_numeric('Hello')).toBeFalsy();
|
70
|
+
});
|
71
|
+
});
|
@@ -0,0 +1,22 @@
|
|
1
|
+
describe("Extensions", function() {
|
2
|
+
it("should test a negated conditional with unless", function() {
|
3
|
+
var is_true = false,
|
4
|
+
does_fallback_work = false;
|
5
|
+
|
6
|
+
unless (false,
|
7
|
+
function() {
|
8
|
+
is_true = true;
|
9
|
+
}
|
10
|
+
);
|
11
|
+
|
12
|
+
unless (true,
|
13
|
+
function() {},
|
14
|
+
function() {
|
15
|
+
does_fallback_work = true;
|
16
|
+
}
|
17
|
+
);
|
18
|
+
|
19
|
+
expect(is_true).toBeTruthy();
|
20
|
+
expect(does_fallback_work).toBeTruthy();
|
21
|
+
});
|
22
|
+
});
|
@@ -0,0 +1,30 @@
|
|
1
|
+
describe("NinjsModule", function() {
|
2
|
+
|
3
|
+
var app;
|
4
|
+
|
5
|
+
beforeEach(function() {
|
6
|
+
app = new NinjsApplication('myapp');
|
7
|
+
});
|
8
|
+
|
9
|
+
it("should return the module when added", function() {
|
10
|
+
var module = app.add_module('mymod');
|
11
|
+
expect(module).toEqual(app.mymod);
|
12
|
+
});
|
13
|
+
|
14
|
+
it("should have the correct default values", function() {
|
15
|
+
app.add_module('testmodule');
|
16
|
+
// properties
|
17
|
+
expect(is_defined(app.testmodule.data)).toBeTruthy();
|
18
|
+
expect(is_defined(app.testmodule.name)).toBeTruthy();
|
19
|
+
expect(app.testmodule.name).toEqual('testmodule');
|
20
|
+
|
21
|
+
// methods
|
22
|
+
expect(is_defined(app.testmodule.actions)).toBeTruthy();
|
23
|
+
expect(is_typeof(Function, app.testmodule.actions)).toBeTruthy();
|
24
|
+
expect(is_defined(app.testmodule.run)).toBeTruthy();
|
25
|
+
expect(is_typeof(Function, app.testmodule.run)).toBeTruthy();
|
26
|
+
expect(is_defined(app.testmodule.execute)).toBeTruthy();
|
27
|
+
expect(is_defined(app.testmodule.elements)).toBeTruthy();
|
28
|
+
expect(is_defined(app.testmodule.set_data)).toBeTruthy();
|
29
|
+
});
|
30
|
+
});
|
@@ -0,0 +1,85 @@
|
|
1
|
+
describe("String utility tests", function() {
|
2
|
+
|
3
|
+
it("should test for emptiness with is_empty and not_empty", function() {
|
4
|
+
expect(''.is_empty()).toBeTruthy();
|
5
|
+
expect('hey there'.is_empty()).toBeFalsy();
|
6
|
+
expect('hey there'.not_empty()).toBeTruthy();
|
7
|
+
expect(''.not_empty()).toBeFalsy();
|
8
|
+
});
|
9
|
+
|
10
|
+
it("should test for a numeric value", function() {
|
11
|
+
expect('34'.is_numeric()).toBeTruthy();
|
12
|
+
expect('0.5'.is_numeric()).toBeTruthy();
|
13
|
+
expect('-34'.is_numeric()).toBeTruthy();
|
14
|
+
expect('-0.5'.is_numeric()).toBeTruthy();
|
15
|
+
expect('hello'.is_numeric()).toBeFalsy();
|
16
|
+
});
|
17
|
+
|
18
|
+
it("should trim a string with trim, ltrim, and rtrim", function() {
|
19
|
+
expect(' hello '.trim()).toEqual('hello');
|
20
|
+
expect(' hello '.ltrim()).toEqual('hello ');
|
21
|
+
expect(' hello '.rtrim()).toEqual(' hello');
|
22
|
+
});
|
23
|
+
|
24
|
+
it("should iterate over each character with each", function() {
|
25
|
+
var iteration_count = 0,
|
26
|
+
test_chars = [],
|
27
|
+
test_indices = [];
|
28
|
+
|
29
|
+
'123'.each(function(character, index) {
|
30
|
+
test_chars.push(character);
|
31
|
+
test_indices.push(index);
|
32
|
+
iteration_count++;
|
33
|
+
});
|
34
|
+
|
35
|
+
expect(test_chars[0]).toEqual('1');
|
36
|
+
expect(test_chars[1]).toEqual('2');
|
37
|
+
expect(test_chars[2]).toEqual('3');
|
38
|
+
|
39
|
+
expect(test_indices[0]).toEqual(0);
|
40
|
+
expect(test_indices[1]).toEqual(1);
|
41
|
+
expect(test_indices[2]).toEqual(2);
|
42
|
+
|
43
|
+
expect(iteration_count).toEqual(3);
|
44
|
+
});
|
45
|
+
|
46
|
+
it("should capitalize a String with capitalize", function() {
|
47
|
+
expect('hello world'.capitalize()).toEqual('Hello world');
|
48
|
+
});
|
49
|
+
|
50
|
+
it("should reverse a string with reverse", function() {
|
51
|
+
expect('hello world'.reverse()).toEqual('dlrow olleh');
|
52
|
+
expect('satan oscillate my metallic sonatas'.reverse()).toEqual('satanos cillatem ym etallicso natas');
|
53
|
+
});
|
54
|
+
|
55
|
+
it("should convert to a number", function() {
|
56
|
+
var whole_number = '32',
|
57
|
+
decimal = '0.08',
|
58
|
+
negative_number = '-32',
|
59
|
+
negative_float = '-0.08';
|
60
|
+
|
61
|
+
expect(whole_number.to_n()).toBe(32);
|
62
|
+
expect(decimal.to_n()).toBe(0.08);
|
63
|
+
expect(negative_number.to_n()).toBe(-32);
|
64
|
+
expect(negative_float.to_n()).toBe(-0.08);
|
65
|
+
});
|
66
|
+
|
67
|
+
it("should pluck all instances of a sup-string within a string", function() {
|
68
|
+
expect('one, two, three'.pluck(',')).toEqual('one two three');
|
69
|
+
});
|
70
|
+
|
71
|
+
it("should compress a string to single spaces", function() {
|
72
|
+
var hard_space = 'one two three four five six',
|
73
|
+
soft_space = 'one two three four five six',
|
74
|
+
mixed_space = 'one two three four five six';
|
75
|
+
|
76
|
+
expect(hard_space.single_space()).toBe('one two three four five six');
|
77
|
+
expect(soft_space.single_space()).toBe('one two three four five six');
|
78
|
+
expect(mixed_space.single_space()).toBe('one two three four five six');
|
79
|
+
});
|
80
|
+
|
81
|
+
it("should compress a string, removing all whitespace", function() {
|
82
|
+
var string = "satan\n\t oscillate\n\t my\n\t metallic\n sonatas";
|
83
|
+
expect(string.compress()).toBe('satanoscillatemymetallicsonatas');
|
84
|
+
});
|
85
|
+
});
|
@@ -0,0 +1,75 @@
|
|
1
|
+
# src_files
|
2
|
+
#
|
3
|
+
# Return an array of filepaths relative to src_dir to include before jasmine specs.
|
4
|
+
# Default: []
|
5
|
+
#
|
6
|
+
# EXAMPLE:
|
7
|
+
#
|
8
|
+
# src_files:
|
9
|
+
# - lib/source1.js
|
10
|
+
# - lib/source2.js
|
11
|
+
# - dist/**/*.js
|
12
|
+
#
|
13
|
+
src_files:
|
14
|
+
- lib/core/*.js
|
15
|
+
- lib/extensions/*.js
|
16
|
+
- lib/utilities/*.js
|
17
|
+
|
18
|
+
# stylesheets
|
19
|
+
#
|
20
|
+
# Return an array of stylesheet filepaths relative to src_dir to include before jasmine specs.
|
21
|
+
# Default: []
|
22
|
+
#
|
23
|
+
# EXAMPLE:
|
24
|
+
#
|
25
|
+
# stylesheets:
|
26
|
+
# - css/style.css
|
27
|
+
# - stylesheets/*.css
|
28
|
+
#
|
29
|
+
stylesheets:
|
30
|
+
|
31
|
+
# helpers
|
32
|
+
#
|
33
|
+
# Return an array of filepaths relative to spec_dir to include before jasmine specs.
|
34
|
+
# Default: ["helpers/**/*.js"]
|
35
|
+
#
|
36
|
+
# EXAMPLE:
|
37
|
+
#
|
38
|
+
# helpers:
|
39
|
+
# - helpers/**/*.js
|
40
|
+
#
|
41
|
+
helpers:
|
42
|
+
|
43
|
+
# spec_files
|
44
|
+
#
|
45
|
+
# Return an array of filepaths relative to spec_dir to include.
|
46
|
+
# Default: ["**/*[sS]pec.js"]
|
47
|
+
#
|
48
|
+
# EXAMPLE:
|
49
|
+
#
|
50
|
+
# spec_files:
|
51
|
+
# - **/*[sS]pec.js
|
52
|
+
#
|
53
|
+
spec_files:
|
54
|
+
|
55
|
+
# src_dir
|
56
|
+
#
|
57
|
+
# Source directory path. Your src_files must be returned relative to this path. Will use root if left blank.
|
58
|
+
# Default: project root
|
59
|
+
#
|
60
|
+
# EXAMPLE:
|
61
|
+
#
|
62
|
+
# src_dir: public
|
63
|
+
#
|
64
|
+
src_dir:
|
65
|
+
|
66
|
+
# spec_dir
|
67
|
+
#
|
68
|
+
# Spec directory path. Your spec_files must be returned relative to this path.
|
69
|
+
# Default: spec/javascripts
|
70
|
+
#
|
71
|
+
# EXAMPLE:
|
72
|
+
#
|
73
|
+
# spec_dir: spec/javascripts
|
74
|
+
#
|
75
|
+
spec_dir:
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Jasmine
|
2
|
+
class Config
|
3
|
+
|
4
|
+
# Add your overrides or custom config code here
|
5
|
+
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
|
10
|
+
# Note - this is necessary for rspec2, which has removed the backtrace
|
11
|
+
module Jasmine
|
12
|
+
class SpecBuilder
|
13
|
+
def declare_spec(parent, spec)
|
14
|
+
me = self
|
15
|
+
example_name = spec["name"]
|
16
|
+
@spec_ids << spec["id"]
|
17
|
+
backtrace = @example_locations[parent.description + " " + example_name]
|
18
|
+
parent.it example_name, {} do
|
19
|
+
me.report_spec(spec["id"])
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
$:.unshift(ENV['JASMINE_GEM_PATH']) if ENV['JASMINE_GEM_PATH'] # for gem testing purposes
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'jasmine'
|
5
|
+
jasmine_config_overrides = File.expand_path(File.join(File.dirname(__FILE__), 'jasmine_config.rb'))
|
6
|
+
require jasmine_config_overrides if File.exist?(jasmine_config_overrides)
|
7
|
+
if Jasmine::rspec2?
|
8
|
+
require 'rspec'
|
9
|
+
else
|
10
|
+
require 'spec'
|
11
|
+
end
|
12
|
+
|
13
|
+
jasmine_config = Jasmine::Config.new
|
14
|
+
spec_builder = Jasmine::SpecBuilder.new(jasmine_config)
|
15
|
+
|
16
|
+
should_stop = false
|
17
|
+
|
18
|
+
if Jasmine::rspec2?
|
19
|
+
RSpec.configuration.after(:suite) do
|
20
|
+
spec_builder.stop if should_stop
|
21
|
+
end
|
22
|
+
else
|
23
|
+
Spec::Runner.configure do |config|
|
24
|
+
config.after(:suite) do
|
25
|
+
spec_builder.stop if should_stop
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
spec_builder.start
|
31
|
+
should_stop = true
|
32
|
+
spec_builder.declare_suites
|
@@ -0,0 +1,121 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe NinjsFramework do
|
4
|
+
|
5
|
+
before :each do
|
6
|
+
@fw = NinjsFramework.new
|
7
|
+
end
|
8
|
+
|
9
|
+
it 'should have the correct defaults' do
|
10
|
+
@fw.defaults.should == {
|
11
|
+
name: 'application',
|
12
|
+
framework: 'ninjs',
|
13
|
+
src_dir: 'modules',
|
14
|
+
dest_dir: 'application',
|
15
|
+
asset_root: '../',
|
16
|
+
output: 'expanded',
|
17
|
+
dependencies: ['<jquery/latest>'],
|
18
|
+
autoload: ['../lib/utilities'],
|
19
|
+
module_alias: 'm'
|
20
|
+
}
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'should have the correct manifest' do
|
24
|
+
@fw.manifest.should == [
|
25
|
+
'application',
|
26
|
+
'elements',
|
27
|
+
'lib',
|
28
|
+
'models',
|
29
|
+
'modules',
|
30
|
+
'plugins',
|
31
|
+
'spec',
|
32
|
+
'spec/javascripts',
|
33
|
+
'spec/javascripts/support'
|
34
|
+
]
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'should have the correct name' do
|
38
|
+
@fw.name.should == 'ninjs'
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'should have a template_dir' do
|
42
|
+
@fw.template_dir.should == "#{LIB}/ninjs-framework/templates"
|
43
|
+
end
|
44
|
+
|
45
|
+
context 'Using Ninjs::Project' do
|
46
|
+
|
47
|
+
before :each do
|
48
|
+
FileUtils.mkdir TMP_DIR unless File.exists? TMP_DIR
|
49
|
+
@project = Ninjs::Project.new(name: 'myapp', root: TMP_DIR, framework: NinjsFramework)
|
50
|
+
suppress_output { @project.create }
|
51
|
+
end
|
52
|
+
|
53
|
+
after :each do
|
54
|
+
FileUtils.rm_rf "#{TMP_DIR}" if File.exists? TMP_DIR
|
55
|
+
end
|
56
|
+
|
57
|
+
it 'should create the default scaffold' do
|
58
|
+
File.directory?("#{TMP_DIR}/application").should be_true
|
59
|
+
File.directory?("#{TMP_DIR}/elements").should be_true
|
60
|
+
File.directory?("#{TMP_DIR}/lib").should be_true
|
61
|
+
File.directory?("#{TMP_DIR}/models").should be_true
|
62
|
+
File.directory?("#{TMP_DIR}/modules").should be_true
|
63
|
+
File.directory?("#{TMP_DIR}/plugins").should be_true
|
64
|
+
File.directory?("#{TMP_DIR}/spec").should be_true
|
65
|
+
File.directory?("#{TMP_DIR}/spec/javascripts").should be_true
|
66
|
+
File.directory?("#{TMP_DIR}/spec/javascripts/support").should be_true
|
67
|
+
end
|
68
|
+
|
69
|
+
it 'should create a config file' do
|
70
|
+
File.exists?("#{TMP_DIR}/ninjs.conf").should be_true
|
71
|
+
"#{TMP_DIR}/ninjs.conf".should be_same_file_as "#{FIXTURES}/ninjs.conf"
|
72
|
+
end
|
73
|
+
|
74
|
+
it 'should create a lib/nin.js file' do
|
75
|
+
File.exists?("#{TMP_DIR}/lib/nin.js").should be_true
|
76
|
+
"#{TMP_DIR}/lib/nin.js".should be_same_file_as "#{FIXTURES}/nin.js"
|
77
|
+
end
|
78
|
+
|
79
|
+
it 'should create a lib/utilities.js file' do
|
80
|
+
File.exists?("#{TMP_DIR}/lib/utilities.js").should be_true
|
81
|
+
"#{TMP_DIR}/lib/utilities.js".should be_same_file_as "#{FIXTURES}/utilities.js"
|
82
|
+
end
|
83
|
+
|
84
|
+
it 'should create an application.js file' do
|
85
|
+
File.exists?("#{TMP_DIR}/application/myapp.js").should be_true
|
86
|
+
File.read("#{TMP_DIR}/application/myapp.js").match(/var\smyapp\s\=\snew\sNinjsApplication\(\)\;/).should be_true
|
87
|
+
end
|
88
|
+
|
89
|
+
it 'should import the Rakefile' do
|
90
|
+
File.exists?("#{TMP_DIR}/Rakefile").should be_true
|
91
|
+
end
|
92
|
+
|
93
|
+
it 'should import the spec support files' do
|
94
|
+
File.exists?("#{TMP_DIR}/spec/javascripts/support/jasmine_favicon.png").should be_true
|
95
|
+
File.exists?("#{TMP_DIR}/spec/javascripts/support/jasmine.css").should be_true
|
96
|
+
File.exists?("#{TMP_DIR}/spec/javascripts/support/jasmine.js").should be_true
|
97
|
+
File.exists?("#{TMP_DIR}/spec/javascripts/support/jasmine-html.js").should be_true
|
98
|
+
end
|
99
|
+
|
100
|
+
it 'should import the spec files' do
|
101
|
+
File.exists?("#{TMP_DIR}/spec/javascripts/application_spec.js").should be_true
|
102
|
+
File.exists?("#{TMP_DIR}/spec/javascripts/array_utility_spec.js").should be_true
|
103
|
+
File.exists?("#{TMP_DIR}/spec/javascripts/existence_spec.js").should be_true
|
104
|
+
File.exists?("#{TMP_DIR}/spec/javascripts/extension_spec.js").should be_true
|
105
|
+
File.exists?("#{TMP_DIR}/spec/javascripts/module_spec.js").should be_true
|
106
|
+
File.exists?("#{TMP_DIR}/spec/javascripts/string_utility_spec.js").should be_true
|
107
|
+
File.exists?("#{TMP_DIR}/spec/javascripts/support/jasmine_config.rb").should be_true
|
108
|
+
File.exists?("#{TMP_DIR}/spec/javascripts/support/jasmine_runner.rb").should be_true
|
109
|
+
end
|
110
|
+
|
111
|
+
it 'should update an application' do
|
112
|
+
FileUtils.cp "#{FIXTURES}/test.module.js", "#{TMP_DIR}/modules"
|
113
|
+
FileUtils.cp "#{FIXTURES}/test.elements.js", "#{TMP_DIR}/elements"
|
114
|
+
FileUtils.cp "#{FIXTURES}/test.model.js", "#{TMP_DIR}/models"
|
115
|
+
suppress_output { @project.update }
|
116
|
+
"#{TMP_DIR}/application/myapp.js".should be_same_file_as "#{FIXTURES}/myapp.js"
|
117
|
+
File.exists?("#{TMP_DIR}/application/test.js").should be_true
|
118
|
+
"#{TMP_DIR}/application/test.js".should be_same_file_as "#{FIXTURES}/test.js"
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|