cartage-rack 2.2 → 2.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,22 +1,22 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'minitest_config'
3
+ require "minitest_helper"
4
4
 
5
5
  describe Cartage::Rack do
6
6
  include Rack::Test::Methods
7
7
 
8
8
  let(:app) { Cartage::Rack(path) }
9
- let(:path) { 'test/hillvalley' }
9
+ let(:path) { "test/hillvalley" }
10
10
  let(:metadata) {
11
11
  {
12
- 'package' => {
13
- 'name' => 'hillvalley',
14
- 'repo' => {
15
- 'type' => 'git',
16
- 'url' => 'git:doc@hillvalley.com/delorean.git'
12
+ "package" => {
13
+ "name" => "hillvalley",
14
+ "repo" => {
15
+ "type" => "git",
16
+ "url" => "git:doc@hillvalley.com/delorean.git"
17
17
  },
18
- 'hashref' => 'd0cb1ff',
19
- 'timestamp' => '19851027104200'
18
+ "hashref" => "d0cb1ff",
19
+ "timestamp" => "19851027104200"
20
20
  }
21
21
  }
22
22
  }
@@ -31,160 +31,160 @@ describe Cartage::Rack do
31
31
  end
32
32
  end
33
33
 
34
- it 'inspects nicely for `rake routes` in Rails' do
35
- assert_equal 'Cartage::Rack for hillvalley (release_metadata_json)',
34
+ it "inspects nicely for `rake routes` in Rails" do
35
+ assert_equal "Cartage::Rack for hillvalley (release_metadata_json)",
36
36
  Cartage::Rack().inspect
37
37
  end
38
38
 
39
- it 'returns application/json content by default' do
40
- get '/'
41
- assert_equal 'application/json', last_response.header['Content-Type']
39
+ it "returns application/json content by default" do
40
+ get "/"
41
+ assert_equal "application/json", last_response.headers["Content-Type"]
42
42
  end
43
43
 
44
- it 'returns text/plain content when requested' do
45
- get '/.txt'
46
- assert_equal 'text/plain', last_response.header['Content-Type']
44
+ it "returns text/plain content when requested" do
45
+ get "/.txt"
46
+ assert_equal "text/plain", last_response.headers["Content-Type"]
47
47
  end
48
48
 
49
- context 'application environment' do
50
- it 'uses $RAILS_ENV first' do
51
- stub_env 'RAILS_ENV' => 'vne_sliar',
52
- 'APP_ENV' => 'vne_ppa',
53
- 'RACK_ENV' => 'vne_kcar' do
54
- get '/'
49
+ describe "application environment" do
50
+ it "uses $RAILS_ENV first" do
51
+ stub_env "RAILS_ENV" => "vne_sliar",
52
+ "APP_ENV" => "vne_ppa",
53
+ "RACK_ENV" => "vne_kcar" do
54
+ get "/"
55
55
 
56
- metadata['env'] = { 'name' => 'vne_sliar' }
56
+ metadata["env"] = {"name" => "vne_sliar"}
57
57
 
58
58
  assert last_response.ok?
59
59
  assert_equal metadata.to_json, last_response.body
60
- assert_equal 'application/json', last_response.header['Content-Type']
60
+ assert_equal "application/json", last_response.headers["Content-Type"]
61
61
  end
62
62
  end
63
63
 
64
- it 'uses $APP_ENV second' do
65
- stub_env 'RAILS_ENV' => nil, 'APP_ENV' => 'vne_ppa', 'RACK_ENV' => 'vne_kcar' do
66
- get '/'
64
+ it "uses $APP_ENV second" do
65
+ stub_env "RAILS_ENV" => nil, "APP_ENV" => "vne_ppa", "RACK_ENV" => "vne_kcar" do
66
+ get "/"
67
67
 
68
- metadata['env'] = { 'name' => 'vne_ppa' }
68
+ metadata["env"] = {"name" => "vne_ppa"}
69
69
 
70
70
  assert last_response.ok?
71
71
  assert_equal metadata.to_json, last_response.body
72
- assert_equal 'application/json', last_response.header['Content-Type']
72
+ assert_equal "application/json", last_response.headers["Content-Type"]
73
73
  end
74
74
  end
75
75
 
76
- it 'uses $RACK_ENV third' do
77
- stub_env 'RAILS_ENV' => nil, 'APP_ENV' => nil, 'RACK_ENV' => 'vne_kcar' do
78
- get '/'
76
+ it "uses $RACK_ENV third" do
77
+ stub_env "RAILS_ENV" => nil, "APP_ENV" => nil, "RACK_ENV" => "vne_kcar" do
78
+ get "/"
79
79
 
80
- metadata['env'] = { 'name' => 'vne_kcar' }
80
+ metadata["env"] = {"name" => "vne_kcar"}
81
81
 
82
82
  assert last_response.ok?
83
83
  assert_equal metadata.to_json, last_response.body
84
- assert_equal 'application/json', last_response.header['Content-Type']
84
+ assert_equal "application/json", last_response.headers["Content-Type"]
85
85
  end
86
86
  end
87
87
 
88
- it 'falls through to UNKNOWN without either $RAILS_ENV, $APP_ENV or $RACK_ENV' do
89
- stub_env 'RAILS_ENV' => nil, 'APP_ENV' => nil, 'RACK_ENV' => nil do
90
- get '/'
88
+ it "falls through to UNKNOWN without either $RAILS_ENV, $APP_ENV or $RACK_ENV" do
89
+ stub_env "RAILS_ENV" => nil, "APP_ENV" => nil, "RACK_ENV" => nil do
90
+ get "/"
91
91
 
92
- metadata['env'] = { 'name' => 'UNKNOWN' }
92
+ metadata["env"] = {"name" => "UNKNOWN"}
93
93
 
94
94
  assert last_response.ok?
95
95
  assert_equal metadata.to_json, last_response.body
96
- assert_equal 'application/json', last_response.header['Content-Type']
96
+ assert_equal "application/json", last_response.headers["Content-Type"]
97
97
  end
98
98
  end
99
99
  end
100
100
 
101
- context 'timestamp' do
101
+ describe "timestamp" do
102
102
  around do |&block|
103
- metadata['package'].delete('timestamp')
103
+ metadata["package"].delete("timestamp")
104
104
  super(&block)
105
105
  end
106
106
 
107
- it 'is omitted if not present in the metadata' do
108
- stub_env 'RAILS_ENV' => nil, 'RACK_ENV' => nil do
109
- get '/'
107
+ it "is omitted if not present in the metadata" do
108
+ stub_env "RAILS_ENV" => nil, "RACK_ENV" => nil do
109
+ get "/"
110
110
 
111
- metadata['env'] = { 'name' => 'UNKNOWN' }
111
+ metadata["env"] = {"name" => "UNKNOWN"}
112
112
 
113
113
  assert last_response.ok?
114
114
  assert_equal metadata.to_json, last_response.body
115
- assert_equal 'application/json', last_response.header['Content-Type']
115
+ assert_equal "application/json", last_response.headers["Content-Type"]
116
116
  end
117
117
  end
118
118
  end
119
119
 
120
- context 'text/plain' do
121
- it 'returns a useful plaintext format' do
122
- stub_env 'RAILS_ENV' => 'production' do
123
- get '/.text'
120
+ describe "text/plain" do
121
+ it "returns a useful plaintext format" do
122
+ stub_env "RAILS_ENV" => "production" do
123
+ get "/.text"
124
124
 
125
125
  assert last_response.ok?
126
- assert_equal <<-text.chomp, last_response.body
127
- name: hillvalley
128
- environment: production
129
- hashref: d0cb1ff
130
- timestamp: 19851027104200
131
- git: git:doc@hillvalley.com/delorean.git
132
- text
133
- assert_equal 'text/plain', last_response.header['Content-Type']
126
+ assert_equal <<~TEXT.chomp, last_response.body
127
+ name: hillvalley
128
+ environment: production
129
+ hashref: d0cb1ff
130
+ timestamp: 19851027104200
131
+ git: git:doc@hillvalley.com/delorean.git
132
+ TEXT
133
+ assert_equal "text/plain", last_response.headers["Content-Type"]
134
134
  end
135
135
  end
136
136
 
137
- it 'skips the repo if package.repo is missing' do
138
- stub_env 'RAILS_ENV' => 'production' do
139
- metadata['package'].delete('repo')
137
+ it "skips the repo if package.repo is missing" do
138
+ stub_env "RAILS_ENV" => "production" do
139
+ metadata["package"].delete("repo")
140
140
 
141
- get '/.text'
141
+ get "/.text"
142
142
 
143
143
  assert last_response.ok?
144
- assert_equal <<-text.chomp, last_response.body
145
- name: hillvalley
146
- environment: production
147
- hashref: d0cb1ff
148
- timestamp: 19851027104200
149
- text
150
- assert_equal 'text/plain', last_response.header['Content-Type']
144
+ assert_equal <<~TEXT.chomp, last_response.body
145
+ name: hillvalley
146
+ environment: production
147
+ hashref: d0cb1ff
148
+ timestamp: 19851027104200
149
+ TEXT
150
+ assert_equal "text/plain", last_response.headers["Content-Type"]
151
151
  end
152
152
  end
153
153
 
154
- it 'skips the timestamp if package.timestamp is missing' do
155
- stub_env 'RAILS_ENV' => 'production' do
156
- metadata['package'].delete('timestamp')
154
+ it "skips the timestamp if package.timestamp is missing" do
155
+ stub_env "RAILS_ENV" => "production" do
156
+ metadata["package"].delete("timestamp")
157
157
 
158
- get '/.text'
158
+ get "/.text"
159
159
 
160
160
  assert last_response.ok?
161
- assert_equal <<-text.chomp, last_response.body
162
- name: hillvalley
163
- environment: production
164
- hashref: d0cb1ff
165
- git: git:doc@hillvalley.com/delorean.git
166
- text
167
- assert_equal 'text/plain', last_response.header['Content-Type']
161
+ assert_equal <<~TEXT.chomp, last_response.body
162
+ name: hillvalley
163
+ environment: production
164
+ hashref: d0cb1ff
165
+ git: git:doc@hillvalley.com/delorean.git
166
+ TEXT
167
+ assert_equal "text/plain", last_response.headers["Content-Type"]
168
168
  end
169
169
  end
170
170
  end
171
171
 
172
- context 'filter' do
172
+ describe "filter" do
173
173
  let(:app) {
174
174
  Cartage::Rack(path) { |content|
175
- content['env']['name'] = content['env']['name'].reverse
175
+ content["env"]["name"] = content["env"]["name"].reverse
176
176
  }
177
177
  }
178
178
 
179
- it 'applies the filter before returning' do
180
- stub_env 'RAILS_ENV' => 'vne_sliar' do
181
- get '/'
179
+ it "applies the filter before returning" do
180
+ stub_env "RAILS_ENV" => "vne_sliar" do
181
+ get "/"
182
182
 
183
- metadata['env'] = { 'name' => 'rails_env' }
183
+ metadata["env"] = {"name" => "rails_env"}
184
184
 
185
185
  assert last_response.ok?
186
186
  assert_equal metadata.to_json, last_response.body
187
- assert_equal 'application/json', last_response.header['Content-Type']
187
+ assert_equal "application/json", last_response.headers["Content-Type"]
188
188
  end
189
189
  end
190
190
  end
@@ -1,31 +1,31 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'minitest_config'
3
+ require "minitest_helper"
4
4
 
5
5
  describe Cartage::Rack::Metadata do
6
6
  let(:described_class) { Cartage::Rack::Metadata }
7
- let(:path) { 'test/hillvalley' }
8
- let(:env) { { 'RAILS_ENV' => 'production' } }
7
+ let(:path) { "test/hillvalley" }
8
+ let(:env) { {"RAILS_ENV" => "production"} }
9
9
 
10
- context 'with release-metadata.json' do
10
+ describe "with release-metadata.json" do
11
11
  let(:expected) {
12
12
  {
13
- 'env' => { 'name' => 'production' },
14
- 'package' => {
15
- 'name' => 'hillvalley',
16
- 'repo' => {
17
- 'type' => 'git',
18
- 'url' => 'git:doc@hillvalley.com/delorean.git'
13
+ "env" => {"name" => "production"},
14
+ "package" => {
15
+ "name" => "hillvalley",
16
+ "repo" => {
17
+ "type" => "git",
18
+ "url" => "git:doc@hillvalley.com/delorean.git"
19
19
  },
20
- 'hashref' => 'd0cb1ff',
21
- 'timestamp' => '19851027104200'
20
+ "hashref" => "d0cb1ff",
21
+ "timestamp" => "19851027104200"
22
22
  }
23
23
  }
24
24
  }
25
25
 
26
- it '#inspect uses the source (release_metadata_json) for inspection' do
27
- stub_pathname_exist? ->(v) { v.basename.to_s == 'release-metadata.json' } do
28
- instance_stub Pathname, :read, '{}' do
26
+ it "#inspect uses the source (release_metadata_json) for inspection" do
27
+ stub_pathname_exist? ->(v) { v.basename.to_s == "release-metadata.json" } do
28
+ instance_stub Pathname, :read, "{}" do
29
29
  assert_match(
30
30
  /\Ahillvalley \(release_metadata_json\)\z/,
31
31
  described_class.new(path, required: false).inspect
@@ -34,9 +34,9 @@ describe Cartage::Rack::Metadata do
34
34
  end
35
35
  end
36
36
 
37
- it '#resolve returns the content as provided' do
37
+ it "#resolve returns the content as provided" do
38
38
  stub_env(env) do
39
- stub_pathname_exist? ->(v) { v.basename.to_s == 'release-metadata.json' } do
39
+ stub_pathname_exist? ->(v) { v.basename.to_s == "release-metadata.json" } do
40
40
  instance_stub Pathname, :read, expected.to_json do
41
41
  assert_equal expected, described_class.new(path).resolve
42
42
  end
@@ -44,25 +44,25 @@ describe Cartage::Rack::Metadata do
44
44
  end
45
45
  end
46
46
 
47
- it '#resolve returns filtered content' do
47
+ it "#resolve returns filtered content" do
48
48
  filter = ->(content) {
49
- content['env']['capacitor'] = 'flux'
49
+ content["env"]["capacitor"] = "flux"
50
50
  }
51
51
 
52
52
  stub_env(env) do
53
- stub_pathname_exist? ->(v) { v.basename.to_s == 'release-metadata.json' } do
53
+ stub_pathname_exist? ->(v) { v.basename.to_s == "release-metadata.json" } do
54
54
  instance_stub Pathname, :read, expected.to_json do
55
- expected['env']['capacitor'] = 'flux'
55
+ expected["env"]["capacitor"] = "flux"
56
56
  assert_equal expected, described_class.new(path, filter: filter).resolve
57
57
  end
58
58
  end
59
59
  end
60
60
  end
61
61
 
62
- it '.new throws an exception with a non-JSON file' do
62
+ it ".new throws an exception with a non-JSON file" do
63
63
  stub_env(env) do
64
- stub_pathname_exist? ->(v) { v.basename.to_s == 'release-metadata.json' } do
65
- instance_stub Pathname, :read, 'supercalafragalisticexpealadocious' do
64
+ stub_pathname_exist? ->(v) { v.basename.to_s == "release-metadata.json" } do
65
+ instance_stub Pathname, :read, "supercalafragalisticexpealadocious" do
66
66
  ex = assert_raises(JSON::ParserError) do
67
67
  described_class.new(path)
68
68
  end
@@ -74,31 +74,31 @@ describe Cartage::Rack::Metadata do
74
74
  end
75
75
  end
76
76
 
77
- context 'with release_hashref' do
78
- let(:one_line) { 'd0cb1ff' }
77
+ describe "with release_hashref" do
78
+ let(:one_line) { "d0cb1ff" }
79
79
  let(:two_line) { "d0cb1ff\n19851027104200\n" }
80
80
  let(:two_line_empty) { "d0cb1ff\n\n" }
81
81
  let(:three_line) { "d0cb1ff\n19851027104200\nsomethingelse\n" }
82
82
  let(:expected_notimestamp) {
83
83
  {
84
- 'env' => {
85
- 'name' => 'production'
84
+ "env" => {
85
+ "name" => "production"
86
86
  },
87
- 'package' => {
88
- 'name' => 'hillvalley',
89
- 'hashref' => 'd0cb1ff'
87
+ "package" => {
88
+ "name" => "hillvalley",
89
+ "hashref" => "d0cb1ff"
90
90
  }
91
91
  }
92
92
  }
93
93
  let(:expected_timestamp) {
94
94
  expected_notimestamp.dup.tap do |en|
95
- en['package'] = en['package'].merge('timestamp' => '19851027104200')
95
+ en["package"] = en["package"].merge("timestamp" => "19851027104200")
96
96
  end
97
97
  }
98
98
 
99
- it 'uses the source (release_hashref) for inspection' do
100
- stub_pathname_exist? ->(v) { v.basename.to_s == 'release_hashref' } do
101
- instance_stub Pathname, :read, '' do
99
+ it "uses the source (release_hashref) for inspection" do
100
+ stub_pathname_exist? ->(v) { v.basename.to_s == "release_hashref" } do
101
+ instance_stub Pathname, :read, "" do
102
102
  assert_match(
103
103
  /\Ahillvalley \(release_hashref\)\z/,
104
104
  described_class.new(path, required: false).inspect
@@ -107,10 +107,10 @@ describe Cartage::Rack::Metadata do
107
107
  end
108
108
  end
109
109
 
110
- context '#resolve' do
111
- it 'returns the hashref from a one line release_hashref' do
110
+ describe "#resolve" do
111
+ it "returns the hashref from a one line release_hashref" do
112
112
  stub_env(env) do
113
- stub_pathname_exist? ->(v) { v.basename.to_s == 'release_hashref' } do
113
+ stub_pathname_exist? ->(v) { v.basename.to_s == "release_hashref" } do
114
114
  instance_stub Pathname, :read, one_line do
115
115
  assert_equal expected_notimestamp, described_class.new(path).resolve
116
116
  end
@@ -118,9 +118,9 @@ describe Cartage::Rack::Metadata do
118
118
  end
119
119
  end
120
120
 
121
- it 'returns hashref and timestamp from a two line release_hashref' do
121
+ it "returns hashref and timestamp from a two line release_hashref" do
122
122
  stub_env(env) do
123
- stub_pathname_exist? ->(v) { v.basename.to_s == 'release_hashref' } do
123
+ stub_pathname_exist? ->(v) { v.basename.to_s == "release_hashref" } do
124
124
  instance_stub Pathname, :read, two_line do
125
125
  assert_equal expected_timestamp, described_class.new(path).resolve
126
126
  end
@@ -128,9 +128,9 @@ describe Cartage::Rack::Metadata do
128
128
  end
129
129
  end
130
130
 
131
- it 'returns hashref from a two line release_hashref (with empty timestamp line)' do
131
+ it "returns hashref from a two line release_hashref (with empty timestamp line)" do
132
132
  stub_env(env) do
133
- stub_pathname_exist? ->(v) { v.basename.to_s == 'release_hashref' } do
133
+ stub_pathname_exist? ->(v) { v.basename.to_s == "release_hashref" } do
134
134
  instance_stub Pathname, :read, two_line_empty do
135
135
  assert_equal expected_notimestamp, described_class.new(path).resolve
136
136
  end
@@ -138,9 +138,9 @@ describe Cartage::Rack::Metadata do
138
138
  end
139
139
  end
140
140
 
141
- it 'ignores anything larger than two lines in release_hashref' do
141
+ it "ignores anything larger than two lines in release_hashref" do
142
142
  stub_env(env) do
143
- stub_pathname_exist? ->(v) { v.basename.to_s == 'release_hashref' } do
143
+ stub_pathname_exist? ->(v) { v.basename.to_s == "release_hashref" } do
144
144
  instance_stub Pathname, :read, three_line do
145
145
  assert_equal expected_timestamp, described_class.new(path).resolve
146
146
  end
@@ -150,8 +150,8 @@ describe Cartage::Rack::Metadata do
150
150
  end
151
151
  end
152
152
 
153
- context 'with live data' do
154
- it 'uses the source (live) for inspection' do
153
+ describe "with live data" do
154
+ it "uses the source (live) for inspection" do
155
155
  instance_stub Pathname, :exist?, false do
156
156
  assert_match(
157
157
  /\(live\)\z/,
@@ -162,44 +162,44 @@ describe Cartage::Rack::Metadata do
162
162
 
163
163
  let(:expected_nogit) {
164
164
  {
165
- 'env' => {
166
- 'name' => 'production'
165
+ "env" => {
166
+ "name" => "production"
167
167
  },
168
- 'package' => {
169
- 'name' => 'hillvalley',
170
- 'hashref' => 'UNKNOWN - no .git directory',
171
- 'timestamp' => '19851027104200'
168
+ "package" => {
169
+ "name" => "hillvalley",
170
+ "hashref" => "UNKNOWN - no .git directory",
171
+ "timestamp" => "19851027104200"
172
172
  }
173
173
  }
174
174
  }
175
175
  let(:expected_git) {
176
176
  expected_nogit.dup.tap { |en|
177
- en['package'] = en['package'].merge(
178
- 'repo' => {
179
- 'type' => 'git',
180
- 'url' => 'git:doc@hillvalley.com/delorean.git'
177
+ en["package"] = en["package"].merge(
178
+ "repo" => {
179
+ "type" => "git",
180
+ "url" => "git:doc@hillvalley.com/delorean.git"
181
181
  },
182
- 'hashref' => '(git) verne'
182
+ "hashref" => "(git) verne"
183
183
  )
184
184
  }
185
185
  }
186
186
 
187
- it 'fails if required is true' do
187
+ it "fails if required is true" do
188
188
  ex = assert_raises(RuntimeError) do
189
189
  described_class.new(path, required: true)
190
190
  end
191
191
 
192
- assert_equal 'Cannot find release-metadata.json or release_hashref', ex.message
192
+ assert_equal "Cannot find release-metadata.json or release_hashref", ex.message
193
193
  end
194
194
 
195
- context '#resolve' do
195
+ describe "#resolve" do
196
196
  around do |&block|
197
- Timecop.freeze(Time.new(1985, 10, 27, 2, 42, 0, '-08:00')) do
197
+ Timecop.freeze(Time.new(1985, 10, 27, 2, 42, 0, "-08:00")) do
198
198
  super(&block)
199
199
  end
200
200
  end
201
201
 
202
- it 'excludes package.repo when no .git directory' do
202
+ it "excludes package.repo when no .git directory" do
203
203
  stub_env(env) do
204
204
  instance_stub Pathname, :exist?, false do
205
205
  instance_stub Pathname, :directory?, false do
@@ -210,13 +210,13 @@ describe Cartage::Rack::Metadata do
210
210
  end
211
211
  end
212
212
 
213
- it 'includes package.repo when a .git directory exists' do
213
+ it "includes package.repo when a .git directory exists" do
214
214
  backticks = ->(v) {
215
215
  case v
216
216
  when /remote show/
217
217
  "\n Fetch URL: git:doc@hillvalley.com/delorean.git"
218
218
  when /rev-parse/
219
- 'verne'
219
+ "verne"
220
220
  else
221
221
  __stub_backticks__(v)
222
222
  end