psyho_juicer 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +58 -0
- data/Manifest.txt +58 -0
- data/Rakefile +96 -0
- data/Readme.rdoc +313 -0
- data/VERSION +1 -0
- data/bin/juicer +6 -0
- data/lib/juicer.rb +69 -0
- data/lib/juicer/asset/path.rb +275 -0
- data/lib/juicer/asset/path_resolver.rb +79 -0
- data/lib/juicer/binary.rb +171 -0
- data/lib/juicer/cache_buster.rb +131 -0
- data/lib/juicer/chainable.rb +106 -0
- data/lib/juicer/cli.rb +56 -0
- data/lib/juicer/command/install.rb +61 -0
- data/lib/juicer/command/list.rb +57 -0
- data/lib/juicer/command/merge.rb +205 -0
- data/lib/juicer/command/util.rb +32 -0
- data/lib/juicer/command/verify.rb +60 -0
- data/lib/juicer/css_cache_buster.rb +90 -0
- data/lib/juicer/datafy/datafy.rb +20 -0
- data/lib/juicer/dependency_resolver/css_dependency_resolver.rb +29 -0
- data/lib/juicer/dependency_resolver/dependency_resolver.rb +101 -0
- data/lib/juicer/dependency_resolver/javascript_dependency_resolver.rb +23 -0
- data/lib/juicer/ext/logger.rb +5 -0
- data/lib/juicer/ext/string.rb +47 -0
- data/lib/juicer/ext/symbol.rb +15 -0
- data/lib/juicer/image_embed.rb +129 -0
- data/lib/juicer/install/base.rb +186 -0
- data/lib/juicer/install/closure_compiler_installer.rb +69 -0
- data/lib/juicer/install/jslint_installer.rb +51 -0
- data/lib/juicer/install/rhino_installer.rb +53 -0
- data/lib/juicer/install/yui_compressor_installer.rb +67 -0
- data/lib/juicer/jslint.rb +90 -0
- data/lib/juicer/merger/base.rb +74 -0
- data/lib/juicer/merger/javascript_merger.rb +29 -0
- data/lib/juicer/merger/stylesheet_merger.rb +110 -0
- data/lib/juicer/minifyer/closure_compiler.rb +90 -0
- data/lib/juicer/minifyer/java_base.rb +77 -0
- data/lib/juicer/minifyer/yui_compressor.rb +96 -0
- data/test/bin/jslint-1.0.js +523 -0
- data/test/bin/jslint.js +523 -0
- data/test/bin/rhino1_7R1.zip +0 -0
- data/test/bin/rhino1_7R2-RC1.jar +0 -0
- data/test/bin/rhino1_7R2-RC1.zip +0 -0
- data/test/bin/yuicompressor +0 -0
- data/test/bin/yuicompressor-2.3.5.zip +0 -0
- data/test/bin/yuicompressor-2.4.2.jar +0 -0
- data/test/bin/yuicompressor-2.4.2.zip +0 -0
- data/test/fixtures/yui-download.html +425 -0
- data/test/test_helper.rb +175 -0
- data/test/unit/juicer/asset/path_resolver_test.rb +76 -0
- data/test/unit/juicer/asset/path_test.rb +370 -0
- data/test/unit/juicer/cache_buster_test.rb +104 -0
- data/test/unit/juicer/chainable_test.rb +94 -0
- data/test/unit/juicer/command/install_test.rb +58 -0
- data/test/unit/juicer/command/list_test.rb +81 -0
- data/test/unit/juicer/command/merge_test.rb +162 -0
- data/test/unit/juicer/command/util_test.rb +58 -0
- data/test/unit/juicer/command/verify_test.rb +48 -0
- data/test/unit/juicer/css_cache_buster_test.rb +71 -0
- data/test/unit/juicer/datafy_test.rb +37 -0
- data/test/unit/juicer/dependency_resolver/css_dependency_resolver_test.rb +36 -0
- data/test/unit/juicer/dependency_resolver/javascript_dependency_resolver_test.rb +50 -0
- data/test/unit/juicer/ext/string_test.rb +59 -0
- data/test/unit/juicer/ext/symbol_test.rb +27 -0
- data/test/unit/juicer/image_embed_test.rb +271 -0
- data/test/unit/juicer/install/installer_base_test.rb +214 -0
- data/test/unit/juicer/install/jslint_installer_test.rb +54 -0
- data/test/unit/juicer/install/rhino_installer_test.rb +57 -0
- data/test/unit/juicer/install/yui_compressor_test.rb +56 -0
- data/test/unit/juicer/jslint_test.rb +60 -0
- data/test/unit/juicer/merger/base_test.rb +122 -0
- data/test/unit/juicer/merger/javascript_merger_test.rb +74 -0
- data/test/unit/juicer/merger/stylesheet_merger_test.rb +180 -0
- data/test/unit/juicer/minifyer/closure_compressor_test.rb +107 -0
- data/test/unit/juicer/minifyer/yui_compressor_test.rb +116 -0
- data/test/unit/juicer_test.rb +1 -0
- metadata +278 -0
@@ -0,0 +1,214 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
module Juicer
|
4
|
+
module Install
|
5
|
+
class SomeMagicInstaller < Juicer::Install::Base
|
6
|
+
def install(version = nil)
|
7
|
+
version ||= "1.0.0"
|
8
|
+
ver = super(version)
|
9
|
+
File.open(File.join(@install_dir, path, "bin", ver + ".app"), "w") do |file|
|
10
|
+
file.puts version
|
11
|
+
end
|
12
|
+
|
13
|
+
version
|
14
|
+
end
|
15
|
+
|
16
|
+
def uninstall(version = "1.0.0")
|
17
|
+
super(version) do |path, version|
|
18
|
+
File.delete(File.join(path, "bin", version + ".app"))
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
class SomeOtherInstaller < Juicer::Install::SomeMagicInstaller
|
24
|
+
def install(version = nil)
|
25
|
+
version ||= "1.0.0"
|
26
|
+
super(version)
|
27
|
+
end
|
28
|
+
|
29
|
+
def latest
|
30
|
+
"1.0.0"
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
class TestInstallerBase < Test::Unit::TestCase
|
37
|
+
def initialize(*args)
|
38
|
+
super
|
39
|
+
@juicer_home = File.expand_path(File.join("test", "data", ".juicer"))
|
40
|
+
end
|
41
|
+
|
42
|
+
def setup
|
43
|
+
FileUtils.rm_rf @juicer_home
|
44
|
+
@installer = Juicer::Install::SomeMagicInstaller.new(@juicer_home)
|
45
|
+
end
|
46
|
+
|
47
|
+
context "installation directory" do
|
48
|
+
should "should be Juicer.home by default" do
|
49
|
+
installer = Juicer::Install::SomeMagicInstaller.new
|
50
|
+
assert_equal Juicer.home, installer.install_dir
|
51
|
+
end
|
52
|
+
|
53
|
+
should "override installation directory" do
|
54
|
+
installer = Juicer::Install::SomeMagicInstaller.new("/home/baluba")
|
55
|
+
assert_equal "/home/baluba", installer.install_dir
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
context "latest" do
|
60
|
+
should "raise NotImplementedError" do
|
61
|
+
assert_raise NotImplementedError do
|
62
|
+
@installer.latest
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
context "paths and name" do
|
68
|
+
should "reflect installer class name" do
|
69
|
+
assert_equal "lib/some_magic", @installer.path
|
70
|
+
end
|
71
|
+
|
72
|
+
should "reflect installer class name for bin path" do
|
73
|
+
assert_equal "lib/some_magic/bin", @installer.bin_path
|
74
|
+
end
|
75
|
+
|
76
|
+
should "reflect class name in human name" do
|
77
|
+
assert_equal "Some Magic", @installer.name
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
context "already installed module" do
|
82
|
+
should "report as installed" do
|
83
|
+
assert !@installer.installed?("x.y.z")
|
84
|
+
@installer.install("x.y.z")
|
85
|
+
assert @installer.installed?("x.y.z")
|
86
|
+
end
|
87
|
+
|
88
|
+
should "fail re-installation" do
|
89
|
+
@installer.install("1.0.0")
|
90
|
+
|
91
|
+
assert_raise RuntimeError do
|
92
|
+
@installer.install("1.0.0")
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
context "installation" do
|
98
|
+
should "create bin and release folders" do
|
99
|
+
assert_equal "1.0.0", @installer.install("1.0.0")
|
100
|
+
assert File.exists?(File.join(@juicer_home, "lib/some_magic/bin"))
|
101
|
+
assert File.exists?(File.join(@juicer_home, "lib/some_magic/1.0.0"))
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
context "uninstall" do
|
106
|
+
should "remove library path when only version is uninstalled" do
|
107
|
+
@installer.install("1.0.0")
|
108
|
+
@installer.uninstall("1.0.0")
|
109
|
+
assert !File.exists?(File.join(@juicer_home, "lib/some_magic"))
|
110
|
+
end
|
111
|
+
|
112
|
+
should "keep other versions" do
|
113
|
+
@installer.install("1.0.0")
|
114
|
+
@installer.install("1.0.1")
|
115
|
+
@installer.uninstall("1.0.0")
|
116
|
+
assert !File.exists?(File.join(@juicer_home, "lib/some_magic/1.0.0"))
|
117
|
+
assert File.exists?(File.join(@juicer_home, "lib/some_magic"))
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
context "download" do
|
122
|
+
# TODO: Don't download
|
123
|
+
should "cache files" do
|
124
|
+
File.expects(:delete).at_most(0)
|
125
|
+
@installer.download("http://www.julienlecomte.net/yuicompressor/")
|
126
|
+
filename = File.join(@juicer_home, "download/some_magic/yuicompressor")
|
127
|
+
assert File.exists?(filename)
|
128
|
+
@installer.download("http://www.julienlecomte.net/yuicompressor/")
|
129
|
+
end
|
130
|
+
|
131
|
+
should "redownload cached files when forced" do
|
132
|
+
File.expects(:delete).at_most(1)
|
133
|
+
@installer.download("http://www.julienlecomte.net/yuicompressor/")
|
134
|
+
filename = File.join(@juicer_home, "download/some_magic/yuicompressor")
|
135
|
+
assert File.exists?(filename)
|
136
|
+
File.expects(:open).at_most(1)
|
137
|
+
@installer.download("http://www.julienlecomte.net/yuicompressor/", true)
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
context "installer dependencies" do
|
142
|
+
should "not return true from installer when missing dependencies" do
|
143
|
+
@installer.install
|
144
|
+
|
145
|
+
installer = Juicer::Install::SomeMagicInstaller.new(@juicer_home)
|
146
|
+
assert !installer.installed?("1.0.1"), "Installer should be installed"
|
147
|
+
|
148
|
+
installer.dependency Juicer::Install::SomeOtherInstaller
|
149
|
+
assert !installer.installed?("1.0.1"), "Installer should not report as being installed when missing dependencies"
|
150
|
+
end
|
151
|
+
|
152
|
+
should "install single dependency" do
|
153
|
+
installer = Juicer::Install::SomeMagicInstaller.new(@juicer_home)
|
154
|
+
installer.dependency Juicer::Install::SomeOtherInstaller
|
155
|
+
installer.install "1.0.0"
|
156
|
+
assert File.exists?(File.join(@juicer_home, "lib/some_magic/1.0.0"))
|
157
|
+
assert File.exists?(File.join(@juicer_home, "lib/some_other/1.0.0"))
|
158
|
+
end
|
159
|
+
|
160
|
+
should "not raise error when they exist" do
|
161
|
+
installer = Juicer::Install::SomeMagicInstaller.new(@juicer_home)
|
162
|
+
installer.dependency Juicer::Install::SomeOtherInstaller
|
163
|
+
|
164
|
+
dep = Juicer::Install::SomeOtherInstaller.new
|
165
|
+
dep.install unless dep.installed?
|
166
|
+
|
167
|
+
assert_nothing_raised do
|
168
|
+
installer.install "1.0.0"
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
172
|
+
should "get dependency from single symbol" do
|
173
|
+
installer = Juicer::Install::SomeMagicInstaller.new(@juicer_home)
|
174
|
+
installer.dependency :some_other
|
175
|
+
installer.install "1.0.0"
|
176
|
+
assert File.exists?(File.join(@juicer_home, "lib/some_magic/1.0.0"))
|
177
|
+
assert File.exists?(File.join(@juicer_home, "lib/some_other/1.0.0"))
|
178
|
+
end
|
179
|
+
|
180
|
+
should "get dependency from single string" do
|
181
|
+
installer = Juicer::Install::SomeMagicInstaller.new(@juicer_home)
|
182
|
+
installer.dependency "some_other"
|
183
|
+
installer.install "1.0.0"
|
184
|
+
assert File.exists?(File.join(@juicer_home, "lib/some_magic/1.0.0"))
|
185
|
+
assert File.exists?(File.join(@juicer_home, "lib/some_other/1.0.0"))
|
186
|
+
end
|
187
|
+
|
188
|
+
should "support multiple dependencies" do
|
189
|
+
installer = Juicer::Install::SomeMagicInstaller.new(@juicer_home)
|
190
|
+
installer.dependency :some_other
|
191
|
+
installer.dependency :some_other, "2.0.4"
|
192
|
+
installer.dependency :some_other, "3.0.5"
|
193
|
+
installer.install "1.0.0"
|
194
|
+
assert File.exists?(File.join(@juicer_home, "lib/some_magic/1.0.0"))
|
195
|
+
assert File.exists?(File.join(@juicer_home, "lib/some_other/1.0.0"))
|
196
|
+
assert File.exists?(File.join(@juicer_home, "lib/some_other/2.0.4"))
|
197
|
+
assert File.exists?(File.join(@juicer_home, "lib/some_other/3.0.5"))
|
198
|
+
end
|
199
|
+
end
|
200
|
+
|
201
|
+
context "resolving class" do
|
202
|
+
should "accept class input" do
|
203
|
+
assert_equal Juicer::Install::SomeMagicInstaller, Juicer::Install.get(Juicer::Install::SomeMagicInstaller)
|
204
|
+
end
|
205
|
+
|
206
|
+
should "accept symbol input" do
|
207
|
+
assert_equal Juicer::Install::SomeMagicInstaller, Juicer::Install.get(:some_magic)
|
208
|
+
end
|
209
|
+
|
210
|
+
should "accept string input" do
|
211
|
+
assert_equal Juicer::Install::SomeMagicInstaller, Juicer::Install.get("some_magic")
|
212
|
+
end
|
213
|
+
end
|
214
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
class TestJsLintInstaller < Test::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
@installer = Juicer::Install::JSLintInstaller.new(path(".juicer"))
|
6
|
+
end
|
7
|
+
|
8
|
+
def teardown
|
9
|
+
FileUtils.rm_rf(path(".juicer/lib")) if File.exists?(path(".juicer/lib"))
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_install_should_download_js
|
13
|
+
@installer.install unless @installer.installed?
|
14
|
+
|
15
|
+
assert File.exists?(path(".juicer"))
|
16
|
+
assert File.exists?(path(".juicer/lib"))
|
17
|
+
assert File.exists?(path(".juicer/lib/jslint"))
|
18
|
+
assert File.exists?(path(".juicer/lib/jslint/bin"))
|
19
|
+
assert_match(/jslint-\d\.\d\.js/, Dir.glob(path(".juicer/lib/jslint/bin/*"))[0])
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_uninstall_should_remove_all_files_and_empty_directories
|
23
|
+
@installer.install
|
24
|
+
assert File.exists?(path(".juicer/lib/jslint/bin"))
|
25
|
+
assert_equal 1, Dir.glob(path(".juicer/lib/jslint/**/*")).find_all { |f| File.file?(f) }.length
|
26
|
+
|
27
|
+
@installer.uninstall
|
28
|
+
assert !File.exists?(path(".juicer/lib/jslint"))
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_install_specific_version
|
32
|
+
@installer.install("1.0")
|
33
|
+
|
34
|
+
assert File.exists?(path(".juicer/lib/jslint/bin"))
|
35
|
+
assert_equal "jslint-1.0.js", File.basename(Dir.glob(path(".juicer/lib/jslint/bin/*"))[0])
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_install_should_install_rhino_also
|
39
|
+
assert !File.exists?(path(".juicer/lib/rhino"))
|
40
|
+
@installer.install
|
41
|
+
assert File.exists?(path(".juicer/lib/rhino"))
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_uninstall_should_leave_directories_when_other_versions_are_installed
|
45
|
+
@installer.install
|
46
|
+
@installer.install("1.1")
|
47
|
+
assert File.exists?(path(".juicer/lib/jslint/bin"))
|
48
|
+
assert_equal 2, Dir.glob(path(".juicer/lib/jslint/**/*")).find_all { |f| File.file?(f) }.length
|
49
|
+
|
50
|
+
@installer.uninstall("1.1")
|
51
|
+
assert File.exists?(path(".juicer/lib/jslint"))
|
52
|
+
assert_equal 1, Dir.glob(path(".juicer/lib/jslint/**/*")).find_all { |f| File.file?(f) }.length
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
class TestRhinoInstaller < Test::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
@installer = Juicer::Install::RhinoInstaller.new(path(".juicer"))
|
6
|
+
end
|
7
|
+
|
8
|
+
def teardown
|
9
|
+
FileUtils.rm_rf(path(".juicer/lib")) if File.exists?(path(".juicer/lib"))
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_check_installation
|
13
|
+
FileUtils.rm_rf(path(".juicer/lib")) if File.exists?(path(".juicer/lib"))
|
14
|
+
assert !@installer.installed?
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_install_should_download_jar_and_license
|
18
|
+
@installer.install
|
19
|
+
|
20
|
+
assert File.exists?(path(".juicer"))
|
21
|
+
assert File.exists?(path(".juicer/lib"))
|
22
|
+
assert File.exists?(path(".juicer/lib/rhino"))
|
23
|
+
assert File.exists?(path(".juicer/lib/rhino/bin"))
|
24
|
+
assert_match(/rhino\d\_\d[^\.]*\.jar/, Dir.glob(path(".juicer/lib/rhino/bin/*"))[0])
|
25
|
+
|
26
|
+
files = Dir.glob(path(".juicer/lib/rhino/*_*/**/*"))
|
27
|
+
assert_equal ["LICENSE.txt"], files.collect { |file| file.split("/").pop }.sort
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_uninstall_should_remove_all_files_and_empty_directories
|
31
|
+
@installer.install
|
32
|
+
assert File.exists?(path(".juicer/lib/rhino/bin"))
|
33
|
+
assert_equal 2, Dir.glob(path(".juicer/lib/rhino/**/*")).find_all { |f| File.file?(f) }.length
|
34
|
+
|
35
|
+
@installer.uninstall
|
36
|
+
assert !File.exists?(path(".juicer/lib/rhino"))
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_install_specific_version
|
40
|
+
@installer.install("1.7R2-RC1")
|
41
|
+
|
42
|
+
assert File.exists?(path(".juicer/lib/rhino/bin"))
|
43
|
+
assert File.exists?(path(".juicer/lib/rhino/1_7R2-RC1"))
|
44
|
+
assert_equal "rhino1_7R2-RC1.jar", File.basename(Dir.glob(path(".juicer/lib/rhino/bin/*"))[0])
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_uninstall_should_leave_directories_when_other_versions_are_installed
|
48
|
+
@installer.install
|
49
|
+
@installer.install("1.7R1")
|
50
|
+
assert File.exists?(path(".juicer/lib/rhino/bin"))
|
51
|
+
assert_equal 3, Dir.glob(path(".juicer/lib/rhino/**/*")).find_all { |f| File.file?(f) }.length
|
52
|
+
|
53
|
+
@installer.uninstall("1.7R2-RC1")
|
54
|
+
assert File.exists?(path(".juicer/lib/rhino"))
|
55
|
+
assert_equal 1, Dir.glob(path(".juicer/lib/rhino/**/*")).find_all { |f| File.file?(f) }.length
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
class TestYuiCompressorInstall < Test::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
@installer = Juicer::Install::YuiCompressorInstaller.new(path(".juicer"))
|
6
|
+
end
|
7
|
+
|
8
|
+
def teardown
|
9
|
+
FileUtils.rm_rf(path(".juicer/lib")) if File.exists?(path(".juicer/lib"))
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_check_installation
|
13
|
+
assert !@installer.installed?
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_install_should_download_jar_and_readme
|
17
|
+
@installer.install
|
18
|
+
|
19
|
+
assert File.exists?(path(".juicer"))
|
20
|
+
assert File.exists?(path(".juicer/lib"))
|
21
|
+
assert File.exists?(path(".juicer/lib/yui_compressor"))
|
22
|
+
assert File.exists?(path(".juicer/lib/yui_compressor/bin"))
|
23
|
+
assert_match(/yuicompressor-\d\.\d\.\d\.jar/, Dir.glob(path(".juicer/lib/yui_compressor/bin/*"))[0])
|
24
|
+
|
25
|
+
files = Dir.glob(path(".juicer/lib/yui_compressor/*.*.*/**/*"))
|
26
|
+
assert_equal ["CHANGELOG", "README"], files.collect { |file| file.split("/").pop }.sort
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_uninstall_should_remove_all_files_and_empty_directories
|
30
|
+
@installer.install
|
31
|
+
assert File.exists?(path(".juicer/lib/yui_compressor/bin"))
|
32
|
+
assert_equal 3, Dir.glob(path(".juicer/lib/yui_compressor/**/*")).find_all { |f| File.file?(f) }.length
|
33
|
+
|
34
|
+
@installer.uninstall
|
35
|
+
assert !File.exists?(path(".juicer/lib/yui_compressor"))
|
36
|
+
end
|
37
|
+
|
38
|
+
# def test_install_specific_version
|
39
|
+
# @installer.install("2.3.5")
|
40
|
+
|
41
|
+
# assert File.exists?(path(".juicer/lib/yui_compressor/bin"))
|
42
|
+
# assert File.exists?(path(".juicer/lib/yui_compressor/2.3.5"))
|
43
|
+
# assert_equal "yuicompressor-2.3.5.jar", File.basename(Dir.glob(path(".juicer/lib/yui_compressor/bin/*"))[0])
|
44
|
+
# end
|
45
|
+
|
46
|
+
# def test_uninstall_should_leave_directories_when_other_versions_are_installed
|
47
|
+
# @installer.install
|
48
|
+
# @installer.install("2.3.5")
|
49
|
+
# assert File.exists?(path(".juicer/lib/yui_compressor/bin"))
|
50
|
+
# assert_equal 6, Dir.glob(path(".juicer/lib/yui_compressor/**/*")).find_all { |f| File.file?(f) }.length
|
51
|
+
|
52
|
+
# @installer.uninstall("2.3.5")
|
53
|
+
# assert File.exists?(path(".juicer/lib/yui_compressor"))
|
54
|
+
# assert_equal 3, Dir.glob(path(".juicer/lib/yui_compressor/**/*")).find_all { |f| File.file?(f) }.length
|
55
|
+
# end
|
56
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
class TestJsLint < Test::Unit::TestCase
|
4
|
+
def initialize(*args)
|
5
|
+
@path = File.expand_path(path("../bin"))
|
6
|
+
@file = path("jsltest.js")
|
7
|
+
super
|
8
|
+
end
|
9
|
+
|
10
|
+
def setup
|
11
|
+
FileUtils.mkdir(path("")) unless File.exists?(path(""))
|
12
|
+
File.open(@file, "w") { |f| f.puts "" }
|
13
|
+
end
|
14
|
+
|
15
|
+
def teardown
|
16
|
+
File.delete(@file)
|
17
|
+
end
|
18
|
+
|
19
|
+
context "verifying file with jslint" do
|
20
|
+
should "shell out to rhino/jslint" do
|
21
|
+
jslint = Juicer::JsLint.new(:bin_path => @path)
|
22
|
+
jslint.expects(:execute).with("-jar \"#{@path}/rhino1_7R2-RC1.jar\" \"#{@path}/jslint-1.0.js\" \"#{@file}\"").returns("jslint: No problems")
|
23
|
+
|
24
|
+
assert jslint.check(@file).ok?
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
context "jslint report returns" do
|
29
|
+
should "be a report object for valid files" do
|
30
|
+
jslint = Juicer::JsLint.new(:bin_path => @path)
|
31
|
+
jslint.expects(:execute).returns("jslint: No problems")
|
32
|
+
|
33
|
+
assert_equal Juicer::JsLint::Report, jslint.check(@file).class
|
34
|
+
end
|
35
|
+
|
36
|
+
should "be a report object for invalid files" do
|
37
|
+
jslint = Juicer::JsLint.new(:bin_path => @path)
|
38
|
+
jslint.expects(:execute).returns("Wrong use of semicolon\nWrong blabla")
|
39
|
+
|
40
|
+
assert_equal Juicer::JsLint::Report, jslint.check(path("not-ok.js")).class
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
context "errors" do
|
45
|
+
should "be available on report" do
|
46
|
+
jslint = Juicer::JsLint.new(:bin_path => @path)
|
47
|
+
jslint.expects(:execute).returns("Wrong use of semicolon\nWrong blabla\nWrong use of semicolon\nWrong blabla")
|
48
|
+
|
49
|
+
assert_equal 2, jslint.check(@file).errors.length
|
50
|
+
end
|
51
|
+
|
52
|
+
should "be error objects" do
|
53
|
+
jslint = Juicer::JsLint.new(:bin_path => @path)
|
54
|
+
jslint.expects(:execute).returns("Wrong use of semicolon\nWrong blabla")
|
55
|
+
|
56
|
+
error = jslint.check(@file).errors.first
|
57
|
+
assert_equal Juicer::JsLint::Error, error.class
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,122 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
class TestMergerBase < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def setup
|
6
|
+
@file_merger = Juicer::Merger::Base.new
|
7
|
+
Juicer::Test::FileSetup.new.create
|
8
|
+
end
|
9
|
+
|
10
|
+
def teardown
|
11
|
+
file = path('test_out.css')
|
12
|
+
File.delete(file) if File.exists?(file)
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_constructor
|
16
|
+
files = ['a.css', 'b.css'].collect { |file| path(file) }
|
17
|
+
file_merger = Juicer::Merger::Base.new files
|
18
|
+
assert_equal 2, file_merger.files.length
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_append_duplicate_files
|
22
|
+
@file_merger.append ['a.css', 'b.css'].collect { |file| path(file) }
|
23
|
+
assert_equal 2, @file_merger.files.length,
|
24
|
+
"b.css should not be included twice even when a.css imports it and it is manually added"
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_append_duplicate
|
28
|
+
@file_merger.append ['a.css', 'b.css'].collect { |file| path(file) }
|
29
|
+
assert_equal 2, @file_merger.files.length
|
30
|
+
|
31
|
+
@file_merger.append path('a.css')
|
32
|
+
assert_equal 2, @file_merger.files.length
|
33
|
+
|
34
|
+
@file_merger.append path('version.txt')
|
35
|
+
assert_equal 3, @file_merger.files.length
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_append_alias
|
39
|
+
@file_merger << ['a.css', 'b.css'].collect { |file| path(file) }
|
40
|
+
assert_equal 2, @file_merger.files.length
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_save_to_stream
|
44
|
+
a_css = path('a.css')
|
45
|
+
a_css_contents = IO.read(a_css) + "\n"
|
46
|
+
ios = StringIO.new
|
47
|
+
@file_merger << a_css
|
48
|
+
@file_merger.save ios
|
49
|
+
assert_equal a_css_contents, ios.string
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_save_to_file
|
53
|
+
a_css = path('a.css')
|
54
|
+
output_file = path('test_out.css')
|
55
|
+
@file_merger << a_css
|
56
|
+
@file_merger.save(output_file)
|
57
|
+
|
58
|
+
assert_equal IO.read(a_css) + "\n", IO.read(output_file)
|
59
|
+
end
|
60
|
+
|
61
|
+
def test_save_merged_to_stream
|
62
|
+
a_css = path('a.css')
|
63
|
+
b_css = path('b.css')
|
64
|
+
ios = StringIO.new
|
65
|
+
|
66
|
+
@file_merger << a_css
|
67
|
+
@file_merger << b_css
|
68
|
+
@file_merger.save(ios)
|
69
|
+
|
70
|
+
assert_equal "#{IO.read(a_css)}\n#{IO.read(b_css)}\n", ios.string
|
71
|
+
end
|
72
|
+
|
73
|
+
def test_save_merged_to_file
|
74
|
+
a_css = path('a.css')
|
75
|
+
b_css = path('b.css')
|
76
|
+
a_contents = IO.read(a_css) + "\n"
|
77
|
+
b_contents = IO.read(b_css) + "\n"
|
78
|
+
output_file = path('test_out.css')
|
79
|
+
|
80
|
+
@file_merger << a_css
|
81
|
+
@file_merger << b_css
|
82
|
+
@file_merger.save(output_file)
|
83
|
+
|
84
|
+
assert_equal "#{IO.read(a_css)}\n#{IO.read(b_css)}\n", IO.read(output_file)
|
85
|
+
end
|
86
|
+
|
87
|
+
def test_resolve_dependencies
|
88
|
+
Juicer::Merger::Base.publicize_methods do
|
89
|
+
@file_merger.dependency_resolver = MockImportResolver.new
|
90
|
+
|
91
|
+
@file_merger.resolve_dependencies('a.css')
|
92
|
+
assert_equal 1, @file_merger.files.length
|
93
|
+
|
94
|
+
@file_merger.resolve_dependencies('a.css')
|
95
|
+
assert_equal 1, @file_merger.files.length
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
def test_merge
|
100
|
+
Juicer::Merger::Base.publicize_methods do
|
101
|
+
a_content = <<EOF
|
102
|
+
@import 'b.css';
|
103
|
+
|
104
|
+
/* Dette er a.css */
|
105
|
+
|
106
|
+
EOF
|
107
|
+
|
108
|
+
content = @file_merger.merge(path('a.css'))
|
109
|
+
assert_equal a_content, content
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
def test_attributes
|
114
|
+
assert_not_nil @file_merger.files
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
class MockImportResolver
|
119
|
+
def resolve(file)
|
120
|
+
[file]
|
121
|
+
end
|
122
|
+
end
|