dassets 0.14.5 → 0.15.0

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.
@@ -1,140 +1,144 @@
1
- require 'assert'
2
- require 'dassets/asset_file'
1
+ require "assert"
2
+ require "dassets/asset_file"
3
3
 
4
- require 'fileutils'
5
- require 'dassets/file_store'
6
- require 'dassets/source_proxy'
4
+ require "fileutils"
5
+ require "dassets/file_store"
6
+ require "dassets/source_proxy"
7
7
 
8
8
  class Dassets::AssetFile
9
-
10
9
  class UnitTests < Assert::Context
11
10
  desc "Dassets::AssetFile"
11
+ subject { @asset_file }
12
+
12
13
  setup do
13
- @asset_file = Dassets::AssetFile.new('file1.txt')
14
+ @asset_file = Dassets::AssetFile.new("file1.txt")
14
15
  end
15
- subject{ @asset_file }
16
16
 
17
17
  should have_readers :digest_path, :dirname, :extname, :basename, :source_proxy
18
18
  should have_imeths :digest!, :url, :href, :fingerprint, :content
19
19
  should have_imeths :mtime, :size, :mime_type, :exists?, :==
20
20
 
21
21
  should "know its digest path, dirname, extname, and basename" do
22
- assert_equal 'file1.txt', subject.digest_path
23
- assert_equal '.', subject.dirname
24
- assert_equal '.txt', subject.extname
25
- assert_equal 'file1', subject.basename
22
+ assert_that(subject.digest_path).equals("file1.txt")
23
+ assert_that(subject.dirname).equals(".")
24
+ assert_that(subject.extname).equals(".txt")
25
+ assert_that(subject.basename).equals("file1")
26
26
  end
27
27
 
28
28
  should "use its source proxy attrs as its own" do
29
- assert_equal subject.source_proxy.mtime.httpdate, subject.mtime
30
- assert_equal Rack::Utils.bytesize(subject.content), subject.size
31
- assert_equal "text/plain", subject.mime_type
32
- assert_equal subject.source_proxy.response_headers, subject.response_headers
33
- assert subject.exists?
34
-
35
- null_file = Dassets::AssetFile.new('')
36
- assert_nil null_file.mtime
37
- assert_nil null_file.size
38
- assert_nil null_file.mime_type
39
- assert_not null_file.exists?
40
- assert_equal null_file.source_proxy.response_headers, null_file.response_headers
29
+ assert_that(subject.mtime).equals(subject.source_proxy.mtime.httpdate)
30
+ assert_that(subject.size).equals(subject.content.bytesize)
31
+ assert_that(subject.mime_type).equals("text/plain")
32
+ assert_that(subject.response_headers)
33
+ .equals(subject.source_proxy.response_headers)
34
+ assert_that(subject.exists?).is_true
35
+
36
+ null_file = Dassets::AssetFile.new("")
37
+ assert_that(null_file.mtime).is_nil
38
+ assert_that(null_file.size).is_nil
39
+ assert_that(null_file.mime_type).is_nil
40
+ assert_that(null_file.exists?).is_false
41
+ assert_that(null_file.response_headers)
42
+ .equals(null_file.source_proxy.response_headers)
41
43
  end
42
44
 
43
45
  should "know its source proxy" do
44
46
  source_proxy = subject.source_proxy
45
- assert_not_nil source_proxy
46
- assert_kind_of Dassets::SourceProxy, source_proxy
47
- assert_equal subject.digest_path, source_proxy.digest_path
48
- assert_equal Dassets.config.content_cache, source_proxy.content_cache
49
- assert_equal Dassets.config.fingerprint_cache, source_proxy.fingerprint_cache
47
+ assert_that(source_proxy).is_not_nil
48
+ assert_that(source_proxy).is_kind_of(Dassets::SourceProxy)
49
+ assert_that(source_proxy.digest_path).equals(subject.digest_path)
50
+ assert_that(source_proxy.content_cache)
51
+ .equals(Dassets.config.content_cache)
52
+ assert_that(source_proxy.fingerprint_cache)
53
+ .equals(Dassets.config.fingerprint_cache)
50
54
  end
51
55
 
52
56
  should "have a fingerprint" do
53
- assert_not_nil subject.fingerprint
57
+ assert_that(subject.fingerprint).is_not_nil
54
58
  end
55
59
 
56
60
  should "get its fingerprint from its source proxy if none is given" do
57
- af = Dassets::AssetFile.new('file1.txt')
58
- assert_equal af.source_proxy.fingerprint, af.fingerprint
61
+ af = Dassets::AssetFile.new("file1.txt")
62
+ assert_that(af.fingerprint).equals(af.source_proxy.fingerprint)
59
63
  end
60
64
 
61
65
  should "know it's content" do
62
- assert_equal "file1.txt\n", subject.content
66
+ assert_that(subject.content).equals("file1.txt\n")
63
67
 
64
- null_file = Dassets::AssetFile.new('')
65
- assert_nil null_file.content
68
+ null_file = Dassets::AssetFile.new("")
69
+ assert_that(null_file.content).is_nil
66
70
  end
67
71
 
68
72
  should "get its content from its source proxy if no output file" do
69
- digest_path = 'nested/a-thing.txt.no-use'
73
+ digest_path = "nested/a-thing.txt.no-use"
70
74
  exp_content = "thing\n\nDUMB\nUSELESS"
71
75
 
72
76
  without_output = Dassets::AssetFile.new(digest_path)
73
- assert_equal exp_content, without_output.content
77
+ assert_that(without_output.content).equals(exp_content)
74
78
  end
75
79
 
76
- should "build it's url/href from the file, fingerpint and any configured base url" do
77
- assert_match /^\/file1-[a-f0-9]{32}\.txt$/, subject.url
78
- assert_match subject.url, subject.href
80
+ should "build it's url/href from the file, fingerpint, and "\
81
+ "any configured base url" do
82
+ assert_that(subject.url).matches(/^\/file1-[a-f0-9]{32}\.txt$/)
83
+ assert_that(subject.href).matches(subject.url)
79
84
 
80
- nested = Dassets::AssetFile.new('nested/file1.txt')
81
- assert_equal "/nested/file1-.txt", nested.url
82
- assert_equal nested.url, nested.href
85
+ nested = Dassets::AssetFile.new("nested/file1.txt")
86
+ assert_that(nested.url).equals("/nested/file1-.txt")
87
+ assert_that(nested.href).equals(nested.url)
83
88
 
84
89
  base_url = Factory.url
85
90
  Assert.stub(Dassets.config, :base_url){ base_url }
86
91
 
87
- assert_match /^#{base_url}\/file1-[a-f0-9]{32}\.txt$/, subject.url
88
- assert_match subject.url, subject.href
92
+ assert_that(subject.url).matches(/^#{base_url}\/file1-[a-f0-9]{32}\.txt$/)
93
+ assert_that(subject.href).matches(subject.url)
89
94
 
90
- assert_equal "#{base_url}/nested/file1-.txt", nested.url
91
- assert_equal nested.url, nested.href
95
+ assert_that(nested.url).equals("#{base_url}/nested/file1-.txt")
96
+ assert_that(nested.href).equals(nested.url)
92
97
  end
93
98
 
94
99
  should "not memoize its attributes" do
95
100
  url1 = subject.url
96
101
  url2 = subject.url
97
- assert_not_same url2, url1
102
+ assert_that(url1).is_not(url2)
98
103
 
99
104
  fingerprint1 = subject.fingerprint
100
105
  fingerprint2 = subject.fingerprint
101
- assert_not_same fingerprint2, fingerprint1
106
+ assert_that(fingerprint1).is_not(fingerprint2)
102
107
 
103
108
  content1 = subject.content
104
109
  content2 = subject.content
105
- assert_not_same content2, content1
110
+ assert_that(content1).is_not(content2)
106
111
 
107
112
  mtime1 = subject.mtime
108
113
  mtime2 = subject.mtime
109
- assert_not_same mtime2, mtime1
114
+ assert_that(mtime1).is_not(mtime2)
110
115
  end
111
-
112
116
  end
113
117
 
114
118
  class DigestTests < UnitTests
115
119
  desc "being digested with an output path configured"
120
+
116
121
  setup do
117
122
  base_url = Factory.base_url
118
123
  Assert.stub(Dassets.config, :base_url){ base_url }
119
- Dassets.config.file_store TEST_SUPPORT_PATH.join('public').to_s
124
+ Dassets.config.file_store TEST_SUPPORT_PATH.join("public").to_s
120
125
 
121
126
  @save_path = @asset_file.digest!
122
127
  @outfile = Dassets.config.file_store.store_path(@asset_file.url)
123
128
  end
129
+
124
130
  teardown do
125
131
  FileUtils.rm_rf(Dassets.config.file_store.root.to_s)
126
- Dassets.config.file_store Dassets::FileStore::NullStore.new
132
+ Dassets.config.file_store Dassets::NullFileStore.new
127
133
  end
128
134
 
129
135
  should "return the asset file url" do
130
- assert_equal @outfile, @save_path
136
+ assert_that(@save_path).equals(@outfile)
131
137
  end
132
138
 
133
139
  should "compile and write an asset file to the output path" do
134
- assert_file_exists @outfile
135
- assert_equal subject.content, File.read(@outfile)
140
+ assert_that(@outfile).is_a_file
141
+ assert_that(File.read(@outfile)).equals(subject.content)
136
142
  end
137
-
138
143
  end
139
-
140
144
  end
@@ -1,53 +1,32 @@
1
- require 'assert'
2
- require 'dassets/cache'
3
-
4
- module Dassets::Cache
1
+ require "assert"
2
+ require "dassets/cache"
5
3
 
4
+ class Dassets::MemCache
6
5
  class UnitTests < Assert::Context
7
- desc "Dassets::Cache"
8
-
9
- should "define an in-memory cache handler" do
10
- assert MemCache
11
- end
12
-
13
- should "define a no-op cache handler" do
14
- assert NoCache
15
- end
16
-
17
- end
18
-
19
- class MemCacheTests < UnitTests
20
- desc "MemCache"
21
- setup do
22
- @cache = MemCache.new
23
- end
24
- subject{ @cache }
6
+ desc "Dassets::MemCache"
7
+ subject { Dassets::MemCache.new }
25
8
 
26
9
  should have_imeths :keys, :[], :[]=
27
10
 
28
11
  should "cache given key/value pairs in memory" do
29
12
  val = []
30
- subject['something'] = val
31
- assert_same val, subject['something']
13
+ subject["something"] = val
14
+ assert_that(subject["something"]).is(val)
32
15
  end
33
-
34
16
  end
17
+ end
35
18
 
36
- class NoCacheTests < UnitTests
37
- desc "NoCache"
38
- setup do
39
- @cache = NoCache.new
40
- end
41
- subject{ @cache }
19
+ class Dassets::NoCache
20
+ class UnitTests < Assert::Context
21
+ desc "Dassets::NoCache"
22
+ subject { Dassets::NoCache.new }
42
23
 
43
24
  should have_imeths :keys, :[], :[]=
44
25
 
45
26
  should "not cache given key/value pairs in memory" do
46
27
  val = []
47
- subject['something'] = val
48
- assert_not_same val, subject['something']
28
+ subject["something"] = val
29
+ assert_that(subject["something"]).is_not(val)
49
30
  end
50
-
51
31
  end
52
-
53
32
  end
@@ -1,17 +1,17 @@
1
- require 'assert'
2
- require 'dassets/config'
1
+ require "assert"
2
+ require "dassets/config"
3
3
 
4
- require 'dassets/cache'
5
- require 'dassets/file_store'
4
+ require "dassets/cache"
5
+ require "dassets/file_store"
6
6
 
7
7
  class Dassets::Config
8
-
9
8
  class UnitTests < Assert::Context
10
9
  desc "Dassets::Config"
10
+ subject { @config }
11
+
11
12
  setup do
12
13
  @config = Dassets::Config.new
13
14
  end
14
- subject{ @config }
15
15
 
16
16
  should have_readers :combinations
17
17
  should have_imeths :reset
@@ -20,83 +20,83 @@ class Dassets::Config
20
20
  should have_imeths :source, :combination, :combination?
21
21
 
22
22
  should "reset its sources and combination on `reset`" do
23
- assert_empty subject.sources
24
- assert_empty subject.combinations
23
+ assert_that(subject.sources).is_empty
24
+ assert_that(subject.combinations).is_empty
25
25
 
26
26
  path = Factory.path
27
27
  subject.source(path)
28
28
  subject.combination path, [Factory.path]
29
- assert_equal 1, subject.sources.size
30
- assert_equal 1, subject.combinations.size
29
+ assert_that(subject.sources.size).equals(1)
30
+ assert_that(subject.combinations.size).equals(1)
31
31
 
32
32
  subject.reset
33
- assert_empty subject.sources
34
- assert_empty subject.combinations
33
+ assert_that(subject.sources).is_empty
34
+ assert_that(subject.combinations).is_empty
35
35
  end
36
36
 
37
37
  should "have no base url by default" do
38
- assert_nil subject.base_url
38
+ assert_that(subject.base_url).is_nil
39
39
  end
40
40
 
41
41
  should "set non-nil base urls" do
42
42
  url = Factory.url
43
43
  subject.base_url url
44
- assert_equal url, subject.base_url
44
+ assert_that(subject.base_url).equals(url)
45
45
 
46
46
  subject.base_url(nil)
47
- assert_equal url, subject.base_url
47
+ assert_that(subject.base_url).equals(url)
48
48
  end
49
49
 
50
50
  should "force set any base urls" do
51
51
  url = Factory.url
52
52
  subject.set_base_url url
53
- assert_equal url, subject.base_url
53
+ assert_that(subject.base_url).equals(url)
54
54
 
55
55
  subject.set_base_url(nil)
56
- assert_nil subject.base_url
56
+ assert_that(subject.base_url).is_nil
57
57
  end
58
58
 
59
59
  should "default the file store option to a null file store" do
60
- assert_kind_of Dassets::FileStore::NullStore, subject.file_store
60
+ assert_that(subject.file_store).is_kind_of(Dassets::NullFileStore)
61
61
  end
62
62
 
63
63
  should "configure non-nil file stores" do
64
64
  store_root = Factory.path
65
65
  subject.file_store(store_root)
66
- assert_equal store_root, subject.file_store.root
66
+ assert_that(subject.file_store.root).equals(store_root)
67
67
 
68
68
  store = Dassets::FileStore.new(Factory.path)
69
69
  subject.file_store(store)
70
- assert_equal store, subject.file_store
70
+ assert_that(subject.file_store).equals(store)
71
71
 
72
72
  subject.file_store(nil)
73
- assert_equal store, subject.file_store
73
+ assert_that(subject.file_store).equals(store)
74
74
  end
75
75
 
76
76
  should "default its content cache" do
77
- assert_instance_of Dassets::Cache::NoCache, subject.content_cache
77
+ assert_that(subject.content_cache).is_instance_of(Dassets::NoCache)
78
78
  end
79
79
 
80
80
  should "configure non-nil content caches" do
81
- cache = Dassets::Cache::MemCache.new
81
+ cache = Dassets::MemCache.new
82
82
  subject.content_cache(cache)
83
- assert_equal cache, subject.content_cache
83
+ assert_that(subject.content_cache).equals(cache)
84
84
 
85
85
  subject.content_cache(nil)
86
- assert_equal cache, subject.content_cache
86
+ assert_that(subject.content_cache).equals(cache)
87
87
  end
88
88
 
89
89
  should "default its fingerprint cache" do
90
- assert_instance_of Dassets::Cache::NoCache, subject.fingerprint_cache
90
+ assert_instance_of Dassets::NoCache, subject.fingerprint_cache
91
91
  end
92
92
 
93
93
  should "configure non-nil fingerprint caches" do
94
- cache = Dassets::Cache::MemCache.new
94
+ cache = Dassets::MemCache.new
95
95
  subject.fingerprint_cache(cache)
96
- assert_equal cache, subject.fingerprint_cache
96
+ assert_that(subject.fingerprint_cache).equals(cache)
97
97
 
98
98
  subject.fingerprint_cache(nil)
99
- assert_equal cache, subject.fingerprint_cache
99
+ assert_that(subject.fingerprint_cache).equals(cache)
100
100
  end
101
101
 
102
102
  should "register new sources with the `source` method" do
@@ -104,35 +104,39 @@ class Dassets::Config
104
104
  filter = proc{ |paths| [] }
105
105
  subject.source(path){ |s| s.filter(&filter) }
106
106
 
107
- assert_equal 1, subject.sources.size
108
- assert_kind_of Dassets::Source, subject.sources.first
109
- assert_equal path, subject.sources.first.path
110
- assert_equal filter, subject.sources.first.filter
107
+ assert_that(subject.sources.size).equals(1)
108
+ assert_that(subject.sources.first).is_kind_of(Dassets::Source)
109
+ assert_that(subject.sources.first.path).equals(path)
110
+ assert_that(subject.sources.first.filter).equals(filter)
111
111
  end
112
112
 
113
113
  should "know its combinations and return the keyed digest path by default" do
114
- assert_kind_of ::Hash, subject.combinations
115
- assert_equal ['some/digest.path'], subject.combinations['some/digest.path']
114
+ assert_that(subject.combinations).is_kind_of(::Hash)
115
+ assert_that(subject.combinations["some/digest.path"])
116
+ .equals(["some/digest.path"])
116
117
  end
117
118
 
118
119
  should "allow registering new combinations" do
119
- assert_equal ['some/digest.path'], subject.combinations['some/digest.path']
120
- exp_combination = ['some/other.path', 'and/another.path']
121
- subject.combination 'some/digest.path', exp_combination
122
- assert_equal exp_combination, subject.combinations['some/digest.path']
123
-
124
- assert_equal ['test/digest.path'], subject.combinations['test/digest.path']
125
- subject.combination 'test/digest.path', ['some/other.path']
126
- assert_equal ['some/other.path'], subject.combinations['test/digest.path']
120
+ assert_that(subject.combinations["some/digest.path"])
121
+ .equals(["some/digest.path"])
122
+ exp_combination = ["some/other.path", "and/another.path"]
123
+ subject.combination "some/digest.path", exp_combination
124
+ assert_that(subject.combinations["some/digest.path"])
125
+ .equals(exp_combination)
126
+
127
+ assert_that(subject.combinations["test/digest.path"])
128
+ .equals(["test/digest.path"])
129
+ subject.combination "test/digest.path", ["some/other.path"]
130
+ assert_that(subject.combinations["test/digest.path"])
131
+ .equals(["some/other.path"])
127
132
  end
128
133
 
129
- should "know which digest paths are actual combinations and which are just pass-thrus" do
130
- subject.combination 'some/combination.path', ['some.path', 'another.path']
134
+ should "know which digest paths are actual combinations and which are "\
135
+ "just pass-thrus" do
136
+ subject.combination "some/combination.path", ["some.path", "another.path"]
131
137
 
132
- assert subject.combination? 'some/combination.path'
133
- assert_not subject.combination? 'some/non-combo.path'
138
+ assert_that(subject.combination?("some/combination.path")).is_true
139
+ assert_that(subject.combination?("some/non-combo.path")).is_false
134
140
  end
135
-
136
141
  end
137
-
138
142
  end