modjs-architecture 0.0.0 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (39) hide show
  1. data/.travis.yml +2 -0
  2. data/Gemfile +9 -3
  3. data/Gemfile.lock +49 -13
  4. data/{README.rdoc → README.md} +6 -4
  5. data/Rakefile +25 -4
  6. data/VERSION +1 -1
  7. data/lib/modjs-architecture.rb +122 -0
  8. data/lib/modjs-architecture/core/application.js +29 -0
  9. data/lib/modjs-architecture/core/dom.js +84 -0
  10. data/lib/modjs-architecture/core/module.js +65 -0
  11. data/lib/modjs-architecture/extensions/events.js +84 -0
  12. data/lib/modjs-architecture/helpers/existence.js +62 -0
  13. data/lib/modjs-architecture/jasmine/MIT.LICENSE +20 -0
  14. data/lib/modjs-architecture/jasmine/index.html +50 -0
  15. data/lib/modjs-architecture/jasmine/jasmine-html.js +190 -0
  16. data/lib/modjs-architecture/jasmine/jasmine.css +166 -0
  17. data/lib/modjs-architecture/jasmine/jasmine.js +2476 -0
  18. data/lib/modjs-architecture/jasmine/jasmine_favicon.png +0 -0
  19. data/lib/modjs-architecture/lib/mod.js +320 -0
  20. data/lib/modjs-architecture/modjs.architecture +6 -0
  21. data/lib/modjs-architecture/src/mod.js +9 -0
  22. data/modjs-architecture.gemspec +92 -0
  23. data/spec/fixtures/myapp.architecture +8 -0
  24. data/spec/fixtures/myapp.js +322 -0
  25. data/spec/fixtures/test.js +1 -0
  26. data/spec/fixtures/test.module.js +1 -0
  27. data/spec/fixtures/update.architecture +8 -0
  28. data/spec/fixtures/update.js +329 -0
  29. data/spec/javascripts/application_spec.js +23 -0
  30. data/spec/javascripts/dom_spec.js +49 -0
  31. data/spec/javascripts/existence_spec.js +143 -0
  32. data/spec/javascripts/module_spec.js +76 -0
  33. data/spec/javascripts/support/jasmine.css +229 -0
  34. data/spec/javascripts/support/jasmine.yml +73 -0
  35. data/spec/javascripts/support/jasmine_config.rb +23 -0
  36. data/spec/javascripts/support/jasmine_runner.rb +32 -0
  37. data/spec/modjs-architecture_spec.rb +97 -4
  38. data/spec/spec_helper.rb +39 -8
  39. metadata +61 -22
@@ -0,0 +1,76 @@
1
+ describe("Mod.Module", function() {
2
+ var module;
3
+
4
+ beforeEach(function() {
5
+ module = new Mod.Module('foo');
6
+ });
7
+
8
+ it("should require a name", function() {
9
+ expect(function() {
10
+ var x = new Mod.Module;
11
+ }).toThrow("Mod.Module(name): name is undefined");
12
+ });
13
+
14
+ it("should have a dom attribute", function() {
15
+ expect(module.dom.constructor).toEqual(Mod.DOM);
16
+ });
17
+
18
+ it("should have a name attribute", function() {
19
+ expect(module.name).toEqual('foo');
20
+ });
21
+
22
+ it("should have a data attribute", function() {
23
+ expect(module.data).toEqual({});
24
+ });
25
+
26
+ it("should add data with set_data", function() {
27
+ module.set_data({
28
+ one: 'one',
29
+ two: 'two'
30
+ });
31
+ module.set_data('three', 'three');
32
+ expect(module.data.one).toEqual('one');
33
+ expect(module.data.two).toEqual('two');
34
+ expect(module.data.three).toEqual('three');
35
+ });
36
+
37
+ it("should have an actions method", function() {
38
+ expect(module.actions).toBeTruthy();
39
+ });
40
+
41
+ it("should have an execute method to call the actions", function() {
42
+ module.actions = function() {
43
+ this.set_data('actions_did_run', true);
44
+ };
45
+ module.execute();
46
+ expect(module.data.actions_did_run).toBeTruthy();
47
+ });
48
+
49
+ it("should have an elements method to cache DOM elements", function() {
50
+ module.elements({
51
+ body: document.getElementsByTagName('body')[0],
52
+ jasmine_content: document.getElementById('jasmine_content')
53
+ });
54
+ expect(module.elements('body')).toEqual(document.getElementsByTagName('body')[0]);
55
+ expect(module.elements('jasmine_content')).toEqual(document.getElementById('jasmine_content'));
56
+ });
57
+
58
+ it("should get all the elements", function() {
59
+ module.elements({
60
+ body: document.getElementsByTagName('body')[0],
61
+ jasmine_content: document.getElementById('jasmine_content')
62
+ });
63
+ expect(module.elements()).toEqual({
64
+ body: document.getElementsByTagName('body')[0],
65
+ jasmine_content: document.getElementById('jasmine_content')
66
+ });
67
+ });
68
+
69
+ it("should run the execute method when the dom is ready", function() {
70
+ module.actions = function() {
71
+ this.set_data('actions_did_run', true);
72
+ expect(module.data.actions_did_run).toBeTruthy();
73
+ };
74
+ module.run();
75
+ });
76
+ });
@@ -0,0 +1,229 @@
1
+ body {
2
+ padding: 1em;
3
+ margin: 0;
4
+ font-family: Arial, "Helvetica Neue", Helvetica, sans-serif;
5
+ }
6
+
7
+ .left-icon, .suite.passed > .description, .suite.failed > .description {
8
+ padding: 0 0 0 20px;
9
+ }
10
+
11
+ .rounded, .spec.failed {
12
+ -moz-border-radius: 5px;
13
+ -webkit-border-radius: 5px;
14
+ -o-border-radius: 5px;
15
+ -ms-border-radius: 5px;
16
+ -khtml-border-radius: 5px;
17
+ border-radius: 5px;
18
+ }
19
+
20
+ .banner {
21
+ overflow: hidden;
22
+ padding: 0.5em;
23
+ margin: 0 0 0.5em 0;
24
+ border-bottom: solid 2px #666;
25
+ }
26
+
27
+ .logo {
28
+ float: left;
29
+ display: inline-block;
30
+ background: url("images/jasmine_favicon.png") no-repeat;
31
+ padding: 0 0 0 18px;
32
+ }
33
+
34
+ .logo .title {
35
+ font-size: 24px;
36
+ color: #6c5e4b;
37
+ }
38
+
39
+ .options {
40
+ color: transparent;
41
+ }
42
+
43
+ .options label {
44
+ color: #666666;
45
+ }
46
+
47
+ .version {
48
+ color: #666666;
49
+ display: inline-block;
50
+ color: #6c5e4b;
51
+ margin: 0 0 0 1em;
52
+ font-size: 0.75em;
53
+ }
54
+
55
+ .options {
56
+ float: right;
57
+ }
58
+
59
+ .run_spec {
60
+ float: right;
61
+ color: #666666;
62
+ }
63
+
64
+ .runner {
65
+ margin: 0 0 1.5em 0;
66
+ }
67
+
68
+ .runner .description {
69
+ text-decoration: none;
70
+ color: #333;
71
+ }
72
+
73
+ .runner.passed {
74
+ border-color: #49C267;
75
+ }
76
+
77
+ .runner.passed .description {
78
+ text-decoration: none;
79
+ color: #49C267;
80
+ font-weight: bold;
81
+ }
82
+
83
+ .runner.failed .description {
84
+ text-decoration: none;
85
+ color: red;
86
+ font-weight: bold;
87
+ }
88
+
89
+ .runner .finished-at {
90
+ float: right;
91
+ font-size: 0.75em;
92
+ }
93
+
94
+ .runner .run_spec {
95
+ background: url("images/icons.png") 0px -130px no-repeat;
96
+ float: left;
97
+ text-indent: -999em;
98
+ margin: 0 0 0 0.5em;
99
+ }
100
+
101
+ .runner .finished-at {
102
+ color: #666666;
103
+ }
104
+
105
+ .suite {
106
+ padding: 0;
107
+ border-bottom: none;
108
+ }
109
+
110
+ .suite.skipped {
111
+ display: none;
112
+ }
113
+
114
+ .suite > .description {
115
+ color: #666666;
116
+ display: block;
117
+ text-decoration: none;
118
+ background: url("images/icons.png") no-repeat;
119
+ background-position: 0px -999em;
120
+ }
121
+
122
+ .suite.passed {
123
+ border-color: #49c267;
124
+ }
125
+
126
+ .suite.passed > .description {
127
+ color: #666666;
128
+ background-position: 0px -26px;
129
+ }
130
+
131
+ .suite.passed > .description:hover {
132
+ color: #49c267;
133
+ }
134
+
135
+ .suite.failed {
136
+ border-color: red;
137
+ }
138
+
139
+ .suite.failed > .description {
140
+ color: red;
141
+ background-position: 0px -78px;
142
+ }
143
+
144
+ .suite.skipped > .description {
145
+ color: #999;
146
+ background-position: 0px -52px;
147
+ padding: 0 0 0 20px;
148
+ }
149
+
150
+ .suite .run_spec {
151
+ display: none;
152
+ }
153
+
154
+ .spec {
155
+ padding: 0.125em 0;
156
+ margin: 0 0 0 1.25em;
157
+ background: url("images/icons.png") no-repeat;
158
+ background-position: 0px -999em;
159
+ }
160
+
161
+ .spec:last-child {
162
+ padding-bottom: 0;
163
+ }
164
+
165
+ .spec.passed {
166
+ display: none;
167
+ padding-left: 18px;
168
+ background-position: 0px 3px;
169
+ }
170
+
171
+ .spec.passed a {
172
+ color: #666666;
173
+ text-decoration: none;
174
+ }
175
+
176
+ .spec.passed a:hover {
177
+ color: #49c267;
178
+ }
179
+
180
+ .spec.failed {
181
+ margin: 0.25em 0 0 0;
182
+ border: solid 2px #ff0000;
183
+ padding: 0.25em 0.5em;
184
+ }
185
+
186
+ .spec.failed a {
187
+ color: red;
188
+ font-weight: bold;
189
+ text-decoration: none;
190
+ }
191
+
192
+ .spec.skipped {
193
+ display: none;
194
+ }
195
+
196
+ .spec.skipped a {
197
+ color: #999;
198
+ text-decoration: none;
199
+ }
200
+
201
+ .resultMessage.fail {
202
+ font-size: 1.25em;
203
+ font-weight: bold;
204
+ color: red;
205
+ margin: 0.75em 0 0 0;
206
+ }
207
+
208
+ .stackTrace {
209
+ font-family: Monaco, "Bitstream Vera Sans Mono", "Lucida Console", Terminal, monospace;
210
+ font-size: 0.7em;
211
+ padding: 0.75em 0;
212
+ color: #666666;
213
+ }
214
+
215
+ .show-skipped .spec.skipped {
216
+ display: block;
217
+ }
218
+
219
+ .show-skipped .suite.skipped {
220
+ display: block;
221
+ }
222
+
223
+ .show-passed .spec.passed {
224
+ display: block;
225
+ }
226
+
227
+ .show-passed .suite {
228
+ padding: 0.25em 0 0.5em 0;
229
+ }
@@ -0,0 +1,73 @@
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/modjs-architecture/lib/**/*.js
15
+
16
+ # stylesheets
17
+ #
18
+ # Return an array of stylesheet filepaths relative to src_dir to include before jasmine specs.
19
+ # Default: []
20
+ #
21
+ # EXAMPLE:
22
+ #
23
+ # stylesheets:
24
+ # - css/style.css
25
+ # - stylesheets/*.css
26
+ #
27
+ stylesheets:
28
+ - spec/javascripts/support/jasmine.css
29
+ # helpers
30
+ #
31
+ # Return an array of filepaths relative to spec_dir to include before jasmine specs.
32
+ # Default: ["helpers/**/*.js"]
33
+ #
34
+ # EXAMPLE:
35
+ #
36
+ # helpers:
37
+ # - helpers/**/*.js
38
+ #
39
+ helpers:
40
+
41
+ # spec_files
42
+ #
43
+ # Return an array of filepaths relative to spec_dir to include.
44
+ # Default: ["**/*[sS]pec.js"]
45
+ #
46
+ # EXAMPLE:
47
+ #
48
+ # spec_files:
49
+ # - **/*[sS]pec.js
50
+ #
51
+ spec_files:
52
+
53
+ # src_dir
54
+ #
55
+ # Source directory path. Your src_files must be returned relative to this path. Will use root if left blank.
56
+ # Default: project root
57
+ #
58
+ # EXAMPLE:
59
+ #
60
+ # src_dir: public
61
+ #
62
+ src_dir:
63
+
64
+ # spec_dir
65
+ #
66
+ # Spec directory path. Your spec_files must be returned relative to this path.
67
+ # Default: spec/javascripts
68
+ #
69
+ # EXAMPLE:
70
+ #
71
+ # spec_dir: spec/javascripts
72
+ #
73
+ 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::Dependencies.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::Dependencies.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
@@ -1,7 +1,100 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
1
+ require "spec_helper.rb"
2
2
 
3
- describe "ModjsArchitecture" do
4
- it "fails" do
5
- fail "hey buddy, you should probably rename this file and start specing for real"
3
+ describe ModJS::Project do
4
+
5
+ describe "defaults" do
6
+
7
+ before :each do
8
+ suppress_output { @project = ModJS::Project.new( { name: 'myapp' }, TMP_DIR) }
9
+ end
10
+
11
+ it 'should have a BASE_DIR constant' do
12
+ ModJS::BASE_DIR = MODJS_ROOT
13
+ end
14
+
15
+ it 'should have the correct directories' do
16
+ @project.directories.should == %w'application elements lib models modules plugins spec'
17
+ end
18
+ end
19
+
20
+ describe 'project creation' do
21
+ before :each do
22
+ suppress_output do
23
+ @project = ModJS::Project.new( { name: 'myapp' }, TMP_DIR)
24
+ @project.create
25
+ end
26
+ end
27
+
28
+ after :each do
29
+ FileUtils.rm_rf(TMP_DIR)
30
+ end
31
+
32
+ it 'should create the modjs directories' do
33
+ File.exists?("#{TMP_DIR}/application").should be_true
34
+ File.exists?("#{TMP_DIR}/elements").should be_true
35
+ File.exists?("#{TMP_DIR}/lib").should be_true
36
+ File.exists?("#{TMP_DIR}/models").should be_true
37
+ File.exists?("#{TMP_DIR}/modules").should be_true
38
+ File.exists?("#{TMP_DIR}/plugins").should be_true
39
+ File.exists?("#{TMP_DIR}/spec").should be_true
40
+ end
41
+
42
+ it 'should create the architecture file' do
43
+ File.exists?("#{TMP_DIR}/myapp.architecture").should be_true
44
+ "#{TMP_DIR}/myapp.architecture".should be_same_file_as "#{FIXTURES}/myapp.architecture"
45
+ end
46
+
47
+ it 'should create an application file in the build_dir' do
48
+ "#{TMP_DIR}/application/myapp.js".should be_same_file_as "#{FIXTURES}/myapp.js"
49
+ end
50
+
51
+ it 'should copy the core library into the lib folder' do
52
+ "#{TMP_DIR}/lib/mod.js".should be_same_file_as "#{ModJS::LIB_DIR}/mod.js"
53
+ end
54
+
55
+ it 'should copy the jasmine tests into the spec folder' do
56
+ "#{TMP_DIR}/spec/application_spec.js".should be_same_file_as "#{SPEC_DIR}/javascripts/application_spec.js"
57
+ "#{TMP_DIR}/spec/dom_spec.js".should be_same_file_as "#{SPEC_DIR}/javascripts/dom_spec.js"
58
+ "#{TMP_DIR}/spec/existence_spec.js".should be_same_file_as "#{SPEC_DIR}/javascripts/existence_spec.js"
59
+ "#{TMP_DIR}/spec/module_spec.js".should be_same_file_as "#{SPEC_DIR}/javascripts/module_spec.js"
60
+ File.exists?("#{TMP_DIR}/spec/jasmine").should be_true
61
+
62
+ File.exists?("#{TMP_DIR}/spec/jasmine/jasmine-html.js").should be_true
63
+ File.exists?("#{TMP_DIR}/spec/jasmine/jasmine.css").should be_true
64
+ File.exists?("#{TMP_DIR}/spec/jasmine/jasmine.js").should be_true
65
+ File.exists?("#{TMP_DIR}/spec/jasmine/jasmine_favicon.png").should be_true
66
+ File.exists?("#{TMP_DIR}/spec/jasmine/MIT.LICENSE").should be_true
67
+ File.exists?("#{TMP_DIR}/spec/jasmine/index.html").should be_true
68
+ end
69
+ end
70
+
71
+ describe 'project update' do
72
+
73
+ before :each do
74
+ suppress_output do
75
+ @project = ModJS::Project.new( { name: 'myapp' }, TMP_DIR)
76
+ @project.create
77
+ end
78
+
79
+ FileUtils.rm_rf "#{TMP_DIR}/myapp.architecture"
80
+ FileUtils.cp "#{FIXTURES}/update.architecture", "#{TMP_DIR}/myapp.architecture"
81
+ FileUtils.cp "#{FIXTURES}/test.module.js", "#{TMP_DIR}/modules/test.module.js"
82
+
83
+ suppress_output do
84
+ @project.update
85
+ end
86
+ end
87
+
88
+ after :each do
89
+ FileUtils.rm_rf(TMP_DIR)
90
+ end
91
+
92
+ it 'should compile the application file' do
93
+ "#{TMP_DIR}/application/myapp.js".should be_same_file_as "#{FIXTURES}/update.js"
94
+ end
95
+
96
+ it 'should compile the test module' do
97
+ "#{TMP_DIR}/application/test.js".should be_same_file_as "#{FIXTURES}/test.js"
98
+ end
6
99
  end
7
100
  end