dassets 0.14.5 → 0.15.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,80 +1,65 @@
1
- require 'assert'
2
- require 'dassets'
1
+ require "assert"
2
+ require "dassets"
3
3
 
4
- require 'fileutils'
5
- require 'dassets/asset_file'
4
+ require "fileutils"
5
+ require "dassets/asset_file"
6
6
 
7
7
  module Dassets
8
-
9
8
  class UnitTests < Assert::Context
10
9
  desc "Dassets"
11
- subject{ Dassets }
10
+ subject { Dassets }
12
11
 
13
12
  should have_imeths :config, :configure, :init, :reset
14
13
  should have_imeths :asset_file, :[], :source_files, :combinations
15
14
 
16
15
  should "return a `Config` instance with the `config` method" do
17
- assert_kind_of Config, subject.config
16
+ assert_that(subject.config).is_kind_of(Dassets::Config)
18
17
  end
19
18
 
20
19
  should "know how to reset itself" do
21
20
  config_reset_called = false
22
- Assert.stub(subject.config, :reset){ config_reset_called = true }
21
+ Assert.stub(subject.config, :reset) { config_reset_called = true }
23
22
 
24
- file1 = subject['nested/file3.txt']
23
+ file1 = subject["nested/file3.txt"]
25
24
 
26
25
  subject.reset
27
26
 
28
- file2 = subject['nested/file3.txt']
29
- assert_not_same file2, file1
30
- assert_true config_reset_called
27
+ file2 = subject["nested/file3.txt"]
28
+ assert_that(file2).is_not(file1)
29
+ assert_that(config_reset_called).is_true
31
30
  end
32
31
 
33
32
  should "return asset files given their digest path " do
34
- file = subject.asset_file('nested/file3.txt')
35
-
36
- assert_kind_of subject::AssetFile, file
37
- assert_equal 'nested/file3.txt', file.digest_path
38
- assert_equal 'd41d8cd98f00b204e9800998ecf8427e', file.fingerprint
33
+ file = subject.asset_file("nested/file3.txt")
39
34
 
40
- file = subject['nested/file3.txt']
41
-
42
- assert_kind_of subject::AssetFile, file
43
- assert_equal 'nested/file3.txt', file.digest_path
44
- assert_equal 'd41d8cd98f00b204e9800998ecf8427e', file.fingerprint
35
+ assert_that(file).is_kind_of(subject::AssetFile)
36
+ assert_that(file.digest_path).equals("nested/file3.txt")
37
+ assert_that(file.fingerprint).equals("d41d8cd98f00b204e9800998ecf8427e")
45
38
  end
46
39
 
47
40
  should "cache asset files" do
48
- file1 = subject.asset_file('nested/file3.txt')
49
- file2 = subject.asset_file('nested/file3.txt')
50
-
51
- assert_same file2, file1
41
+ file1 = subject.asset_file("nested/file3.txt")
42
+ file2 = subject.asset_file("nested/file3.txt")
52
43
 
53
- file1 = subject['nested/file3.txt']
54
- file2 = subject['nested/file3.txt']
55
-
56
- assert_same file2, file1
44
+ assert_that(file2).is(file1)
57
45
  end
58
46
 
59
47
  should "complain if digest path is not found using the index operator" do
60
- assert_nothing_raised do
61
- subject.asset_file('path/not/found.txt')
62
- end
63
- assert_raises AssetFileError do
64
- subject['path/not/found.txt']
65
- end
48
+ assert_that(-> {
49
+ subject.asset_file("path/not/found.txt")
50
+ }).does_not_raise
51
+
52
+ assert_that { subject["path/not/found.txt"] }.raises(AssetFileError)
66
53
  end
67
54
 
68
55
  should "know its list of configured source files" do
69
56
  exp = Dassets::SourceFiles.new(subject.config.sources)
70
- assert_equal exp, subject.source_files
57
+ assert_that(subject.source_files).equals(exp)
71
58
  end
72
59
 
73
60
  should "know its configured combinations" do
74
61
  exp = subject.config.combinations
75
- assert_equal exp, subject.combinations
62
+ assert_that(subject.combinations).equals(exp)
76
63
  end
77
-
78
64
  end
79
-
80
65
  end
@@ -1,59 +1,23 @@
1
- require 'assert'
2
- require 'dassets/engine'
1
+ require "assert"
2
+ require "dassets/engine"
3
3
 
4
4
  class Dassets::Engine
5
-
6
5
  class UnitTests < Assert::Context
7
6
  desc "Dassets::Engine"
8
- setup do
9
- @engine = Dassets::Engine.new
10
- end
11
- subject{ @engine }
7
+ subject { Dassets::Engine.new }
12
8
 
13
9
  should have_reader :opts
14
10
  should have_imeths :ext, :compile
15
11
 
16
12
  should "default the opts if none given" do
17
13
  exp_opts = {}
18
- assert_equal exp_opts, subject.opts
14
+ assert_that(subject.opts).equals(exp_opts)
19
15
  end
20
16
 
21
17
  should "raise NotImplementedError on `ext` and `compile`" do
22
- assert_raises NotImplementedError do
23
- subject.ext('foo')
24
- end
25
-
26
- assert_raises NotImplementedError do
27
- subject.compile('some content')
28
- end
18
+ assert_that { subject.ext("foo") }.raises(NotImplementedError)
19
+ assert_that { subject.compile("some content") }
20
+ .raises(NotImplementedError)
29
21
  end
30
-
31
22
  end
32
-
33
- class NullEngineTests < Assert::Context
34
- desc "Dassets::NullEngine"
35
- setup do
36
- @engine = Dassets::NullEngine.new('some' => 'opts')
37
- end
38
- subject{ @engine }
39
-
40
- should "be a Engine" do
41
- assert_kind_of Dassets::Engine, subject
42
- end
43
-
44
- should "know its opts" do
45
- exp_opts = {'some' => 'opts'}
46
- assert_equal exp_opts, subject.opts
47
- end
48
-
49
- should "return the given extension on `ext`" do
50
- assert_equal 'foo', subject.ext('foo')
51
- end
52
-
53
- should "return the given input on `compile" do
54
- assert_equal 'some content', subject.compile('some content')
55
- end
56
-
57
- end
58
-
59
23
  end
@@ -1,65 +1,73 @@
1
- require 'assert'
2
- require 'dassets/file_store'
1
+ require "assert"
2
+ require "dassets/file_store"
3
3
 
4
4
  class Dassets::FileStore
5
-
6
5
  class UnitTests < Assert::Context
7
6
  desc "Dassets::FileStore"
7
+ subject { Dassets::FileStore.new(@root.to_s) }
8
+
8
9
  setup do
9
- @root = TEST_SUPPORT_PATH.join('public')
10
+ @root = TEST_SUPPORT_PATH.join("public")
10
11
  @url_path = Factory.url
11
12
  @root_path = File.join(@root, @url_path).to_s
12
13
  FileUtils.rm_f(@root_path)
13
-
14
- @store = Dassets::FileStore.new(@root.to_s)
15
14
  end
15
+
16
16
  teardown do
17
17
  FileUtils.rm_rf(@root.to_s)
18
18
  end
19
- subject{ @store }
20
19
 
21
20
  should have_readers :root
22
21
  should have_imeths :save, :store_path
23
22
 
24
23
  should "know its root" do
25
- assert_equal @root.to_s, subject.root
24
+ assert_that(subject.root).equals(@root.to_s)
26
25
  end
27
26
 
28
27
  should "build the store path based on a given url path" do
29
- assert_equal @root_path, subject.store_path(@url_path)
28
+ assert_that(subject.store_path(@url_path)).equals(@root_path)
30
29
  end
31
30
 
32
31
  should "write a file and return the store path on save" do
33
32
  content = Factory.text
34
- assert_not_file_exists @root_path
35
- path = subject.save(@url_path){ content }
33
+ assert_that(@root_path).is_not_a_file
36
34
 
37
- assert_equal @root_path, path
38
- assert_file_exists @root_path
39
- assert_equal content, File.read(@root_path)
40
- end
35
+ path = subject.save(@url_path) { content }
41
36
 
37
+ assert_that(path).equals(@root_path)
38
+ assert_that(@root_path).is_a_file
39
+ assert_that(File.read(@root_path)).equals(content)
40
+ end
42
41
  end
42
+ end
43
+
44
+ class Dassets::NullFileStore
45
+ class UnitTests < Assert::Context
46
+ desc "Dassets::NullFileStore"
47
+ subject { Dassets::NullFileStore.new }
43
48
 
44
- class NullStoreTests < UnitTests
45
- desc "NullStore"
46
49
  setup do
47
- @store = Dassets::FileStore::NullStore.new
50
+ @root = TEST_SUPPORT_PATH.join("public")
51
+ @url_path = Factory.url
52
+ @root_path = File.join(@root, @url_path).to_s
53
+ FileUtils.rm_f(@root_path)
48
54
  end
49
55
 
50
- should "be a kind of FileStore" do
51
- assert_kind_of Dassets::FileStore, subject
56
+ teardown do
57
+ FileUtils.rm_rf(@root.to_s)
58
+ end
59
+
60
+ should "be a kind of Dassets::FileStore" do
61
+ assert_that(subject).is_kind_of(Dassets::FileStore)
52
62
  end
53
63
 
54
64
  should "know its root" do
55
- assert_equal '', subject.root
65
+ assert_that(subject.root).equals("")
56
66
  end
57
67
 
58
68
  should "return the store path on save but not save a file" do
59
- assert_equal File.join('', @url_path), subject.save(@url_path)
60
- assert_not_file_exists @root_path
69
+ assert_that(subject.save(@url_path)).equals(File.join("", @url_path))
70
+ assert_that(@root_path).is_not_a_file
61
71
  end
62
-
63
72
  end
64
-
65
73
  end
@@ -1,106 +1,101 @@
1
- require 'assert'
2
- require 'dassets/server/request'
1
+ require "assert"
2
+ require "dassets/server/request"
3
3
 
4
- require 'dassets/asset_file'
4
+ require "dassets/asset_file"
5
5
 
6
6
  class Dassets::Server::Request
7
-
8
7
  class UnitTests < Assert::Context
9
8
  desc "Dassets::Server::Request"
9
+ subject { @req }
10
+
10
11
  setup do
11
- @path = '/file1-daa05c683a4913b268653f7a7e36a5b4.txt'
12
- @req = file_request('GET', @path)
12
+ @path = "/file1-daa05c683a4913b268653f7a7e36a5b4.txt"
13
+ @req = file_request("GET", @path)
13
14
  end
14
- subject{ @req }
15
15
 
16
16
  should have_imeths :dassets_base_url
17
17
  should have_imeths :for_asset_file?, :asset_path, :asset_file
18
18
 
19
- should "know its base url" do
20
- assert_equal Dassets.config.base_url.to_s, subject.dassets_base_url
21
- end
22
-
23
- should "know its path info" do
24
- assert_equal @path, subject.path_info
25
- end
26
-
27
- should "know its asset_path" do
28
- assert_equal 'file1.txt', subject.asset_path
29
- end
30
-
31
- should "know its asset_file" do
32
- assert_equal Dassets['file1.txt'], subject.asset_file
19
+ should "know its attributes" do
20
+ assert_that(subject.dassets_base_url).equals(Dassets.config.base_url.to_s)
21
+ assert_that(subject.path_info).equals(@path)
22
+ assert_that(subject.asset_path).equals("file1.txt")
23
+ assert_that(subject.asset_file).equals(Dassets["file1.txt"])
33
24
  end
34
25
 
35
26
  should "know if it is for an asset file" do
36
27
  # find nested path with matching fingerprint
37
- req = file_request('GET', '/nested/file3-d41d8cd98f00b204e9800998ecf8427e.txt')
38
- assert req.for_asset_file?
28
+ req =
29
+ file_request(
30
+ "GET",
31
+ "/nested/file3-d41d8cd98f00b204e9800998ecf8427e.txt"
32
+ )
33
+ assert_that(req.for_asset_file?).is_true
39
34
 
40
35
  # find not nested path with matching fingerprint
41
- req = file_request('HEAD', '/file1-daa05c683a4913b268653f7a7e36a5b4.txt')
42
- assert req.for_asset_file?
36
+ req = file_request("HEAD", "/file1-daa05c683a4913b268653f7a7e36a5b4.txt")
37
+ assert_that(req.for_asset_file?).is_true
43
38
 
44
39
  # find even if fingerprint is *not* matching - just need to have any fingerprint
45
- req = file_request('GET', '/file1-d41d8cd98f00b204e9800998ecf8427e.txt')
46
- assert req.for_asset_file?
40
+ req = file_request("GET", "/file1-d41d8cd98f00b204e9800998ecf8427e.txt")
41
+ assert_that(req.for_asset_file?).is_true
47
42
 
48
43
  # not find an invalid fingerprint
49
- req = file_request('GET', '/file1-abc123.txt')
50
- assert_not req.for_asset_file?
44
+ req = file_request("GET", "/file1-abc123.txt")
45
+ assert_that(req.for_asset_file?).is_false
51
46
 
52
47
  # not find a missing fingerprint
53
- req = file_request('HEAD', '/file1.txt')
54
- assert_not req.for_asset_file?
48
+ req = file_request("HEAD", "/file1.txt")
49
+ assert_that(req.for_asset_file?).is_false
55
50
 
56
51
  # not find an unknown file with a missing fingerprint
57
- req = file_request('GET', '/some-file.txt')
58
- assert_not req.for_asset_file?
52
+ req = file_request("GET", "/some-file.txt")
53
+ assert_that(req.for_asset_file?).is_false
59
54
 
60
55
  # not find an unknown file with a valid fingerprint
61
- req = file_request('GET', '/some-file-daa05c683a4913b268653f7a7e36a5b4.txt')
62
- assert_not req.for_asset_file?
56
+ req =
57
+ file_request("GET", "/some-file-daa05c683a4913b268653f7a7e36a5b4.txt")
58
+ assert_that(req.for_asset_file?).is_false
63
59
  end
64
60
 
65
61
  should "return an empty path and file if request not for an asset file" do
66
- req = file_request('GET', '/some-file.txt')
62
+ req = file_request("GET", "/some-file.txt")
67
63
 
68
- assert_equal '', req.asset_path
69
- assert_equal Dassets::AssetFile.new(''), req.asset_file
64
+ assert_that(req.asset_path).equals("")
65
+ assert_that(req.asset_file).equals(Dassets::AssetFile.new(""))
70
66
  end
71
67
 
72
- protected
68
+ private
73
69
 
74
70
  def file_request(method, path_info)
75
- require 'dassets/server/request'
76
71
  Dassets::Server::Request.new({
77
- 'REQUEST_METHOD' => method,
78
- 'PATH_INFO' => path_info
72
+ "REQUEST_METHOD" => method,
73
+ "PATH_INFO" => path_info
79
74
  })
80
75
  end
81
-
82
76
  end
83
77
 
84
78
  class BaseUrlTests < UnitTests
85
79
  desc "when a base url is configured"
80
+
86
81
  setup do
87
82
  @orig_base_url = Dassets.config.base_url
88
83
  @new_base_url = Factory.url
89
84
  Dassets.config.base_url(@new_base_url)
90
85
  end
86
+
91
87
  teardown do
92
88
  Dassets.config.set_base_url(@orig_base_url)
93
89
  end
94
90
 
95
91
  should "have the same base url as is configured" do
96
- assert_equal @new_base_url.to_s, subject.dassets_base_url
92
+ assert_that(subject.dassets_base_url).equals(@new_base_url.to_s)
97
93
  end
98
94
 
99
95
  should "remove the configured base url from the path info" do
100
- assert_equal @path, file_request('GET', @path).path_info
101
- assert_equal @path, file_request('GET', "#{@new_base_url}#{@path}").path_info
96
+ assert_that(file_request("GET", @path).path_info).equals(@path)
97
+ assert_that(file_request("GET", "#{@new_base_url}#{@path}").path_info)
98
+ .equals(@path)
102
99
  end
103
-
104
100
  end
105
-
106
101
  end
@@ -1,77 +1,78 @@
1
- require 'assert'
2
- require 'dassets/server/response'
1
+ require "assert"
2
+ require "dassets/server/response"
3
3
 
4
- require 'rack/utils'
5
- require 'dassets/asset_file'
4
+ require "rack/utils"
5
+ require "dassets/asset_file"
6
6
 
7
7
  class Dassets::Server::Response
8
-
9
8
  class UnitTests < Assert::Context
10
9
  desc "Dassets::Server::Response"
10
+ subject { @response }
11
+
11
12
  setup do
12
- @env = {}
13
- @asset_file = Dassets['file1.txt']
13
+ @env = {}
14
+ @asset_file = Dassets["file1.txt"]
14
15
 
15
16
  @response = Dassets::Server::Response.new(@env, @asset_file)
16
17
  end
17
- subject{ @response }
18
18
 
19
19
  should have_readers :asset_file, :status, :headers, :body
20
20
  should have_imeths :to_rack
21
21
 
22
22
  should "handle not modified files" do
23
- env = { 'HTTP_IF_MODIFIED_SINCE' => @asset_file.mtime }
23
+ env = { "HTTP_IF_MODIFIED_SINCE" => @asset_file.mtime }
24
24
  resp = Dassets::Server::Response.new(env, @asset_file)
25
25
 
26
- assert_equal 304, resp.status
27
- assert_equal [], resp.body
28
-
29
- exp_headers = Rack::Utils::HeaderHash.new('Last-Modified' => @asset_file.mtime.to_s)
30
- assert_equal exp_headers, resp.headers
26
+ assert_that(resp.status).equals(304)
27
+ assert_that(resp.body).equals([])
31
28
 
32
- assert_equal [304, exp_headers.to_hash, []], resp.to_rack
29
+ exp_headers =
30
+ Rack::Utils::HeaderHash.new("Last-Modified" => @asset_file.mtime.to_s)
31
+ assert_that(resp.headers).equals(exp_headers)
32
+ assert_that(resp.to_rack).equals([304, exp_headers.to_hash, []])
33
33
  end
34
34
 
35
35
  should "handle found files" do
36
36
  resp = Dassets::Server::Response.new(@env, @asset_file)
37
37
 
38
- assert_equal 200, resp.status
38
+ assert_that(resp.status).equals(200)
39
39
 
40
40
  exp_body = Body.new(@env, @asset_file)
41
- assert_equal exp_body, resp.body
41
+ assert_that(resp.body).equals(exp_body)
42
42
 
43
- exp_headers = @asset_file.response_headers.merge({
44
- 'Content-Type' => 'text/plain',
45
- 'Content-Length' => Rack::Utils.bytesize(@asset_file.content).to_s,
46
- 'Last-Modified' => @asset_file.mtime.to_s
47
- })
48
- assert_equal exp_headers, resp.headers
43
+ exp_headers =
44
+ @asset_file.response_headers.merge({
45
+ "Content-Type" => "text/plain",
46
+ "Content-Length" => @asset_file.size.to_s,
47
+ "Last-Modified" => @asset_file.mtime.to_s,
48
+ })
49
+ assert_that(resp.headers).equals(exp_headers)
49
50
 
50
- assert_equal [200, exp_headers, exp_body], resp.to_rack
51
+ assert_that(resp.to_rack).equals([200, exp_headers, exp_body])
51
52
  end
52
53
 
53
54
  should "have an empty body for found files with a HEAD request" do
54
- env = { 'REQUEST_METHOD' => 'HEAD' }
55
+ env = { "REQUEST_METHOD" => "HEAD" }
55
56
  resp = Dassets::Server::Response.new(env, @asset_file)
56
57
 
57
- assert_equal 200, resp.status
58
- assert_equal [], resp.body
58
+ assert_that(resp.status).equals(200)
59
+ assert_that(resp.body).equals([])
59
60
  end
60
61
 
61
62
  should "handle not found files" do
62
- af = Dassets.asset_file('not-found-file.txt')
63
+ af = Dassets.asset_file("not-found-file.txt")
63
64
  resp = Dassets::Server::Response.new(@env, af)
64
65
 
65
- assert_equal 404, resp.status
66
- assert_equal ['Not Found'], resp.body
67
- assert_equal Rack::Utils::HeaderHash.new, resp.headers
68
- assert_equal [404, {}, ['Not Found']], resp.to_rack
66
+ assert_that(resp.status).equals(404)
67
+ assert_that(resp.body).equals(["Not Found"])
68
+ assert_that(resp.headers).equals(Rack::Utils::HeaderHash.new)
69
+ assert_that(resp.to_rack).equals([404, {}, ["Not Found"]])
69
70
  end
70
-
71
71
  end
72
72
 
73
73
  class PartialContentTests < UnitTests
74
74
  desc "for a partial content request"
75
+
75
76
  setup do
76
77
  @body = Body.new(@env, @asset_file)
77
78
  Assert.stub(Body, :new).with(@env, @asset_file){ @body }
@@ -84,55 +85,54 @@ class Dassets::Server::Response
84
85
  end
85
86
 
86
87
  should "be a partial content response" do
87
- assert_equal 206, subject.status
88
+ assert_that(subject.status).equals(206)
88
89
 
89
- assert_includes 'Content-Range', subject.headers
90
- assert_equal @body.content_range, subject.headers['Content-Range']
90
+ assert_that(subject.headers).includes("Content-Range")
91
+ assert_that(subject.headers["Content-Range"]).equals(@body.content_range)
91
92
  end
92
-
93
93
  end
94
94
 
95
95
  class BodyTests < UnitTests
96
96
  desc "Body"
97
+ subject { @body }
98
+
97
99
  setup do
98
100
  @body = Body.new(@env, @asset_file)
99
101
  end
100
- subject{ @body }
101
102
 
102
103
  should have_readers :asset_file, :size, :content_range
103
104
  should have_imeths :partial?, :range_begin, :range_end
104
105
  should have_imeths :each
105
106
 
106
107
  should "know its chunk size" do
107
- assert_equal 8192, Body::CHUNK_SIZE
108
+ assert_that(Body::CHUNK_SIZE).equals(8192)
108
109
  end
109
110
 
110
111
  should "know its asset file" do
111
- assert_equal @asset_file, subject.asset_file
112
+ assert_that(subject.asset_file).equals(@asset_file)
112
113
  end
113
114
 
114
115
  should "know if it is equal to another body" do
115
116
  same_af_same_range = Body.new(@env, @asset_file)
116
117
  Assert.stub(same_af_same_range, :range_begin){ subject.range_begin }
117
118
  Assert.stub(same_af_same_range, :range_end){ subject.range_end }
118
- assert_equal same_af_same_range, subject
119
+ assert_that(subject).equals(same_af_same_range)
119
120
 
120
- other_af_same_range = Body.new(@env, Dassets['file2.txt'])
121
+ other_af_same_range = Body.new(@env, Dassets["file2.txt"])
121
122
  Assert.stub(other_af_same_range, :range_begin){ subject.range_begin }
122
123
  Assert.stub(other_af_same_range, :range_end){ subject.range_end }
123
- assert_not_equal other_af_same_range, subject
124
+ assert_that(subject).does_not_equal(other_af_same_range)
124
125
 
125
126
  same_af_other_range = Body.new(@env, @asset_file)
126
127
 
127
128
  Assert.stub(same_af_other_range, :range_begin){ Factory.integer }
128
129
  Assert.stub(same_af_other_range, :range_end){ subject.range_end }
129
- assert_not_equal same_af_other_range, subject
130
+ assert_that(subject).does_not_equal(same_af_other_range)
130
131
 
131
132
  Assert.stub(same_af_other_range, :range_begin){ subject.range_begin }
132
133
  Assert.stub(same_af_other_range, :range_end){ Factory.integer }
133
- assert_not_equal same_af_other_range, subject
134
+ assert_that(subject).does_not_equal(same_af_other_range)
134
135
  end
135
-
136
136
  end
137
137
 
138
138
  class BodyIOTests < BodyTests
@@ -140,50 +140,50 @@ class Dassets::Server::Response
140
140
  @min_num_chunks = 3
141
141
  @num_chunks = @min_num_chunks + Factory.integer(3)
142
142
 
143
- content = 'a' * (@num_chunks * Body::CHUNK_SIZE)
143
+ content = "a" * (@num_chunks * Body::CHUNK_SIZE)
144
144
  Assert.stub(@asset_file, :content){ content }
145
145
  end
146
-
147
146
  end
148
147
 
149
148
  class NonPartialBodyTests < BodyIOTests
150
149
  desc "for non/multi/invalid partial content requests"
150
+
151
151
  setup do
152
- range = [nil, 'bytes=', 'bytes=0-1,2-3', 'bytes=3-2', 'bytes=abc'].sample
153
- env = range.nil? ? {} : { 'HTTP_RANGE' => range }
152
+ range = [nil, "bytes=", "bytes=0-1,2-3", "bytes=3-2", "bytes=abc"].sample
153
+ env = range.nil? ? {} : { "HTTP_RANGE" => range }
154
154
  @body = Body.new(env, @asset_file)
155
155
  end
156
156
 
157
157
  should "not be partial" do
158
- assert_false subject.partial?
158
+ assert_that(subject.partial?).is_false
159
159
  end
160
160
 
161
161
  should "be the full content size" do
162
- assert_equal @asset_file.size, subject.size
162
+ assert_that(subject.size).equals(@asset_file.size)
163
163
  end
164
164
 
165
165
  should "have no content range" do
166
- assert_nil subject.content_range
166
+ assert_that(subject.content_range).is_nil
167
167
  end
168
168
 
169
169
  should "have the full content size as its range" do
170
- assert_equal 0, subject.range_begin
171
- assert_equal subject.size-1, subject.range_end
170
+ assert_that(subject.range_begin).equals(0)
171
+ assert_that(subject.range_end).equals(subject.size - 1)
172
172
  end
173
173
 
174
174
  should "chunk the full content when iterated" do
175
175
  chunks = []
176
176
  subject.each{ |chunk| chunks << chunk }
177
177
 
178
- assert_equal @num_chunks, chunks.size
179
- assert_equal subject.class::CHUNK_SIZE, chunks.first.size
180
- assert_equal @asset_file.content, chunks.join('')
178
+ assert_that(chunks.size).equals(@num_chunks)
179
+ assert_that(chunks.first.size).equals(subject.class::CHUNK_SIZE)
180
+ assert_that(chunks.join("")).equals(@asset_file.content)
181
181
  end
182
-
183
182
  end
184
183
 
185
184
  class PartialBodySetupTests < BodyIOTests
186
185
  desc "for a partial content request"
186
+
187
187
  setup do
188
188
  @start_chunk = Factory.boolean ? 0 : 1
189
189
  @partial_begin = @start_chunk * Body::CHUNK_SIZE
@@ -191,81 +191,79 @@ class Dassets::Server::Response
191
191
  @partial_size = @partial_chunks * Body::CHUNK_SIZE
192
192
  @partial_end = @partial_begin + (@partial_size-1)
193
193
 
194
- @env = { 'HTTP_RANGE' => "bytes=#{@partial_begin}-#{@partial_end}" }
194
+ @env = { "HTTP_RANGE" => "bytes=#{@partial_begin}-#{@partial_end}" }
195
195
  end
196
-
197
196
  end
198
197
 
199
198
  class PartialBodyTests < PartialBodySetupTests
199
+ subject { @body }
200
+
200
201
  setup do
201
202
  @body = Body.new(@env, @asset_file)
202
203
  end
203
- subject{ @body }
204
204
 
205
205
  should "be partial" do
206
- assert_true subject.partial?
206
+ assert_that(subject.partial?).is_true
207
207
  end
208
208
 
209
209
  should "be the specified partial size" do
210
- assert_equal @partial_size, subject.size
210
+ assert_that(subject.size).equals(@partial_size)
211
211
  end
212
212
 
213
213
  should "know its content range" do
214
214
  exp = "bytes #{@partial_begin}-#{@partial_end}/#{@asset_file.size}"
215
- assert_equal exp, subject.content_range
215
+ assert_that(subject.content_range).equals(exp)
216
216
  end
217
217
 
218
218
  should "have the know its range" do
219
- assert_equal @partial_begin, subject.range_begin
220
- assert_equal @partial_end, subject.range_end
219
+ assert_that(subject.range_begin).equals(@partial_begin)
220
+ assert_that(subject.range_end).equals(@partial_end)
221
221
  end
222
222
 
223
223
  should "chunk the range when iterated" do
224
224
  chunks = []
225
225
  subject.each{ |chunk| chunks << chunk }
226
226
 
227
- assert_equal @partial_chunks, chunks.size
228
- assert_equal subject.class::CHUNK_SIZE, chunks.first.size
227
+ assert_that(chunks.size).equals(@partial_chunks)
228
+ assert_that(chunks.first.size).equals(subject.class::CHUNK_SIZE)
229
229
 
230
230
  exp = @asset_file.content[@partial_begin..@partial_end]
231
- assert_equal exp, chunks.join('')
231
+ assert_that(chunks.join("")).equals(exp)
232
232
  end
233
-
234
233
  end
235
234
 
236
235
  class LegacyRackTests < PartialBodySetupTests
237
236
  desc "when using a legacy version of rack that can't interpret byte ranges"
237
+
238
238
  setup do
239
239
  Assert.stub(Rack::Utils, :respond_to?).with(:byte_ranges){ false }
240
240
  @body = Body.new(@env, @asset_file)
241
241
  end
242
242
 
243
243
  should "not be partial" do
244
- assert_false subject.partial?
244
+ assert_that(subject.partial?).is_false
245
245
  end
246
246
 
247
247
  should "be the full content size" do
248
- assert_equal @asset_file.size, subject.size
248
+ assert_that(subject.size).equals(@asset_file.size)
249
249
  end
250
250
 
251
251
  should "have no content range" do
252
- assert_nil subject.content_range
252
+ assert_that(subject.content_range).is_nil
253
253
  end
254
254
 
255
255
  should "have the full content size as its range" do
256
- assert_equal 0, subject.range_begin
257
- assert_equal subject.size-1, subject.range_end
256
+ assert_that(subject.range_begin).equals(0)
257
+ assert_that(subject.range_end).equals(subject.size - 1)
258
258
  end
259
259
 
260
260
  should "chunk the full content when iterated" do
261
261
  chunks = []
262
262
  subject.each{ |chunk| chunks << chunk }
263
263
 
264
- assert_equal @num_chunks, chunks.size
265
- assert_equal subject.class::CHUNK_SIZE, chunks.first.size
266
- assert_equal @asset_file.content, chunks.join('')
264
+ assert_that(chunks.size).equals(@num_chunks)
265
+ assert_that(chunks.first.size).equals(subject.class::CHUNK_SIZE)
266
+ assert_that(chunks.join("")).equals(@asset_file.content)
267
267
  end
268
-
269
268
  end
270
-
271
269
  end