ktheory-juicer 1.0.0.ktheory1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (98) hide show
  1. data/History.txt +30 -0
  2. data/Manifest.txt +58 -0
  3. data/Rakefile +96 -0
  4. data/Readme.rdoc +312 -0
  5. data/VERSION +1 -0
  6. data/bin/juicer +8 -0
  7. data/lib/juicer.rb +70 -0
  8. data/lib/juicer/asset/path.rb +275 -0
  9. data/lib/juicer/asset/path_resolver.rb +79 -0
  10. data/lib/juicer/binary.rb +171 -0
  11. data/lib/juicer/cache_buster.rb +130 -0
  12. data/lib/juicer/chainable.rb +106 -0
  13. data/lib/juicer/cli.rb +56 -0
  14. data/lib/juicer/command/install.rb +61 -0
  15. data/lib/juicer/command/list.rb +57 -0
  16. data/lib/juicer/command/merge.rb +205 -0
  17. data/lib/juicer/command/util.rb +32 -0
  18. data/lib/juicer/command/verify.rb +60 -0
  19. data/lib/juicer/css_cache_buster.rb +80 -0
  20. data/lib/juicer/datafy/datafy.rb +20 -0
  21. data/lib/juicer/dependency_resolver/css_dependency_resolver.rb +29 -0
  22. data/lib/juicer/dependency_resolver/dependency_resolver.rb +101 -0
  23. data/lib/juicer/dependency_resolver/javascript_dependency_resolver.rb +23 -0
  24. data/lib/juicer/ext/logger.rb +5 -0
  25. data/lib/juicer/ext/string.rb +47 -0
  26. data/lib/juicer/ext/symbol.rb +15 -0
  27. data/lib/juicer/image_embed.rb +136 -0
  28. data/lib/juicer/install/base.rb +186 -0
  29. data/lib/juicer/install/closure_compiler_installer.rb +69 -0
  30. data/lib/juicer/install/jslint_installer.rb +51 -0
  31. data/lib/juicer/install/rhino_installer.rb +53 -0
  32. data/lib/juicer/install/yui_compressor_installer.rb +67 -0
  33. data/lib/juicer/jslint.rb +90 -0
  34. data/lib/juicer/merger/base.rb +74 -0
  35. data/lib/juicer/merger/javascript_merger.rb +29 -0
  36. data/lib/juicer/merger/stylesheet_merger.rb +110 -0
  37. data/lib/juicer/minifyer/closure_compiler.rb +90 -0
  38. data/lib/juicer/minifyer/java_base.rb +77 -0
  39. data/lib/juicer/minifyer/yui_compressor.rb +96 -0
  40. data/test/bin/jslint-1.0.js +523 -0
  41. data/test/bin/jslint.js +523 -0
  42. data/test/bin/rhino1_7R1.zip +0 -0
  43. data/test/bin/rhino1_7R2-RC1.jar +0 -0
  44. data/test/bin/rhino1_7R2-RC1.zip +0 -0
  45. data/test/bin/yuicompressor +0 -0
  46. data/test/bin/yuicompressor-2.3.5.zip +0 -0
  47. data/test/bin/yuicompressor-2.4.2.jar +0 -0
  48. data/test/bin/yuicompressor-2.4.2.zip +0 -0
  49. data/test/data/Changelog.txt +10 -0
  50. data/test/data/a.css +3 -0
  51. data/test/data/a.js +5 -0
  52. data/test/data/a1.css +5 -0
  53. data/test/data/b.css +1 -0
  54. data/test/data/b.js +5 -0
  55. data/test/data/b1.css +5 -0
  56. data/test/data/c1.css +3 -0
  57. data/test/data/css/2.gif +1 -0
  58. data/test/data/css/test.css +11 -0
  59. data/test/data/css/test2.css +1 -0
  60. data/test/data/d1.css +3 -0
  61. data/test/data/images/1.png +1 -0
  62. data/test/data/my_app.js +2 -0
  63. data/test/data/not-ok.js +2 -0
  64. data/test/data/ok.js +3 -0
  65. data/test/data/path_test.css +5 -0
  66. data/test/data/path_test2.css +14 -0
  67. data/test/data/pkg/module/moda.js +2 -0
  68. data/test/data/pkg/module/modb.js +3 -0
  69. data/test/data/pkg/pkg.js +1 -0
  70. data/test/test_helper.rb +169 -0
  71. data/test/unit/juicer/asset/path_resolver_test.rb +76 -0
  72. data/test/unit/juicer/asset/path_test.rb +370 -0
  73. data/test/unit/juicer/cache_buster_test.rb +104 -0
  74. data/test/unit/juicer/chainable_test.rb +94 -0
  75. data/test/unit/juicer/command/install_test.rb +58 -0
  76. data/test/unit/juicer/command/list_test.rb +81 -0
  77. data/test/unit/juicer/command/merge_test.rb +162 -0
  78. data/test/unit/juicer/command/util_test.rb +58 -0
  79. data/test/unit/juicer/command/verify_test.rb +48 -0
  80. data/test/unit/juicer/css_cache_buster_test.rb +71 -0
  81. data/test/unit/juicer/datafy_test.rb +37 -0
  82. data/test/unit/juicer/dependency_resolver/css_dependency_resolver_test.rb +36 -0
  83. data/test/unit/juicer/dependency_resolver/javascript_dependency_resolver_test.rb +50 -0
  84. data/test/unit/juicer/ext/string_test.rb +59 -0
  85. data/test/unit/juicer/ext/symbol_test.rb +27 -0
  86. data/test/unit/juicer/image_embed_test.rb +271 -0
  87. data/test/unit/juicer/install/installer_base_test.rb +214 -0
  88. data/test/unit/juicer/install/jslint_installer_test.rb +54 -0
  89. data/test/unit/juicer/install/rhino_installer_test.rb +57 -0
  90. data/test/unit/juicer/install/yui_compressor_test.rb +56 -0
  91. data/test/unit/juicer/jslint_test.rb +60 -0
  92. data/test/unit/juicer/merger/base_test.rb +122 -0
  93. data/test/unit/juicer/merger/javascript_merger_test.rb +74 -0
  94. data/test/unit/juicer/merger/stylesheet_merger_test.rb +180 -0
  95. data/test/unit/juicer/minifyer/closure_compressor_test.rb +107 -0
  96. data/test/unit/juicer/minifyer/yui_compressor_test.rb +116 -0
  97. data/test/unit/juicer_test.rb +1 -0
  98. metadata +265 -0
@@ -0,0 +1,74 @@
1
+ require "test_helper"
2
+
3
+ class TestJavaScriptMerger < Test::Unit::TestCase
4
+
5
+ def setup
6
+ @file_merger = Juicer::Merger::JavaScriptMerger.new
7
+ Juicer::Test::FileSetup.new.create
8
+ end
9
+
10
+ def teardown
11
+ file = path('test_out.js')
12
+ File.delete(file) if File.exists?(file)
13
+ end
14
+
15
+ def test_init
16
+ Juicer::Merger::JavaScriptMerger.publicize_methods do
17
+ assert_equal Juicer::JavaScriptDependencyResolver, @file_merger.dependency_resolver.class
18
+ end
19
+ end
20
+
21
+ def test_merge
22
+ Juicer::Merger::JavaScriptMerger.publicize_methods do
23
+ a_content = <<EOF
24
+ /**
25
+ * @depend b.js
26
+ */
27
+
28
+ /* Dette er a.js */
29
+
30
+ EOF
31
+ content = @file_merger.merge(path('a.js'))
32
+ assert_equal a_content, content
33
+ end
34
+ end
35
+
36
+ def test_constructor
37
+ file_merger = Juicer::Merger::JavaScriptMerger.new(path('a.js'))
38
+ assert_equal 2, file_merger.files.length
39
+ end
40
+
41
+ def test_append
42
+ @file_merger << path('a.js')
43
+ assert_equal 2, @file_merger.files.length
44
+ end
45
+
46
+ def test_save
47
+ a_js = path('a.js')
48
+ b_js = path('b.js')
49
+ merged = <<EOF
50
+ /**
51
+ * @depends a.js
52
+ */
53
+
54
+ /* Dette er b.css */
55
+
56
+ /**
57
+ * @depend b.js
58
+ */
59
+
60
+ /* Dette er a.js */
61
+
62
+ EOF
63
+
64
+ @file_merger << a_js
65
+ ios = StringIO.new
66
+ @file_merger.save(ios)
67
+ assert_equal merged, ios.string
68
+
69
+ output_file = path('test_out.js')
70
+ @file_merger.save(output_file)
71
+
72
+ assert_equal merged, IO.read(output_file)
73
+ end
74
+ end
@@ -0,0 +1,180 @@
1
+ require "test_helper"
2
+
3
+ class TestStylesheetMerger < Test::Unit::TestCase
4
+
5
+ def setup
6
+ @file_merger = Juicer::Merger::StylesheetMerger.new
7
+ Juicer::Test::FileSetup.new.create
8
+ @cwd = Dir.pwd
9
+ Dir.chdir path("")
10
+ end
11
+
12
+ def teardown
13
+ file = path('test_out.css')
14
+ File.delete(file) if File.exists?(file)
15
+ Dir.chdir(@cwd)
16
+ end
17
+
18
+ def test_init
19
+ Juicer::Merger::StylesheetMerger.publicize_methods do
20
+ assert_equal Juicer::CssDependencyResolver, @file_merger.dependency_resolver.class
21
+ end
22
+ end
23
+
24
+ def test_merge
25
+ Juicer::Merger::StylesheetMerger.publicize_methods do
26
+ a_content = "\n\n/* Dette er a.css */\n"
27
+ content = @file_merger.merge(path('a.css'))
28
+ assert_equal a_content + "\n", content
29
+ end
30
+ end
31
+
32
+ def test_constructor
33
+ file_merger = Juicer::Merger::StylesheetMerger.new(path('a.css'))
34
+ assert_equal 2, file_merger.files.length
35
+ end
36
+
37
+ def test_append
38
+ @file_merger << path('a.css')
39
+ assert_equal 2, @file_merger.files.length
40
+ end
41
+
42
+ def test_save
43
+ a_css = path('a.css')
44
+ b_css = path('b.css')
45
+ merged = <<EOF
46
+ /* Dette er b.css */
47
+
48
+
49
+
50
+ /* Dette er a.css */
51
+
52
+ EOF
53
+
54
+ @file_merger << a_css
55
+ ios = StringIO.new
56
+ @file_merger.save(ios)
57
+ assert_equal merged, ios.string
58
+
59
+ output_file = path('test_out.css')
60
+ @file_merger.save(output_file)
61
+
62
+ assert_equal merged, IO.read(output_file)
63
+ end
64
+
65
+ def test_included_files_should_have_referenced_relative_urls_rereferenced
66
+ @file_merger << path("path_test.css")
67
+ ios = StringIO.new
68
+ @file_merger.save(ios)
69
+ files = ios.string.scan(/url\(([^\)]*)\)/).collect { |f| f.first }.uniq.sort
70
+
71
+ assert_equal "a1.css::css/2.gif::images/1.png", files.join("::")
72
+ end
73
+
74
+ def test_resolve_path_should_leave_absolute_urls
75
+ merger = Juicer::Merger::StylesheetMerger.new
76
+ url = "/some/url"
77
+
78
+ Juicer::Merger::StylesheetMerger.publicize_methods do
79
+ assert_equal url, merger.resolve_path(url, nil)
80
+ end
81
+ end
82
+
83
+ def test_resolve_path_error_when_relative_missing_web_root
84
+ merger = Juicer::Merger::StylesheetMerger.new [], :relative_urls => true
85
+
86
+ Juicer::Merger::StylesheetMerger.publicize_methods do
87
+ assert_raise ArgumentError do
88
+ merger.resolve_path("/some/url", nil)
89
+ end
90
+ end
91
+ end
92
+
93
+ def test_resolve_path_should_make_absolute_urls_relative
94
+ merger = Juicer::Merger::StylesheetMerger.new [], :relative_urls => true, :web_root => "/home/usr"
95
+
96
+ Juicer::Merger::StylesheetMerger.publicize_methods do
97
+ merger.instance_eval { @root = Pathname.new "/home/usr/design" }
98
+ assert_equal "../some/url", merger.resolve_path("/some/url", nil)
99
+ end
100
+ end
101
+
102
+ def test_resolve_path_should_leave_full_urls
103
+ merger = Juicer::Merger::StylesheetMerger.new []
104
+ url = "http://test.com"
105
+
106
+ Juicer::Merger::StylesheetMerger.publicize_methods do
107
+ merger.instance_eval { @root = Pathname.new "/home/usr/design" }
108
+ assert_equal url, merger.resolve_path(url, nil)
109
+ end
110
+ end
111
+
112
+ def test_resolve_path_error_when_missing_absolute_web_root
113
+ merger = Juicer::Merger::StylesheetMerger.new [], :absolute_urls => true
114
+
115
+ Juicer::Merger::StylesheetMerger.publicize_methods do
116
+ assert_raise ArgumentError do
117
+ merger.resolve_path("../some/url", nil)
118
+ end
119
+ end
120
+ end
121
+
122
+ def test_resolve_path_should_make_relative_urls_absolute
123
+ merger = Juicer::Merger::StylesheetMerger.new [], :absolute_urls => true, :web_root => "/home/usr"
124
+
125
+ Juicer::Merger::StylesheetMerger.publicize_methods do
126
+ merger.instance_eval { @root = Pathname.new "/home/usr/design" }
127
+ assert_equal "/design/images/1.png", merger.resolve_path("../images/1.png", "/home/usr/design/css")
128
+ end
129
+ end
130
+
131
+ def test_resolve_path_should_redefine_relative_urls
132
+ merger = Juicer::Merger::StylesheetMerger.new [], :relative_urls => true
133
+
134
+ Juicer::Merger::StylesheetMerger.publicize_methods do
135
+ merger.instance_eval { @root = Pathname.new "/home/usr/design2/css" }
136
+ assert_equal "../../design/images/1.png", merger.resolve_path("../images/1.png", "/home/usr/design/css")
137
+ end
138
+ end
139
+
140
+ def test_resolve_path_should_redefine_absolute_urls
141
+ merger = Juicer::Merger::StylesheetMerger.new [], :relative_urls => true, :web_root => "/home/usr"
142
+
143
+ Juicer::Merger::StylesheetMerger.publicize_methods do
144
+ merger.instance_eval { @root = Pathname.new "/home/usr/design2/css" }
145
+ assert_equal "../../images/1.png", merger.resolve_path("/images/1.png", "/home/usr/design/css")
146
+ end
147
+ end
148
+
149
+ def test_resolve_path_with_hosts_should_cycle_asset_hosts
150
+ merger = Juicer::Merger::StylesheetMerger.new [], :hosts => ["http://assets1", "http://assets2", "http://assets3"]
151
+
152
+ Juicer::Merger::StylesheetMerger.publicize_methods do
153
+ merger.instance_eval { @root = Pathname.new "/home/usr/design2/css" }
154
+ assert_equal "http://assets1/images/1.png", merger.resolve_path("/images/1.png", nil)
155
+ assert_equal "http://assets2/images/1.png", merger.resolve_path("/images/1.png", nil)
156
+ assert_equal "http://assets3/images/1.png", merger.resolve_path("/images/1.png", nil)
157
+ assert_equal "http://assets1/images/1.png", merger.resolve_path("/images/1.png", nil)
158
+ end
159
+ end
160
+
161
+ def test_resolve_paths_should_handle_relative_web_roots
162
+ merger = Juicer::Merger::StylesheetMerger.new [], :web_root => "test/data", :relative_urls => true
163
+ merger << File.expand_path("css/test2.css")
164
+
165
+ Juicer::Merger::StylesheetMerger.publicize_methods do
166
+ merger.instance_eval { @root = Pathname.new File.expand_path("test/data/css") }
167
+ assert_equal "../images/1.png", merger.resolve_path("/images/1.png", nil)
168
+ end
169
+ end
170
+
171
+ def test_cycle_asset_hosts_should_use_same_host_for_same_url
172
+ @file_merger = Juicer::Merger::StylesheetMerger.new nil, :hosts => ["http://assets1", "http://assets2", "http://assets3"]
173
+ @file_merger << path("path_test2.css")
174
+ ios = StringIO.new
175
+ @file_merger.save(ios)
176
+ files = ios.string.scan(/url\(([^\)]*)\)/).collect { |f| f.first }
177
+
178
+ assert_equal "1/images/1.png::2/css/2.gif::3/a1.css::2/css/2.gif::1/a2.css".gsub(/(\d\/)/, 'http://assets\1'), files.join("::")
179
+ end
180
+ end
@@ -0,0 +1,107 @@
1
+ require "test_helper"
2
+ require "juicer/minifyer/closure_compiler"
3
+
4
+ class ClosureCompilerTest < Test::Unit::TestCase
5
+ def setup
6
+ @jar = "compiler.jar"
7
+ @input = "in-file.css"
8
+ @output = "out-file.css"
9
+ @cmd = %Q{-jar "#@jar"}
10
+ @closure = Juicer::Minifyer::ClosureCompiler.new
11
+ @closure.stubs(:locate_jar).returns(@jar)
12
+ end
13
+
14
+ context "#save" do
15
+ should "overwrite existing file" do
16
+ @closure.expects(:execute).with(%Q{#@cmd -js_output_file "#@output" -js "#@output"})
17
+ @closure.save(@output, @output)
18
+ end
19
+
20
+ should "write compressed input to output" do
21
+ @closure.expects(:execute).with(%Q{#@cmd -js_output_file "#@output" -js "#@input"})
22
+ @closure.save(@input, @output)
23
+ end
24
+
25
+ should "create non-existant path" do
26
+ output = "some/nested/directory"
27
+ @closure.expects(:execute).with(%Q{#@cmd -js_output_file "#{output}/file.css" -js "#@input"})
28
+ FileUtils.expects(:mkdir_p).with(output)
29
+ @closure.save(@input, "#{output}/file.css")
30
+ end
31
+ end
32
+
33
+ context "locating jar" do
34
+ setup do
35
+ # Avoid developer env settings
36
+ @closure_home = ENV['CLOSUREC_HOME']
37
+ ENV.delete('CLOSUREC_HOME')
38
+ end
39
+
40
+ teardown do
41
+ ENV['CLOSUREC_HOME'] = @closure_home
42
+ File.delete('compiler-2.3.4.jar') if File.exists?('compiler-2.3.4.jar')
43
+ File.delete('compiler-2.3.5.jar') if File.exists?('compiler-2.3.5.jar')
44
+ File.delete('compiler.jar') if File.exists?('compiler.jar')
45
+ FileUtils.rm_rf("another") if File.exists?("another")
46
+ end
47
+
48
+ should "not find jar when no jars on path" do
49
+ Juicer::Minifyer::ClosureCompiler.publicize_methods do
50
+ closure = Juicer::Minifyer::ClosureCompiler.new
51
+
52
+ assert_nil closure.locate_jar
53
+ end
54
+ end
55
+
56
+ should "find only jar in path" do
57
+ Juicer::Minifyer::ClosureCompiler.publicize_methods do
58
+ File.open('compiler-2.3.4.jar', 'w') { |f| f.puts '' }
59
+ closure = Juicer::Minifyer::ClosureCompiler.new
60
+
61
+ assert_equal File.expand_path('compiler-2.3.4.jar'), closure.locate_jar
62
+ end
63
+ end
64
+
65
+ should "find most recent of two jars on path" do
66
+ Juicer::Minifyer::ClosureCompiler.publicize_methods do
67
+ # Create files
68
+ File.open('compiler-2.3.4.jar', 'w') { |f| f.puts '' }
69
+ File.open('compiler-2.3.5.jar', 'w') { |f| f.puts '' }
70
+
71
+ closure = Juicer::Minifyer::ClosureCompiler.new
72
+
73
+ # Test
74
+ assert_equal File.expand_path('compiler-2.3.5.jar'), closure.locate_jar
75
+ end
76
+ end
77
+
78
+ should "find most recent of three jar files on path" do
79
+ Juicer::Minifyer::ClosureCompiler.publicize_methods do
80
+ # Create files
81
+ File.open('compiler-2.3.4.jar', 'w') { |f| f.puts '' }
82
+ File.open('compiler-2.3.5.jar', 'w') { |f| f.puts '' }
83
+ File.open('compiler.jar', 'w') { |f| f.puts '' }
84
+
85
+ closure = Juicer::Minifyer::ClosureCompiler.new
86
+
87
+ # Test
88
+ assert_equal File.expand_path('compiler.jar'), closure.locate_jar
89
+ end
90
+ end
91
+
92
+ should "find jar in custom directory" do
93
+ Juicer::Minifyer::ClosureCompiler.publicize_methods do
94
+ # Prepare
95
+ Dir.mkdir('another')
96
+ File.open('another/compiler-2.3.4.jar', 'w') { |f| f.puts "" }
97
+
98
+ closure = Juicer::Minifyer::ClosureCompiler.new
99
+
100
+ # Test
101
+ assert_nil closure.locate_jar
102
+ closure = Juicer::Minifyer::ClosureCompiler.new({ :bin_path => 'another' })
103
+ assert_equal File.expand_path('another/compiler-2.3.4.jar'), closure.locate_jar
104
+ end
105
+ end
106
+ end
107
+ end
@@ -0,0 +1,116 @@
1
+ require "test_helper"
2
+
3
+ class TestYuiCompressor < Test::Unit::TestCase
4
+ def setup
5
+ @jar = "yuicompressor-2.4.2.jar"
6
+ @input = "in-file.css"
7
+ @output = "out-file.css"
8
+ @cmd = %Q{-jar "#@jar"}
9
+ @yui_compressor = Juicer::Minifyer::YuiCompressor.new
10
+ @yui_compressor.stubs(:locate_jar).returns(@jar)
11
+ end
12
+
13
+ context "#save" do
14
+ should "overwrite existing file" do
15
+ @yui_compressor.expects(:execute).with(%Q{#@cmd -o "#@output" "#@output"})
16
+ @yui_compressor.save(@output)
17
+ end
18
+
19
+ should "use provided symbol type" do
20
+ @yui_compressor.expects(:execute).with(%Q{#@cmd -o "#@output" "#@input"})
21
+ @yui_compressor.save(@input, @output, :css)
22
+ end
23
+
24
+ should "use provided string type" do
25
+ @yui_compressor.expects(:execute).with(%Q{#@cmd -o "#@output" "#@input"})
26
+ @yui_compressor.save(@input, @output, "css")
27
+ end
28
+
29
+ should "write compressed input to output" do
30
+ @yui_compressor.expects(:execute).with(%Q{#@cmd -o "#@output" "#@input"})
31
+ @yui_compressor.save(@input, @output)
32
+ end
33
+
34
+ should "create non-existant path" do
35
+ output = "some/nested/directory"
36
+ @yui_compressor.expects(:execute).with(%Q{#@cmd -o "#{output}/file.css" "#@input"})
37
+ FileUtils.expects(:mkdir_p).with(output)
38
+ @yui_compressor.save(@input, "#{output}/file.css")
39
+ end
40
+ end
41
+
42
+ context "locating jar" do
43
+ setup do
44
+ # Avoid developer env settings
45
+ @yuic_home = ENV['YUIC_HOME']
46
+ ENV.delete('YUIC_HOME')
47
+ end
48
+
49
+ teardown do
50
+ ENV['YUIC_HOME'] = @yuic_home
51
+ File.delete('yuicompressor-2.3.4.jar') if File.exists?('yuicompressor-2.3.4.jar')
52
+ File.delete('yuicompressor-2.3.5.jar') if File.exists?('yuicompressor-2.3.5.jar')
53
+ File.delete('yuicompressor.jar') if File.exists?('yuicompressor.jar')
54
+ FileUtils.rm_rf("another") if File.exists?("another")
55
+ end
56
+
57
+ should "not find jar when no jars on path" do
58
+ Juicer::Minifyer::YuiCompressor.publicize_methods do
59
+ yui_compressor = Juicer::Minifyer::YuiCompressor.new
60
+
61
+ assert_nil yui_compressor.locate_jar
62
+ end
63
+ end
64
+
65
+ should "find only jar in path" do
66
+ Juicer::Minifyer::YuiCompressor.publicize_methods do
67
+ File.open('yuicompressor-2.3.4.jar', 'w') { |f| f.puts '' }
68
+ yui_compressor = Juicer::Minifyer::YuiCompressor.new
69
+
70
+ assert_equal File.expand_path('yuicompressor-2.3.4.jar'), yui_compressor.locate_jar
71
+ end
72
+ end
73
+
74
+ should "find most recent of two jars on path" do
75
+ Juicer::Minifyer::YuiCompressor.publicize_methods do
76
+ # Create files
77
+ File.open('yuicompressor-2.3.4.jar', 'w') { |f| f.puts '' }
78
+ File.open('yuicompressor-2.3.5.jar', 'w') { |f| f.puts '' }
79
+
80
+ yui_compressor = Juicer::Minifyer::YuiCompressor.new
81
+
82
+ # Test
83
+ assert_equal File.expand_path('yuicompressor-2.3.5.jar'), yui_compressor.locate_jar
84
+ end
85
+ end
86
+
87
+ should "find most recent of three jar files on path" do
88
+ Juicer::Minifyer::YuiCompressor.publicize_methods do
89
+ # Create files
90
+ File.open('yuicompressor-2.3.4.jar', 'w') { |f| f.puts '' }
91
+ File.open('yuicompressor-2.3.5.jar', 'w') { |f| f.puts '' }
92
+ File.open('yuicompressor.jar', 'w') { |f| f.puts '' }
93
+
94
+ yui_compressor = Juicer::Minifyer::YuiCompressor.new
95
+
96
+ # Test
97
+ assert_equal File.expand_path('yuicompressor.jar'), yui_compressor.locate_jar
98
+ end
99
+ end
100
+
101
+ should "find jar in custom directory" do
102
+ Juicer::Minifyer::YuiCompressor.publicize_methods do
103
+ # Prepare
104
+ Dir.mkdir('another')
105
+ File.open('another/yuicompressor-2.3.4.jar', 'w') { |f| f.puts "" }
106
+
107
+ yui_compressor = Juicer::Minifyer::YuiCompressor.new
108
+
109
+ # Test
110
+ assert_nil yui_compressor.locate_jar
111
+ yui_compressor = Juicer::Minifyer::YuiCompressor.new({ :bin_path => 'another' })
112
+ assert_equal File.expand_path('another/yuicompressor-2.3.4.jar'), yui_compressor.locate_jar
113
+ end
114
+ end
115
+ end
116
+ end