-
Notifications
You must be signed in to change notification settings - Fork 197
Expand file tree
/
Copy pathtest_command_line.rb
More file actions
53 lines (42 loc) · 1.75 KB
/
test_command_line.rb
File metadata and controls
53 lines (42 loc) · 1.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
$: << File.expand_path(File.dirname(__FILE__) + "/..") ; require 'test_helper'
require 'zlib'
class CommandLineTest < Test::Unit::TestCase
JAMMIT = "bundle exec bin/jammit"
def setup
ENV['RAILS_ROOT'] = 'test'
end
def teardown
begin
FileUtils.rm_r('test/precache')
rescue Errno::ENOENT
end
end
def test_version_and_help_can_run
assert system("#{ JAMMIT } -v > /dev/null")
assert system("#{ JAMMIT } -h > /dev/null")
end
def test_jammit_precaching
system("#{ JAMMIT } -c test/config/assets.yml -o test/precache -u http://www.example.com")
assert_equal PRECACHED_FILES, glob('test/precache/*')
assert_equal zlib_read('test/precache/css_test-datauri.css.gz'),
File.read('test/fixtures/jammed/css_test-datauri.css')
assert_equal zlib_read('test/precache/jst_test.js.gz'),
File.read('test/fixtures/jammed/jst_test_from_cli.js')
assert_equal zlib_read('test/precache/js_test_with_templates.js.gz'),
File.read('test/fixtures/jammed/js_test_with_templates.js')
end
def test_lazy_precaching
system("#{ JAMMIT } -c test/config/assets.yml -o test/precache -u http://www.example.com")
assert_equal PRECACHED_FILES, glob('test/precache/*')
mtime = File.mtime(PRECACHED_FILES.first)
system("#{ JAMMIT } -c test/config/assets.yml -o test/precache -u http://www.example.com")
assert_equal File.mtime(PRECACHED_FILES.first), mtime
system("#{ JAMMIT } -c test/config/assets.yml -o test/precache -u http://www.example.com --force")
new_mtime = File.mtime(PRECACHED_FILES.first)
assert new_mtime > mtime,
"#{ PRECACHED_FILES.first } mtime - #{ new_mtime } - greater than #{ mtime }"
end
def zlib_read(filename)
Zlib::GzipReader.open(filename) {|f| f.read }
end
end