jsus 0.1.4 → 0.1.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/CHANGELOG +5 -0
- data/Manifest +6 -2
- data/Rakefile +1 -1
- data/bin/jsus +1 -0
- data/jsus.gemspec +4 -4
- data/lib/jsus.rb +10 -2
- data/lib/jsus/container.rb +56 -19
- data/lib/jsus/package.rb +99 -35
- data/lib/jsus/packager.rb +17 -2
- data/lib/jsus/pool.rb +96 -23
- data/lib/jsus/source_file.rb +170 -36
- data/lib/jsus/tag.rb +142 -0
- data/spec/data/Basic/app/javascripts/Orwik/package.yml +1 -1
- data/spec/data/Extensions/app/javascripts/Core/Source/Class.js +13 -0
- data/spec/data/Extensions/app/javascripts/Core/package.yml +8 -0
- data/spec/data/Extensions/app/javascripts/Orwik/Extensions/Class.js +16 -0
- data/spec/data/Extensions/app/javascripts/Orwik/package.yml +8 -0
- data/spec/data/ExternalDependencies/app/javascripts/Orwik/Source/Test.js +1 -0
- data/spec/data/ExternalDependencies/app/javascripts/Orwik/package.yml +1 -1
- data/spec/data/test_source_one.js +5 -2
- data/spec/lib/jsus/package_spec.rb +26 -9
- data/spec/lib/jsus/pool_spec.rb +38 -1
- data/spec/lib/jsus/source_file_spec.rb +184 -29
- data/spec/lib/jsus/tag_spec.rb +122 -0
- metadata +11 -7
- data/lib/jsus/topsortable.rb +0 -29
- data/spec/lib/jsus/topsortable_spec.rb +0 -51
@@ -24,17 +24,16 @@ describe Jsus::Package do
|
|
24
24
|
end
|
25
25
|
|
26
26
|
it "should set provided modules from source files" do
|
27
|
-
subject.provides.should have_exactly(4).items
|
28
|
-
subject.
|
27
|
+
subject.provides.should have_exactly(4).items
|
28
|
+
subject.provides_names.should include("Color", "Input", "Input.Color", "Widget")
|
29
29
|
end
|
30
30
|
|
31
31
|
it "should set up outside dependencies" do
|
32
|
-
subject.
|
32
|
+
subject.dependencies_names.should == ['core/Class']
|
33
33
|
end
|
34
34
|
|
35
|
-
it "should set directory
|
35
|
+
it "should set directory field" do
|
36
36
|
subject.directory.should == File.expand_path(input_dir)
|
37
|
-
subject.relative_directory.should == input_dir
|
38
37
|
end
|
39
38
|
end
|
40
39
|
end
|
@@ -54,7 +53,7 @@ describe Jsus::Package do
|
|
54
53
|
subject.generate_scripts_info(output_dir)
|
55
54
|
File.exists?("#{output_dir}/scripts.json").should be_true
|
56
55
|
info = JSON.parse(IO.read("#{output_dir}/scripts.json"))
|
57
|
-
info = info["
|
56
|
+
info = info["Orwik"]
|
58
57
|
info["provides"].should have_exactly(4).items
|
59
58
|
info["provides"].should include("Color", "Widget", "Input", "Input.Color")
|
60
59
|
end
|
@@ -68,7 +67,7 @@ describe Jsus::Package do
|
|
68
67
|
subject.include_dependencies!
|
69
68
|
subject.generate_scripts_info(output_dir)
|
70
69
|
info = JSON.parse(IO.read("#{output_dir}/scripts.json"))
|
71
|
-
info = info["
|
70
|
+
info = info["Orwik"]
|
72
71
|
info["provides"].should have_exactly(4).items
|
73
72
|
info["provides"].should include("Test", "Hash/Hash", "Class/Class", 'Mash/Mash')
|
74
73
|
end
|
@@ -77,8 +76,8 @@ describe Jsus::Package do
|
|
77
76
|
subject.include_dependencies!
|
78
77
|
subject.generate_scripts_info(output_dir)
|
79
78
|
info = JSON.parse(IO.read("#{output_dir}/scripts.json"))
|
80
|
-
info = info["
|
81
|
-
info["requires"].should == []
|
79
|
+
info = info["Orwik"]
|
80
|
+
info["requires"].should == ["Class"]
|
82
81
|
end
|
83
82
|
end
|
84
83
|
end
|
@@ -114,6 +113,11 @@ describe Jsus::Package do
|
|
114
113
|
input_index.should < input_color_index
|
115
114
|
color_index.should < input_color_index
|
116
115
|
end
|
116
|
+
|
117
|
+
it "should not include extensions" do
|
118
|
+
required_files = Jsus::Package.new("spec/data/Extensions/app/javascripts/Orwik").required_files
|
119
|
+
required_files.should be_empty
|
120
|
+
end
|
117
121
|
end
|
118
122
|
|
119
123
|
describe "#include_dependencies!" do
|
@@ -130,4 +134,17 @@ describe Jsus::Package do
|
|
130
134
|
end
|
131
135
|
end
|
132
136
|
end
|
137
|
+
|
138
|
+
describe "#include_extensions!" do
|
139
|
+
let(:lib_dir) { "spec/data/Extensions/app/javascripts" }
|
140
|
+
let(:pool) { Jsus::Pool.new(lib_dir) }
|
141
|
+
subject { Jsus::Package.new("spec/data/Extensions/app/javascripts/Core", :pool => pool) }
|
142
|
+
|
143
|
+
it "should include extensions into source files" do
|
144
|
+
subject.source_files[0].extensions.should be_empty
|
145
|
+
subject.include_extensions!
|
146
|
+
subject.source_files[0].extensions.should have_exactly(1).item
|
147
|
+
end
|
148
|
+
|
149
|
+
end
|
133
150
|
end
|
data/spec/lib/jsus/pool_spec.rb
CHANGED
@@ -34,7 +34,12 @@ describe Jsus::Pool do
|
|
34
34
|
|
35
35
|
it "should add all the source files to pool" do
|
36
36
|
subject.should have_exactly(3).sources
|
37
|
-
subject.sources.map {|s| s.
|
37
|
+
subject.sources.map {|s| s.provides_names }.flatten.should include("Mash/Mash", "Hash/Hash", "Class/Class")
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should keep track of extensions" do
|
41
|
+
pool = Jsus::Pool.new("spec/data/Extensions/app/javascripts")
|
42
|
+
pool.send(:extensions_map).keys.should include(Jsus::Tag["Core/Class"])
|
38
43
|
end
|
39
44
|
end
|
40
45
|
end
|
@@ -52,6 +57,10 @@ describe Jsus::Pool do
|
|
52
57
|
it "should return nil if nothing could be found" do
|
53
58
|
subject.lookup("Core/WTF").should be_nil
|
54
59
|
end
|
60
|
+
|
61
|
+
it "should allow tags" do
|
62
|
+
subject.lookup(Jsus::Tag["Class/Class"]).should == sources[1]
|
63
|
+
end
|
55
64
|
end
|
56
65
|
|
57
66
|
describe "#lookup_direct_dependencies" do
|
@@ -62,6 +71,13 @@ describe Jsus::Pool do
|
|
62
71
|
it "should return a container with direct dependencies" do
|
63
72
|
subject.lookup_direct_dependencies("Mash/Mash").should be_a(Jsus::Container)
|
64
73
|
subject.lookup_direct_dependencies("Mash/Mash").should == [sources[2]]
|
74
|
+
subject.lookup_direct_dependencies(Jsus::Tag["Mash/Mash"]).should be_a(Jsus::Container)
|
75
|
+
subject.lookup_direct_dependencies(Jsus::Tag["Mash/Mash"]).should == [sources[2]]
|
76
|
+
end
|
77
|
+
|
78
|
+
it "should return empty array if pool doesn't contain given source" do
|
79
|
+
subject.lookup_direct_dependencies("Lol/Wtf").should == []
|
80
|
+
subject.lookup_direct_dependencies(Jsus::Tag["Lol/Wtf"]).should == []
|
65
81
|
end
|
66
82
|
end
|
67
83
|
|
@@ -72,6 +88,27 @@ describe Jsus::Pool do
|
|
72
88
|
|
73
89
|
it "should return a container with files and dependencies" do
|
74
90
|
subject.lookup_dependencies("Mash/Mash").should == [sources[1], sources[2]]
|
91
|
+
subject.lookup_dependencies(Jsus::Tag["Mash/Mash"]).should == [sources[1], sources[2]]
|
92
|
+
end
|
93
|
+
|
94
|
+
it "should return empty array if pool doesn't contain given source" do
|
95
|
+
subject.lookup_dependencies("Lol/Wtf").should == []
|
96
|
+
subject.lookup_dependencies(Jsus::Tag["Caught/Mosh"]).should == []
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
describe "#lookup_extensions" do
|
101
|
+
let(:input_dir) { "spec/Data/Extensions/app/javascripts" }
|
102
|
+
subject { Jsus::Pool.new(input_dir) }
|
103
|
+
|
104
|
+
it "should return empty array if there's not a single extension for given tag" do
|
105
|
+
subject.lookup_extensions("Core/WTF").should be_empty
|
106
|
+
subject.lookup_extensions(Jsus::Tag["Core/WTF"]).should be_empty
|
107
|
+
end
|
108
|
+
|
109
|
+
it "should return an array with extensions if there are extensions for given tag" do
|
110
|
+
subject.lookup_extensions("Core/Class").should have_exactly(1).item
|
111
|
+
subject.lookup_extensions(Jsus::Tag["Core/Class"]).should have_exactly(1).item
|
75
112
|
end
|
76
113
|
end
|
77
114
|
end
|
@@ -9,8 +9,8 @@ describe Jsus::SourceFile do
|
|
9
9
|
context "from file" do
|
10
10
|
subject { Jsus::SourceFile.from_file('spec/data/test_source_one.js') }
|
11
11
|
it "should parse json header" do
|
12
|
-
subject.
|
13
|
-
subject.
|
12
|
+
subject.dependencies_names.should == ["Class"]
|
13
|
+
subject.provides_names.should == ["Color"]
|
14
14
|
subject.description.should == "A library to work with colors"
|
15
15
|
end
|
16
16
|
|
@@ -25,7 +25,6 @@ describe Jsus::SourceFile do
|
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
28
|
-
|
29
28
|
context "when file does not exist" do
|
30
29
|
it "should return nil" do
|
31
30
|
Jsus::SourceFile.from_file('spec/data/non-existant-file.js').should == nil
|
@@ -46,51 +45,207 @@ describe Jsus::SourceFile do
|
|
46
45
|
source.header.should == subject.header
|
47
46
|
end
|
48
47
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
48
|
+
end
|
49
|
+
|
50
|
+
context "when no package set, " do
|
51
|
+
subject { Jsus::SourceFile.from_file("spec/data/test_source_one.js") }
|
52
|
+
describe "#package" do
|
53
|
+
it "should return nil" do
|
54
|
+
subject.package.should be_nil
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
describe "#provides_names" do
|
59
|
+
it "should return names without leading slash in both forms" do
|
60
|
+
subject.provides_names.should == ["Color"]
|
61
|
+
subject.provides_names(:short => true).should == ["Color"]
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
describe "#dependencies_names" do
|
66
|
+
it "should return names without leading slash in both forms" do
|
67
|
+
subject.dependencies_names.should == ["Class"]
|
68
|
+
subject.dependencies_names(:short => true).should == ["Class"]
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
describe "#external_dependencies" do
|
73
|
+
it "should be empty" do
|
74
|
+
subject.external_dependencies.should be_empty
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
describe "#external_dependencies_names" do
|
79
|
+
it "should be empty" do
|
80
|
+
subject.external_dependencies_names.should be_empty
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
context "when it is in package, " do
|
86
|
+
let(:package) { Jsus::Package.new("spec/data/ExternalDependencies/app/javascripts/Orwik") }
|
87
|
+
subject { package.source_files[0] }
|
88
|
+
describe "#package" do
|
89
|
+
it "should return the package" do
|
90
|
+
subject.package.should == package
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
describe "#provides_names" do
|
95
|
+
it "should prepend package name by default and when explicitly asked for long form" do
|
96
|
+
subject.provides_names.should == ["Orwik/Test"]
|
97
|
+
subject.provides_names(:short => false).should == ["Orwik/Test"]
|
98
|
+
end
|
99
|
+
|
100
|
+
it "shouldn't prepend package name in short form" do
|
101
|
+
subject.provides_names(:short => true).should == ["Test"]
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
describe "#dependencies_names" do
|
106
|
+
it "should prepend package names to inner dependencies by default and when explicitly asked for long form" do
|
107
|
+
subject.should have_exactly(2).dependencies_names
|
108
|
+
subject.dependencies_names.should include("Orwik/Class", "Mash/Mash")
|
109
|
+
subject.should have_exactly(2).dependencies_names(:short => false)
|
110
|
+
subject.dependencies_names(:short => false).should include("Orwik/Class", "Mash/Mash")
|
111
|
+
end
|
112
|
+
|
113
|
+
it "should not prepend package names to inner dependencies in short form" do
|
114
|
+
subject.should have_exactly(2).dependencies_names(:short => true)
|
115
|
+
subject.dependencies_names(:short => true).should include("Class", "Mash/Mash")
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
describe "#external_dependencies" do
|
120
|
+
it "should include external dependencies" do
|
121
|
+
subject.should have_exactly(1).external_dependencies
|
122
|
+
subject.external_dependencies.should include(Jsus::Tag["Mash/Mash"])
|
123
|
+
end
|
124
|
+
|
125
|
+
it "should not include internal dependencies" do
|
126
|
+
subject.external_dependencies.should_not include(Jsus::Tag["Orwik/Class"])
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
describe "#external_dependencies_names" do
|
131
|
+
it "should include names of external dependencies" do
|
132
|
+
subject.external_dependencies_names.should include("Mash/Mash")
|
133
|
+
end
|
134
|
+
|
135
|
+
it "should not include names of internal dependencies" do
|
136
|
+
subject.external_dependencies_names.should_not include("Orwik/Class")
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
end
|
141
|
+
|
142
|
+
context "when pool is not set, " do
|
143
|
+
subject { Jsus::SourceFile.from_file("spec/data/Extensions/app/javascripts/Core/Source/Class.js", :package => Package.new(:name => "Core")) }
|
144
|
+
describe "#pool" do
|
145
|
+
it "should return nil" do
|
146
|
+
subject.pool.should be_nil
|
147
|
+
end
|
53
148
|
end
|
54
149
|
|
150
|
+
describe "#include_extensions!" do
|
151
|
+
it "should do nothing" do
|
152
|
+
lambda {
|
153
|
+
subject.include_extensions!
|
154
|
+
}.should_not change(subject, :extensions)
|
155
|
+
end
|
156
|
+
end
|
55
157
|
end
|
56
158
|
|
57
|
-
|
58
|
-
|
59
|
-
|
159
|
+
context "when pool is set, " do
|
160
|
+
let(:pool) { Jsus::Pool.new("spec/data/Extensions/app/javascripts") }
|
161
|
+
subject { Jsus::SourceFile.from_file("spec/data/Extensions/app/javascripts/Core/Source/Class.js", :pool => pool, :package => Package.new(:name => "Core")) }
|
162
|
+
describe "#pool" do
|
163
|
+
it "should return the pool" do
|
164
|
+
subject.pool.should == pool
|
165
|
+
end
|
60
166
|
end
|
61
167
|
|
62
|
-
|
63
|
-
|
168
|
+
context "and there are extensions for subject in its pool, " do
|
169
|
+
describe "#include_extensions!" do
|
170
|
+
it "should add all extensions to @extensions" do
|
171
|
+
subject.extensions.should be_empty
|
172
|
+
subject.include_extensions!
|
173
|
+
subject.extensions.should have_exactly(1).item
|
174
|
+
end
|
175
|
+
end
|
64
176
|
end
|
65
177
|
|
66
|
-
|
67
|
-
|
68
|
-
|
178
|
+
context "and there are no extensions for subject in its pool, " do
|
179
|
+
let(:pool) { Jsus::Pool.new }
|
180
|
+
describe "#include_extensions!" do
|
181
|
+
it "should add all extensions to @extensions" do
|
182
|
+
lambda {
|
183
|
+
subject.include_extensions!
|
184
|
+
}.should_not change(subject, :extensions)
|
185
|
+
end
|
186
|
+
end
|
69
187
|
end
|
70
188
|
end
|
71
189
|
|
72
|
-
|
73
|
-
|
74
|
-
|
190
|
+
context "when it is not an extension, " do
|
191
|
+
subject { Jsus::SourceFile.from_file("spec/data/Extensions/app/javascripts/Core/Source/Class.js") }
|
192
|
+
|
193
|
+
describe "#extension?" do
|
194
|
+
it "should return false" do
|
195
|
+
subject.should_not be_an_extension
|
196
|
+
end
|
75
197
|
end
|
198
|
+
end
|
76
199
|
|
77
|
-
|
78
|
-
|
200
|
+
context "when it is an extension, " do
|
201
|
+
subject { Jsus::SourceFile.from_file("spec/data/Extensions/app/javascripts/Orwik/Extensions/Class.js") }
|
202
|
+
|
203
|
+
describe "#extension?" do
|
204
|
+
it "should return true" do
|
205
|
+
subject.should be_an_extension
|
206
|
+
end
|
79
207
|
end
|
208
|
+
end
|
209
|
+
|
210
|
+
context "when there are no extensions, " do
|
211
|
+
let(:input_dir) { "spec/data/Extensions/app/javascripts" }
|
212
|
+
subject { Jsus::SourceFile.from_file("#{input_dir}/Core/Source/Class.js")}
|
80
213
|
|
81
|
-
|
82
|
-
|
83
|
-
|
214
|
+
describe "#required_files" do
|
215
|
+
it "should have only the filename itself" do
|
216
|
+
subject.required_files.should == [subject.filename]
|
217
|
+
end
|
84
218
|
end
|
219
|
+
end
|
85
220
|
|
86
|
-
|
87
|
-
|
88
|
-
|
221
|
+
context "when there are extensions, " do
|
222
|
+
let(:input_dir) { "spec/data/Extensions/app/javascripts" }
|
223
|
+
let(:extension) { Jsus::SourceFile.from_file("#{input_dir}/Orwik/Extensions/Class.js") }
|
224
|
+
subject { Jsus::SourceFile.from_file("#{input_dir}/Core/Source/Class.js")}
|
225
|
+
let(:initial_content) { subject.content }
|
226
|
+
before(:each) { initial_content; subject.extensions << extension }
|
227
|
+
|
228
|
+
describe "#required_files" do
|
229
|
+
it "should include source_file filename itself" do
|
230
|
+
subject.required_files.should include(subject.filename)
|
231
|
+
end
|
232
|
+
|
233
|
+
it "should include extensions filenames" do
|
234
|
+
subject.required_files.should include(extension.filename)
|
235
|
+
end
|
236
|
+
|
237
|
+
it "should put the subject's filename first" do
|
238
|
+
subject.required_files[0].should == subject.filename
|
239
|
+
end
|
89
240
|
end
|
90
241
|
|
91
|
-
|
92
|
-
|
93
|
-
|
242
|
+
describe "#content" do
|
243
|
+
it "should have extensions applied to the initial file content" do
|
244
|
+
subject.content.should_not == initial_content
|
245
|
+
subject.content.index(initial_content).should_not be_nil
|
246
|
+
subject.content.index(extension.content).should_not be_nil
|
247
|
+
subject.content.index(initial_content).should < subject.content.index(extension.content)
|
248
|
+
end
|
94
249
|
end
|
95
250
|
end
|
96
251
|
end
|