license-acceptance 1.0.13 → 1.0.18

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fef5c00ef5400506f147e81de6189cac6b2b62a3072c3b5ce947e1ea1cf45d9b
4
- data.tar.gz: 05a004b7385c49d4b32b45df716e720ca406b011e15a8f270e9f27e79f13a740
3
+ metadata.gz: 857078f9f2d4c9d74fcb5a08876039fa5930c3f7286b1a7d03e2a84bda4d229b
4
+ data.tar.gz: c7c4d34ac946733f0f980f33d1b5fd0dd518e1c8fc1927a9a406580f3ac491c0
5
5
  SHA512:
6
- metadata.gz: 3133cff2199bf4131a40065512443e648dec1f406c0198f094cfcebcd0876ef1c86801d5b103caf55d6036cc2a8e7acdac089999c81aedfc9e758e7a2db449ce
7
- data.tar.gz: 8e27b606ef2f4a55b3b67e474cf14f247ec186520e372657982488eadd8e868a45c9c2800c790052b8343fec90a6a44b9edba62a70e88ad79d0b6009ab150d01
6
+ metadata.gz: c813cf96544c839b605631e587cad4ee3e798d6950022f454e417ac5f83234e969418f0d500f69ee730a102a046e5f20bf97782582fde203d58815d9dae30c9a
7
+ data.tar.gz: 6b497916918c9537c1cc234e6abace8ed448713640ac937b34593a8ac69b93bec72cfe4cca184514b4fe667203c5ec9af1546b1dcaf696a23d3318a47c37b4dd
@@ -1,3 +1,3 @@
1
1
  module LicenseAcceptance
2
- VERSION = "1.0.13"
2
+ VERSION = "1.0.18"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: license-acceptance
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.13
4
+ version: 1.0.18
5
5
  platform: ruby
6
6
  authors:
7
7
  - tyler-ball
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-06-12 00:00:00.000000000 Z
11
+ date: 2020-03-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pastel
@@ -72,14 +72,14 @@ dependencies:
72
72
  requirements:
73
73
  - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: '10.0'
75
+ version: '13.0'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: '10.0'
82
+ version: '13.0'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: rspec
85
85
  requirement: !ruby/object:Gem::Requirement
@@ -154,16 +154,22 @@ dependencies:
154
154
  name: thor
155
155
  requirement: !ruby/object:Gem::Requirement
156
156
  requirements:
157
- - - "~>"
157
+ - - ">="
158
158
  - !ruby/object:Gem::Version
159
159
  version: '0.20'
160
+ - - "<"
161
+ - !ruby/object:Gem::Version
162
+ version: '2.0'
160
163
  type: :development
161
164
  prerelease: false
162
165
  version_requirements: !ruby/object:Gem::Requirement
163
166
  requirements:
164
- - - "~>"
167
+ - - ">="
165
168
  - !ruby/object:Gem::Version
166
169
  version: '0.20'
170
+ - - "<"
171
+ - !ruby/object:Gem::Version
172
+ version: '2.0'
167
173
  - !ruby/object:Gem::Dependency
168
174
  name: climate_control
169
175
  requirement: !ruby/object:Gem::Requirement
@@ -186,9 +192,7 @@ extensions: []
186
192
  extra_rdoc_files: []
187
193
  files:
188
194
  - Gemfile
189
- - Gemfile.lock
190
195
  - LICENSE
191
- - Rakefile
192
196
  - config/product_info.toml
193
197
  - lib/license_acceptance/acceptor.rb
194
198
  - lib/license_acceptance/cli_flags/mixlib_cli.rb
@@ -205,18 +209,6 @@ files:
205
209
  - lib/license_acceptance/strategy/prompt.rb
206
210
  - lib/license_acceptance/strategy/provided_value.rb
207
211
  - lib/license_acceptance/version.rb
208
- - spec/license_acceptance/acceptor_spec.rb
209
- - spec/license_acceptance/cli_flags/mixlib_cli_spec.rb
210
- - spec/license_acceptance/cli_flags/thor_spec.rb
211
- - spec/license_acceptance/config_spec.rb
212
- - spec/license_acceptance/product_reader_spec.rb
213
- - spec/license_acceptance/product_spec.rb
214
- - spec/license_acceptance/strategy/argument_spec.rb
215
- - spec/license_acceptance/strategy/environment_spec.rb
216
- - spec/license_acceptance/strategy/file_spec.rb
217
- - spec/license_acceptance/strategy/prompt_spec.rb
218
- - spec/license_acceptance/strategy/provided_value_spec.rb
219
- - spec/spec_helper.rb
220
212
  homepage: https://github.com/chef/license-acceptance/
221
213
  licenses:
222
214
  - Apache-2.0
@@ -1,91 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- license-acceptance (1.0.13)
5
- pastel (~> 0.7)
6
- tomlrb (~> 1.2)
7
- tty-box (~> 0.3)
8
- tty-prompt (~> 0.18)
9
-
10
- GEM
11
- remote: https://rubygems.org/
12
- specs:
13
- binding_of_caller (0.8.0)
14
- debug_inspector (>= 0.0.1)
15
- byebug (11.0.1)
16
- climate_control (0.2.0)
17
- coderay (1.1.2)
18
- debug_inspector (0.0.3)
19
- diff-lcs (1.3)
20
- equatable (0.5.0)
21
- method_source (0.9.2)
22
- mixlib-cli (1.7.0)
23
- necromancer (0.5.0)
24
- pastel (0.7.2)
25
- equatable (~> 0.5.0)
26
- tty-color (~> 0.4.0)
27
- pry (0.12.2)
28
- coderay (~> 1.1.0)
29
- method_source (~> 0.9.0)
30
- pry-byebug (3.7.0)
31
- byebug (~> 11.0)
32
- pry (~> 0.10)
33
- pry-stack_explorer (0.4.9.3)
34
- binding_of_caller (>= 0.7)
35
- pry (>= 0.9.11)
36
- rake (10.5.0)
37
- rspec (3.8.0)
38
- rspec-core (~> 3.8.0)
39
- rspec-expectations (~> 3.8.0)
40
- rspec-mocks (~> 3.8.0)
41
- rspec-core (3.8.0)
42
- rspec-support (~> 3.8.0)
43
- rspec-expectations (3.8.4)
44
- diff-lcs (>= 1.2.0, < 2.0)
45
- rspec-support (~> 3.8.0)
46
- rspec-mocks (3.8.0)
47
- diff-lcs (>= 1.2.0, < 2.0)
48
- rspec-support (~> 3.8.0)
49
- rspec-support (3.8.2)
50
- strings (0.1.5)
51
- strings-ansi (~> 0.1)
52
- unicode-display_width (~> 1.5)
53
- unicode_utils (~> 1.4)
54
- strings-ansi (0.1.0)
55
- thor (0.20.3)
56
- tomlrb (1.2.8)
57
- tty-box (0.4.0)
58
- pastel (~> 0.7.2)
59
- strings (~> 0.1.5)
60
- tty-cursor (~> 0.7)
61
- tty-color (0.4.3)
62
- tty-cursor (0.7.0)
63
- tty-prompt (0.19.0)
64
- necromancer (~> 0.5.0)
65
- pastel (~> 0.7.0)
66
- tty-reader (~> 0.6.0)
67
- tty-reader (0.6.0)
68
- tty-cursor (~> 0.7)
69
- tty-screen (~> 0.7)
70
- wisper (~> 2.0.0)
71
- tty-screen (0.7.0)
72
- unicode-display_width (1.6.0)
73
- unicode_utils (1.4.0)
74
- wisper (2.0.0)
75
-
76
- PLATFORMS
77
- ruby
78
-
79
- DEPENDENCIES
80
- climate_control (~> 0.2)
81
- license-acceptance!
82
- mixlib-cli (~> 1.7)
83
- pry (~> 0.12)
84
- pry-byebug (~> 3.6)
85
- pry-stack_explorer (~> 0.4)
86
- rake (~> 10.0)
87
- rspec (~> 3.0)
88
- thor (~> 0.20)
89
-
90
- BUNDLED WITH
91
- 1.17.3
data/Rakefile DELETED
@@ -1,6 +0,0 @@
1
- require "bundler/gem_tasks"
2
- require "rspec/core/rake_task"
3
-
4
- RSpec::Core::RakeTask.new(:spec)
5
-
6
- task :default => :spec
@@ -1,302 +0,0 @@
1
- require "spec_helper"
2
- require "license_acceptance/acceptor"
3
-
4
- RSpec.describe LicenseAcceptance::Acceptor do
5
- it "has a version number" do
6
- expect(LicenseAcceptance::VERSION).not_to be nil
7
- end
8
-
9
- let(:output) do
10
- d = StringIO.new
11
- allow(d).to receive(:isatty).and_return(true)
12
- d
13
- end
14
- let(:opts) { { output: output } }
15
- let(:reader) { instance_double(LicenseAcceptance::ProductReader) }
16
- let(:acc) { LicenseAcceptance::Acceptor.new(opts) }
17
- let(:product) { instance_double(LicenseAcceptance::Product, id: "foo", pretty_name: "Foo") }
18
- let(:version) { "version" }
19
- let(:relationship) { instance_double(LicenseAcceptance::ProductRelationship, parent: product) }
20
- let(:missing) { [product] }
21
-
22
- describe "#check_and_persist!" do
23
- before do
24
- expect(LicenseAcceptance::ProductReader).to receive(:new).and_return(reader)
25
- expect(reader).to receive(:read)
26
- end
27
-
28
- let(:err) { LicenseAcceptance::LicenseNotAcceptedError.new(product, [product]) }
29
- it "outputs an error message to stdout and exits when license acceptance is declined" do
30
- expect(acc).to receive(:check_and_persist).and_raise(err)
31
- expect { acc.check_and_persist!(product.id, version) }.to raise_error(SystemExit)
32
- expect(output.string).to match(/#{product.pretty_name}/)
33
- end
34
- end
35
-
36
- describe "#check_and_persist" do
37
- let(:file_acc) { instance_double(LicenseAcceptance::Strategy::File) }
38
- let(:arg_acc) { instance_double(LicenseAcceptance::Strategy::Argument) }
39
- let(:prompt_acc) { instance_double(LicenseAcceptance::Strategy::Prompt) }
40
- let(:env_acc) { instance_double(LicenseAcceptance::Strategy::Environment) }
41
- let(:provided_acc) { instance_double(LicenseAcceptance::Strategy::ProvidedValue) }
42
-
43
- before do
44
- expect(LicenseAcceptance::ProductReader).to receive(:new).and_return(reader)
45
- expect(LicenseAcceptance::Strategy::File).to receive(:new).and_return(file_acc)
46
- expect(LicenseAcceptance::Strategy::Argument).to receive(:new).and_return(arg_acc)
47
- expect(LicenseAcceptance::Strategy::Prompt).to receive(:new).and_return(prompt_acc)
48
- expect(LicenseAcceptance::Strategy::Environment).to receive(:new).and_return(env_acc)
49
- expect(LicenseAcceptance::Strategy::ProvidedValue).to receive(:new).and_return(provided_acc)
50
-
51
- allow(provided_acc).to receive(:no_persist?).and_return(false)
52
- allow(env_acc).to receive(:no_persist?).and_return(false)
53
- allow(arg_acc).to receive(:no_persist?).and_return(false)
54
- allow(provided_acc).to receive(:accepted?).and_return(false)
55
- allow(env_acc).to receive(:accepted?).and_return(false)
56
- allow(arg_acc).to receive(:accepted?).and_return(false)
57
- allow(provided_acc).to receive(:silent?).and_return(false)
58
- allow(env_acc).to receive(:silent?).and_return(false)
59
- allow(arg_acc).to receive(:silent?).and_return(false)
60
-
61
- expect(reader).to receive(:read)
62
- end
63
-
64
- describe "when accept-no-persist is provided from the caller" do
65
- it "returns true" do
66
- expect(provided_acc).to receive(:no_persist?).and_return(true)
67
- expect(acc.check_and_persist(product, version)).to eq(true)
68
- expect(acc.acceptance_value).to eq(LicenseAcceptance::ACCEPT_NO_PERSIST)
69
- end
70
- end
71
-
72
- describe "when accept-no-persist environment variable is set" do
73
- it "returns true" do
74
- expect(env_acc).to receive(:no_persist?).and_return(true)
75
- expect(acc.check_and_persist(product, version)).to eq(true)
76
- expect(acc.acceptance_value).to eq(LicenseAcceptance::ACCEPT_NO_PERSIST)
77
- end
78
- end
79
-
80
- describe "when accept-no-persist command line argument is set" do
81
- it "returns true" do
82
- expect(arg_acc).to receive(:no_persist?).and_return(true)
83
- expect(acc.check_and_persist(product, version)).to eq(true)
84
- expect(acc.acceptance_value).to eq(LicenseAcceptance::ACCEPT_NO_PERSIST)
85
- end
86
- end
87
-
88
- describe "when there are no missing licenses" do
89
- it "returns true" do
90
- expect(reader).to receive(:lookup).with(product, version).and_return(relationship)
91
- expect(file_acc).to receive(:accepted?).with(relationship).and_return([])
92
- expect(acc.check_and_persist(product, version)).to eq(true)
93
- expect(acc.acceptance_value).to eq(LicenseAcceptance::ACCEPT)
94
- end
95
- end
96
-
97
- describe "when the user accepts as an environment variable" do
98
- it "returns true" do
99
- expect(reader).to receive(:lookup).with(product, version).and_return(relationship)
100
- expect(file_acc).to receive(:accepted?).with(relationship).and_return(missing)
101
- expect(env_acc).to receive(:accepted?).and_return(true)
102
- expect(file_acc).to receive(:persist).with(relationship, missing).and_return([])
103
- expect(acc.check_and_persist(product, version)).to eq(true)
104
- expect(output.string).to match(/1 product license accepted./)
105
- expect(acc.acceptance_value).to eq(LicenseAcceptance::ACCEPT)
106
- end
107
-
108
- describe "when persist is set to false" do
109
- let(:opts) { { output: output, persist: false } }
110
-
111
- it "returns true" do
112
- expect(reader).to receive(:lookup).with(product, version).and_return(relationship)
113
- expect(file_acc).to receive(:accepted?).with(relationship).and_return(missing)
114
- expect(env_acc).to receive(:accepted?).and_return(true)
115
- expect(acc.check_and_persist(product, version)).to eq(true)
116
- expect(output.string).to_not match(/accepted./)
117
- expect(acc.acceptance_value).to eq(LicenseAcceptance::ACCEPT)
118
- end
119
- end
120
-
121
- describe "when the silent option is used" do
122
- let(:opts) { { output: output } }
123
-
124
- it "returns true and silently persists the file" do
125
- expect(reader).to receive(:lookup).with(product, version).and_return(relationship)
126
- expect(file_acc).to receive(:accepted?).with(relationship).and_return(missing)
127
- expect(env_acc).to receive(:silent?).times.exactly(3).and_return(true)
128
- expect(file_acc).to receive(:persist).with(relationship, missing).and_return([])
129
- expect(acc.check_and_persist(product, version)).to eq(true)
130
- expect(output.string).to be_empty
131
- expect(acc.acceptance_value).to eq(LicenseAcceptance::ACCEPT_SILENT)
132
- end
133
- end
134
-
135
- describe "when file persistance fails" do
136
- it "returns true" do
137
- expect(reader).to receive(:lookup).with(product, version).and_return(relationship)
138
- expect(file_acc).to receive(:accepted?).with(relationship).and_return(missing)
139
- expect(env_acc).to receive(:accepted?).and_return(true)
140
- expect(file_acc).to receive(:persist).with(relationship, missing).and_return([StandardError.new("foo")])
141
- expect(acc.check_and_persist(product, version)).to eq(true)
142
- expect(output.string).to match(/Could not persist acceptance:/)
143
- expect(acc.acceptance_value).to eq(LicenseAcceptance::ACCEPT)
144
- end
145
- end
146
- end
147
-
148
- describe "when the user accepts as an arg" do
149
- it "returns true" do
150
- expect(reader).to receive(:lookup).with(product, version).and_return(relationship)
151
- expect(file_acc).to receive(:accepted?).with(relationship).and_return(missing)
152
- expect(arg_acc).to receive(:accepted?).and_return(true)
153
- expect(file_acc).to receive(:persist).with(relationship, missing).and_return([])
154
- expect(acc.check_and_persist(product, version)).to eq(true)
155
- expect(output.string).to match(/1 product license accepted./)
156
- expect(acc.acceptance_value).to eq(LicenseAcceptance::ACCEPT)
157
- end
158
-
159
- describe "when the silent option is used" do
160
- let(:opts) { { output: output } }
161
-
162
- it "returns true and silently persists the file" do
163
- expect(reader).to receive(:lookup).with(product, version).and_return(relationship)
164
- expect(file_acc).to receive(:accepted?).with(relationship).and_return(missing)
165
- expect(arg_acc).to receive(:silent?).times.exactly(3).and_return(true)
166
- expect(file_acc).to receive(:persist).with(relationship, missing).and_return([])
167
- expect(acc.check_and_persist(product, version)).to eq(true)
168
- expect(output.string).to be_empty
169
- expect(acc.acceptance_value).to eq(LicenseAcceptance::ACCEPT_SILENT)
170
- end
171
- end
172
-
173
-
174
- describe "when persist is set to false" do
175
- let(:opts) { { output: output, persist: false } }
176
-
177
- it "returns true" do
178
- expect(reader).to receive(:lookup).with(product, version).and_return(relationship)
179
- expect(file_acc).to receive(:accepted?).with(relationship).and_return(missing)
180
- expect(arg_acc).to receive(:accepted?).and_return(true)
181
- expect(acc.check_and_persist(product, version)).to eq(true)
182
- expect(output.string).to_not match(/accepted./)
183
- expect(acc.acceptance_value).to eq(LicenseAcceptance::ACCEPT)
184
- end
185
- end
186
-
187
- describe "when file persistance fails" do
188
- it "returns true" do
189
- expect(reader).to receive(:lookup).with(product, version).and_return(relationship)
190
- expect(file_acc).to receive(:accepted?).with(relationship).and_return(missing)
191
- expect(arg_acc).to receive(:accepted?).and_return(true)
192
- expect(file_acc).to receive(:persist).with(relationship, missing).and_return([StandardError.new("bar")])
193
- expect(acc.check_and_persist(product, version)).to eq(true)
194
- expect(output.string).to match(/Could not persist acceptance:/)
195
- expect(acc.acceptance_value).to eq(LicenseAcceptance::ACCEPT)
196
- end
197
- end
198
- end
199
-
200
- describe "when the prompt is not a tty" do
201
- let(:opts) { { output: File.open(File::NULL, "w") } }
202
- it "raises a LicenseNotAcceptedError error" do
203
- expect(reader).to receive(:lookup).with(product, version).and_return(relationship)
204
- expect(file_acc).to receive(:accepted?).with(relationship).and_return(missing)
205
- expect(prompt_acc).to_not receive(:request)
206
- expect { acc.check_and_persist(product, version) }.to raise_error(LicenseAcceptance::LicenseNotAcceptedError)
207
- expect(acc.acceptance_value).to eq(nil)
208
- end
209
- end
210
-
211
- describe "when the user accepts with the prompt" do
212
- it "returns true" do
213
- expect(reader).to receive(:lookup).with(product, version).and_return(relationship)
214
- expect(file_acc).to receive(:accepted?).with(relationship).and_return(missing)
215
- expect(prompt_acc).to receive(:request).with(missing).and_yield.and_return(true)
216
- expect(file_acc).to receive(:persist).with(relationship, missing)
217
- expect(acc.check_and_persist(product, version)).to eq(true)
218
- expect(acc.acceptance_value).to eq(LicenseAcceptance::ACCEPT)
219
- end
220
-
221
- describe "when persist is set to false" do
222
- let(:opts) { { output: output, persist: false } }
223
-
224
- it "returns true" do
225
- expect(reader).to receive(:lookup).with(product, version).and_return(relationship)
226
- expect(file_acc).to receive(:accepted?).with(relationship).and_return(missing)
227
- expect(prompt_acc).to receive(:request).with(missing).and_yield.and_return(true)
228
- expect(acc.check_and_persist(product, version)).to eq(true)
229
- expect(acc.acceptance_value).to eq(LicenseAcceptance::ACCEPT_NO_PERSIST)
230
- end
231
- end
232
- end
233
-
234
- describe "when the user declines with the prompt" do
235
- it "raises a LicenseNotAcceptedError error" do
236
- expect(reader).to receive(:lookup).with(product, version).and_return(relationship)
237
- expect(file_acc).to receive(:accepted?).with(relationship).and_return(missing)
238
- expect(prompt_acc).to receive(:request).with(missing).and_return(false)
239
- expect { acc.check_and_persist(product, version) }.to raise_error(LicenseAcceptance::LicenseNotAcceptedError)
240
- expect(acc.acceptance_value).to eq(nil)
241
- end
242
- end
243
- end
244
-
245
- describe "#license_required?" do
246
- let(:reader) { instance_double(LicenseAcceptance::ProductReader) }
247
- let(:mixlib_name) { "chef" }
248
- let(:version) { "15.0.0" }
249
- let(:product) { instance_double(LicenseAcceptance::Product, id: "foo", license_required_version: "15.0.0") }
250
-
251
- before do
252
- expect(LicenseAcceptance::ProductReader).to receive(:new).and_return(reader)
253
- expect(reader).to receive(:read)
254
- end
255
-
256
- it "returns false if no product can be found" do
257
- expect(reader).to receive(:lookup_by_mixlib).with(mixlib_name).and_return nil
258
- expect(acc.license_required?(mixlib_name, version)).to eq(false)
259
- end
260
-
261
- describe "when version is :latest" do
262
- let(:version) { :latest }
263
- it "returns true" do
264
- expect(reader).to receive(:lookup_by_mixlib).with(mixlib_name).and_return product
265
- expect(acc.license_required?(mixlib_name, version)).to eq(true)
266
- end
267
- end
268
-
269
- ["latest", "unstable", "current", "stable"].each do |version|
270
- describe "when version is '#{version}'" do
271
- it "returns true" do
272
- expect(reader).to receive(:lookup_by_mixlib).with(mixlib_name).and_return product
273
- expect(acc.license_required?(mixlib_name, version)).to eq(true)
274
- end
275
- end
276
- end
277
-
278
- describe "when version is nil" do
279
- let(:version) { nil }
280
- it "returns true" do
281
- expect(reader).to receive(:lookup_by_mixlib).with(mixlib_name).and_return product
282
- expect(acc.license_required?(mixlib_name, version)).to eq(true)
283
- end
284
- end
285
-
286
- describe "when version is >= than required version" do
287
- let(:version) { "15.0.0" }
288
- it "returns true" do
289
- expect(reader).to receive(:lookup_by_mixlib).with(mixlib_name).and_return product
290
- expect(acc.license_required?(mixlib_name, version)).to eq(true)
291
- end
292
- end
293
-
294
- describe "when version is < required version" do
295
- let(:version) { "14.99.99" }
296
- it "returns false" do
297
- expect(reader).to receive(:lookup_by_mixlib).with(mixlib_name).and_return product
298
- expect(acc.license_required?(mixlib_name, version)).to eq(false)
299
- end
300
- end
301
- end
302
- end
@@ -1,14 +0,0 @@
1
- require "spec_helper"
2
- require "license_acceptance/cli_flags/mixlib_cli"
3
-
4
- class TestMixlibKlass
5
- include Mixlib::CLI
6
- include LicenseAcceptance::CLIFlags::MixlibCLI
7
- end
8
-
9
- RSpec.describe LicenseAcceptance::CLIFlags::MixlibCLI do
10
- let(:klass) { TestMixlibKlass.new }
11
- it "adds the correct command line flag" do
12
- expect(klass.options).to include(:chef_license)
13
- end
14
- end
@@ -1,14 +0,0 @@
1
- require "spec_helper"
2
- require "license_acceptance/cli_flags/thor"
3
- require "thor"
4
-
5
- class TestThorKlass < Thor
6
- include LicenseAcceptance::CLIFlags::Thor
7
- end
8
-
9
- RSpec.describe LicenseAcceptance::CLIFlags::Thor do
10
- let(:klass) { TestThorKlass.new }
11
- it "adds the correct command line flag" do
12
- expect(klass.class.class_options.keys).to eq([:chef_license])
13
- end
14
- end
@@ -1,111 +0,0 @@
1
- require "spec_helper"
2
- require "climate_control"
3
- require "license_acceptance/config"
4
- require "license_acceptance/product_relationship"
5
-
6
- RSpec.describe LicenseAcceptance::Config do
7
- let(:opts) { {} }
8
- let(:config) { LicenseAcceptance::Config.new(opts) }
9
-
10
- it "loads correctly with default values" do
11
- config
12
- end
13
-
14
- describe "with overwritten values" do
15
- let(:output) { StringIO.new }
16
- let(:logger) { "logger" }
17
- let(:license_locations) { [] }
18
- let(:persist_location) { "foo" }
19
- let(:persist) { false }
20
- let(:opts) { { output: output, logger: logger, license_locations: license_locations, persist_location: persist_location, persist: persist } }
21
-
22
- it "loads correctly" do
23
- expect(config.output).to eq(output)
24
- expect(config.logger).to eq(logger)
25
- expect(config.license_locations).to eq(license_locations)
26
- expect(config.persist_location).to eq("foo")
27
- expect(config.persist).to eq(false)
28
- end
29
- end
30
-
31
- describe "#default_license_locations and #default_persist_location" do
32
- before do
33
- expect(Process).to receive(:uid).and_return(uid)
34
- end
35
-
36
- describe "when platform is Windows" do
37
- before do
38
- stub_const("RUBY_PLATFORM", "mingw")
39
- end
40
-
41
- describe "when user is Administrator" do
42
- let(:uid) { 0 }
43
-
44
- it "returns the default value" do
45
- ClimateControl.modify HOMEDRIVE: "C:" do
46
- expect(config.license_locations).to eq(["C:/chef/accepted_licenses/"])
47
- expect(config.persist_location).to eq("C:/chef/accepted_licenses/")
48
- end
49
- end
50
- end
51
-
52
- describe "when user is not Administrator" do
53
- let(:uid) { 1000 }
54
-
55
- it "returns the default USERPROFILE value" do
56
- ClimateControl.modify HOMEDRIVE: "C:", USERPROFILE: "C:/Users/foo", HOME: nil do
57
- expect(Dir).to receive(:exist?).with("C:/Users/foo").and_return(true)
58
- expect(config.license_locations).to eq([
59
- "C:/chef/accepted_licenses/",
60
- "C:/Users/foo/.chef/accepted_licenses/"
61
- ])
62
- expect(config.persist_location).to eq("C:/Users/foo/.chef/accepted_licenses/")
63
- end
64
- end
65
-
66
- it "returns the default HOMEDRIVE + HOMEPATH value" do
67
- ClimateControl.modify HOMEDRIVE: "C:", USERPROFILE: "C:/Users/bar", HOME: nil do
68
- expect(Dir).to receive(:exist?).with("C:/Users/bar").and_return(true)
69
- expect(config.license_locations).to eq([
70
- "C:/chef/accepted_licenses/",
71
- "C:/Users/bar/.chef/accepted_licenses/"
72
- ])
73
- expect(config.persist_location).to eq("C:/Users/bar/.chef/accepted_licenses/")
74
- end
75
- end
76
- end
77
-
78
- end
79
-
80
- describe "when platform is non-Windows" do
81
- before do
82
- stub_const("RUBY_PLATFORM", "darwin")
83
- end
84
-
85
- describe "when user is root" do
86
- let(:uid) { 0 }
87
-
88
- it "returns the default value" do
89
- expect(config.license_locations).to eq(["/etc/chef/accepted_licenses/"])
90
- expect(config.persist_location).to eq("/etc/chef/accepted_licenses/")
91
- end
92
- end
93
-
94
- describe "when user is not root" do
95
- let(:uid) { 1000 }
96
-
97
- it "returns the default user value" do
98
- ClimateControl.modify HOME: "/Users/foo" do
99
- expect(config.license_locations).to eq([
100
- "/etc/chef/accepted_licenses/",
101
- "/Users/foo/.chef/accepted_licenses/"
102
- ])
103
- expect(config.persist_location).to eq("/Users/foo/.chef/accepted_licenses/")
104
- end
105
- end
106
- end
107
-
108
- end
109
- end
110
-
111
- end
@@ -1,155 +0,0 @@
1
- require "spec_helper"
2
- require "license_acceptance/product_reader"
3
- require "license_acceptance/product_relationship"
4
-
5
- RSpec.describe LicenseAcceptance::ProductReader do
6
- let(:reader) { LicenseAcceptance::ProductReader.new }
7
- let(:version) { "0.1.0" }
8
- let(:location) { "location" }
9
-
10
- let(:p1) { {"id" => "p1", "pretty_name" => "P1", "filename" => "f1", "mixlib_name" => "p1m", "license_required_version" => "p1v"} }
11
- let(:p2) { {"id" => "p2", "pretty_name" => "P2", "filename" => "f2", "mixlib_name" => "p2m", "license_required_version" => "p2v"} }
12
- # defined the `==` operator on Product for ease of comparison
13
- let(:product1) { LicenseAcceptance::Product.new(p1["id"], p1["pretty_name"], p1["filename"], p1["mixlib_name"], p1["license_required_version"]) }
14
- let(:product2) { LicenseAcceptance::Product.new(p2["id"], p2["pretty_name"], p2["filename"], p2["mixlib_name"], p2["license_required_version"]) }
15
- let(:r1) { {p1 => p2} }
16
- let(:toml) { {"products" => [p1, p2], "relationships" => {"p1" => ["p2"]}} }
17
-
18
- describe "#read" do
19
- it "reads products and relationships" do
20
- expect(reader).to receive(:get_location).and_return(location)
21
- expect(Tomlrb).to receive(:load_file).with(location, symbolize_keys: false).and_return(toml)
22
- reader.read
23
- expect(reader.products).to eq({
24
- "p1" => product1,
25
- "p2" => product2
26
- })
27
- expect(reader.relationships.size).to eq(1)
28
- expect(reader.relationships.first).to eq([product1, [product2]])
29
- end
30
-
31
- describe "with an empty file" do
32
- it "raises a InvalidProductInfo error" do
33
- expect(reader).to receive(:get_location).and_return(location)
34
- expect(Tomlrb).to receive(:load_file).with(location, symbolize_keys: false).and_return({})
35
-
36
- expect { reader.read }.to raise_error(LicenseAcceptance::InvalidProductInfo)
37
- end
38
- end
39
-
40
- describe "with an unknown parent" do
41
- let(:toml) { {"products" => [p1, p2], "relationships" => {"p3" => ["p2"]}} }
42
-
43
- it "raises a UnknownParent error" do
44
- expect(reader).to receive(:get_location).and_return(location)
45
- expect(Tomlrb).to receive(:load_file).with(location, symbolize_keys: false).and_return(toml)
46
-
47
- expect { reader.read }.to raise_error(LicenseAcceptance::UnknownParent)
48
- end
49
- end
50
-
51
- describe "with a relationship of nil children" do
52
- let(:toml) { {"products" => [p1], "relationships" => {"p1" => nil}} }
53
-
54
- it "raises a NoChildRelationships error" do
55
- expect(reader).to receive(:get_location).and_return(location)
56
- expect(Tomlrb).to receive(:load_file).with(location, symbolize_keys: false).and_return(toml)
57
-
58
- expect { reader.read }.to raise_error(LicenseAcceptance::NoChildRelationships)
59
- end
60
- end
61
-
62
- describe "with a relationship of empty children" do
63
- let(:toml) { {"products" => [p1], "relationships" => {"p1" => []}} }
64
-
65
- it "raises a NoChildRelationships error" do
66
- expect(reader).to receive(:get_location).and_return(location)
67
- expect(Tomlrb).to receive(:load_file).with(location, symbolize_keys: false).and_return(toml)
68
-
69
- expect { reader.read }.to raise_error(LicenseAcceptance::NoChildRelationships)
70
- end
71
- end
72
-
73
- describe "with a relationship of non-array children" do
74
- let(:toml) { {"products" => [p1], "relationships" => {"p1" => "p2"}} }
75
-
76
- it "raises a NoChildRelationships error" do
77
- expect(reader).to receive(:get_location).and_return(location)
78
- expect(Tomlrb).to receive(:load_file).with(location, symbolize_keys: false).and_return(toml)
79
-
80
- expect { reader.read }.to raise_error(LicenseAcceptance::NoChildRelationships)
81
- end
82
- end
83
-
84
- describe "with an unknown child" do
85
- let(:toml) { {"products" => [p1, p2], "relationships" => {"p1" => ["p2", "p3"]}} }
86
-
87
- it "raises a UnknownChild error" do
88
- expect(reader).to receive(:get_location).and_return(location)
89
- expect(Tomlrb).to receive(:load_file).with(location, symbolize_keys: false).and_return(toml)
90
-
91
- expect { reader.read }.to raise_error(LicenseAcceptance::UnknownChild)
92
- end
93
- end
94
- end
95
-
96
- describe "::lookup" do
97
- before do
98
- expect(reader).to receive(:get_location).and_return(location)
99
- expect(Tomlrb).to receive(:load_file).with(location, symbolize_keys: false).and_return(toml)
100
- reader.read
101
- end
102
-
103
- it "returns a ProductRelationship instance successfully" do
104
- expect(reader.lookup("p1", version)).to be_an_instance_of(LicenseAcceptance::ProductRelationship) do |instance|
105
- expect(instance.parent_product).to eq(product1)
106
- expect(instance.children).to eq([prouct2])
107
- expect(instance.version).to eq(version)
108
- end
109
- end
110
-
111
- describe "when called on an unknown product" do
112
- it "raises an UnknownProduct error" do
113
- expect { reader.lookup("DNE", nil) }.to raise_error(LicenseAcceptance::UnknownProduct)
114
- end
115
- end
116
-
117
- let(:nonya) { LicenseAcceptance::Product.new("nonya", "NonYa", "nofile", "no_mixlib", "no_version") }
118
- describe "when called on a product with no relationship" do
119
- before do
120
- reader.products = { "nonya" => nonya }
121
- end
122
-
123
- it "returns the product" do
124
- expect(reader.lookup('nonya', version)).to be_an_instance_of(LicenseAcceptance::ProductRelationship) do |instance|
125
- expect(instance.parent_product).to eq(nonya)
126
- expect(instance.children).to eq([])
127
- expect(instance.version).to eq(version)
128
- end
129
- end
130
- end
131
-
132
- describe "when called with an invalid parent version type" do
133
- it "raises an ProductVersionTypeError error" do
134
- expect { reader.lookup("p1", 1) }.to raise_error(LicenseAcceptance::ProductVersionTypeError)
135
- end
136
- end
137
- end
138
-
139
- describe "::lookup_by_mixlib" do
140
- before do
141
- expect(reader).to receive(:get_location).and_return(location)
142
- expect(Tomlrb).to receive(:load_file).with(location, symbolize_keys: false).and_return(toml)
143
- reader.read
144
- end
145
-
146
- it "returns a Product successfully" do
147
- expect(reader.lookup_by_mixlib("p1m")).to eq(product1)
148
- end
149
-
150
- it "returns nil for an unknown product" do
151
- expect(reader.lookup_by_mixlib("foo")).to eq(nil)
152
- end
153
- end
154
-
155
- end
@@ -1,15 +0,0 @@
1
- require "spec_helper"
2
- require "license_acceptance/product"
3
-
4
- RSpec.describe LicenseAcceptance::Product do
5
- let(:instance) { LicenseAcceptance::Product.new("id", "Pretty Name", "filename", "mixlib_name", "version") }
6
-
7
- it "can lookup the product attributes" do
8
- expect(instance.id).to eq("id")
9
- expect(instance.pretty_name).to eq("Pretty Name")
10
- expect(instance.filename).to eq("filename")
11
- expect(instance.mixlib_name).to eq("mixlib_name")
12
- expect(instance.license_required_version).to eq("version")
13
- end
14
-
15
- end
@@ -1,82 +0,0 @@
1
- require "spec_helper"
2
- require "license_acceptance/strategy/argument"
3
-
4
- RSpec.describe LicenseAcceptance::Strategy::Argument do
5
- let(:acc) { LicenseAcceptance::Strategy::Argument.new(argv) }
6
-
7
- describe "#accepted?" do
8
- describe "when value is space seperated" do
9
- let(:argv) { ["--chef-license", "accept"] }
10
- it "returns true if the args contain the required flag with spaces" do
11
- expect(acc.accepted?).to eq(true)
12
- end
13
- end
14
-
15
- describe "when the value is equal seperated" do
16
- let(:argv) { ["--chef-license=accept"] }
17
- it "returns true if the args contain the required flag with equal" do
18
- expect(acc.accepted?).to eq(true)
19
- end
20
- end
21
-
22
- [ ["--chef-license"], ["--chef-license=foo"], ["--chef-license", "foo"] ].each do |v|
23
- describe "when the value is #{v}" do
24
- let(:argv) { v }
25
- it "returns false if the args do not contain the required value" do
26
- expect(acc.accepted?).to eq(false)
27
- end
28
- end
29
- end
30
- end
31
-
32
- describe "#silent?" do
33
- describe "when value is space seperated" do
34
- let(:argv) { ["--chef-license", "accept-silent"] }
35
- it "returns true if the args contain the required flag with spaces" do
36
- expect(acc.silent?).to eq(true)
37
- end
38
- end
39
-
40
- describe "when the value is equal seperated" do
41
- let(:argv) { ["--chef-license=accept-silent"] }
42
- it "returns true if the args contain the required flag with equal" do
43
- expect(acc.silent?).to eq(true)
44
- end
45
- end
46
-
47
- [ ["--chef-license"], ["--chef-license=accept"], ["--chef-license", "accept"] ].each do |v|
48
- describe "when the value is #{v}" do
49
- let(:argv) { v }
50
- it "returns false if the args do not contain the required value" do
51
- expect(acc.silent?).to eq(false)
52
- end
53
- end
54
- end
55
- end
56
-
57
- describe "#no_persist?" do
58
- describe "when value is space seperated" do
59
- let(:argv) { ["--chef-license", "accept-no-persist"] }
60
- it "returns true if the args contain the required flag with spaces" do
61
- expect(acc.no_persist?).to eq(true)
62
- end
63
- end
64
-
65
- describe "when the value is equal seperated" do
66
- let(:argv) { ["--chef-license=accept-no-persist"] }
67
- it "returns true if the args contain the required flag with equal" do
68
- expect(acc.no_persist?).to eq(true)
69
- end
70
- end
71
-
72
- [ ["--chef-license"], ["--chef-license=accept"], ["--chef-license", "accept"] ].each do |v|
73
- describe "when the value is #{v}" do
74
- let(:argv) { v }
75
- it "returns false if the args do not contain the required value" do
76
- expect(acc.no_persist?).to eq(false)
77
- end
78
- end
79
- end
80
- end
81
-
82
- end
@@ -1,76 +0,0 @@
1
- require "spec_helper"
2
- require "license_acceptance/strategy/environment"
3
-
4
- RSpec.describe LicenseAcceptance::Strategy::Environment do
5
- let(:acc) { LicenseAcceptance::Strategy::Environment.new(env) }
6
-
7
- describe "#accepted?" do
8
- describe "when the environment contains the correct key and value" do
9
- let(:env) { {"CHEF_LICENSE" => "accept"} }
10
- it "returns true" do
11
- expect(acc.accepted?).to eq(true)
12
- end
13
- end
14
-
15
- describe "when the env has a key but nil value" do
16
- let(:env) { {"CHEF_LICENSE" => nil} }
17
- it "returns false" do
18
- expect(acc.accepted?).to eq(false)
19
- end
20
- end
21
-
22
- describe "when the env has a key but incorrect value" do
23
- let(:env) { {"CHEF_LICENSE" => "foo"} }
24
- it "returns false" do
25
- expect(acc.accepted?).to eq(false)
26
- end
27
- end
28
- end
29
-
30
- describe "#silent?" do
31
- describe "when the environment contains the correct key and value" do
32
- let(:env) { {"CHEF_LICENSE" => "accept-silent"} }
33
- it "returns true" do
34
- expect(acc.silent?).to eq(true)
35
- end
36
- end
37
-
38
- describe "when the env has a key but nil value" do
39
- let(:env) { {"CHEF_LICENSE" => nil} }
40
- it "returns false" do
41
- expect(acc.silent?).to eq(false)
42
- end
43
- end
44
-
45
- describe "when the env has a key but incorrect value" do
46
- let(:env) { {"CHEF_LICENSE" => "accept"} }
47
- it "returns false" do
48
- expect(acc.silent?).to eq(false)
49
- end
50
- end
51
- end
52
-
53
- describe "#no_persist?" do
54
- describe "when the environment contains the correct key and value" do
55
- let(:env) { {"CHEF_LICENSE" => "accept-no-persist"} }
56
- it "returns true" do
57
- expect(acc.no_persist?).to eq(true)
58
- end
59
- end
60
-
61
- describe "when the env has a key but nil value" do
62
- let(:env) { {"CHEF_LICENSE" => nil} }
63
- it "returns false" do
64
- expect(acc.no_persist?).to eq(false)
65
- end
66
- end
67
-
68
- describe "when the env has a key but incorrect value" do
69
- let(:env) { {"CHEF_LICENSE" => "accept-silent"} }
70
- it "returns false" do
71
- expect(acc.no_persist?).to eq(false)
72
- end
73
- end
74
- end
75
-
76
- end
@@ -1,127 +0,0 @@
1
- require "spec_helper"
2
- require "license_acceptance/config"
3
- require "license_acceptance/strategy/file"
4
- require "license_acceptance/product_relationship"
5
- require "license_acceptance/product"
6
-
7
- RSpec.describe LicenseAcceptance::Strategy::File do
8
- let(:dir1) { "/dir1" }
9
- let(:dir2) { "/dir2" }
10
- let(:dir3) { "/dir3" }
11
- let(:config) do
12
- instance_double(LicenseAcceptance::Config, license_locations: [dir1, dir2], persist_location: dir3)
13
- end
14
- let(:acc) { LicenseAcceptance::Strategy::File.new(config) }
15
- let(:p1_id) { "foo" }
16
- let(:p1_filename) { "p1_filename" }
17
- let(:p1_pretty) { "Pretty Name" }
18
- let(:p1) { instance_double(LicenseAcceptance::Product, id: p1_id, filename: p1_filename, pretty_name: p1_pretty) }
19
- let(:version) { "0.1.0" }
20
- let(:product_relationship) { instance_double(LicenseAcceptance::ProductRelationship, parent: p1, children: [], parent_version: version) }
21
- let(:mode) { File::WRONLY | File::CREAT | File::EXCL }
22
-
23
- describe "#check" do
24
- describe "when there is an existing license file" do
25
- it "returns an empty missing product list" do
26
- expect(File).to receive(:exist?).with(File.join(dir1, p1_filename)).and_return(true)
27
- expect(acc.accepted?(product_relationship)).to eq([])
28
- end
29
- end
30
-
31
- describe "when there is not an existing license file" do
32
- it "returns the product in the missing product list" do
33
- expect(File).to receive(:exist?).with(File.join(dir1, p1_filename)).and_return(false)
34
- expect(File).to receive(:exist?).with(File.join(dir2, p1_filename)).and_return(false)
35
- expect(acc.accepted?(product_relationship)).to eq([p1])
36
- end
37
- end
38
-
39
- describe "#persist" do
40
- let(:file) { double("file") }
41
-
42
- it "stores a single license without children" do
43
- expect(Dir).to receive(:exist?).with(dir3).and_return(true)
44
- expect(File).to receive(:open).with(File.join(dir3, p1_filename), mode).and_yield(file)
45
- expect(file).to receive(:<<) do |yaml|
46
- yaml = YAML.load(yaml)
47
- expect(yaml["id"]).to eq(p1_id)
48
- expect(yaml["name"]).to eq(p1_pretty)
49
- expect(yaml["accepting_product"]).to eq(p1_id)
50
- expect(yaml["accepting_product_version"]).to eq(version)
51
- end
52
- expect(acc.persist(product_relationship, [p1])).to eq([])
53
- end
54
-
55
- describe "when license has children" do
56
- let(:p2_id) { "bar" }
57
- let(:p2_filename) { "p2_filename" }
58
- let(:p2_pretty) { "Other Pretty Name" }
59
- let(:p2) { instance_double(LicenseAcceptance::Product, id: p2_id, filename: p2_filename, pretty_name: p2_pretty) }
60
- let(:product_relationship) {
61
- instance_double(
62
- LicenseAcceptance::ProductRelationship,
63
- parent: p1,
64
- children: [p2],
65
- parent_version: version
66
- )
67
- }
68
-
69
- it "stores a license file for all" do
70
- expect(Dir).to receive(:exist?).with(dir3).and_return(true)
71
- expect(File).to receive(:open).with(File.join(dir3, p1_filename), mode).and_yield(file)
72
- expect(file).to receive(:<<) do |yaml|
73
- yaml = YAML.load(yaml)
74
- expect(yaml["id"]).to eq(p1_id)
75
- expect(yaml["name"]).to eq(p1_pretty)
76
- expect(yaml["accepting_product"]).to eq(p1_id)
77
- expect(yaml["accepting_product_version"]).to eq(version)
78
- end
79
- expect(File).to receive(:open).with(File.join(dir3, p2_filename), mode).and_yield(file)
80
- expect(file).to receive(:<<) do |yaml|
81
- yaml = YAML.load(yaml)
82
- expect(yaml["id"]).to eq(p2_id)
83
- expect(yaml["name"]).to eq(p2_pretty)
84
- expect(yaml["accepting_product"]).to eq(p1_id)
85
- expect(yaml["accepting_product_version"]).to eq(version)
86
- end
87
- expect(acc.persist(product_relationship, [p1, p2])).to eq([])
88
- end
89
-
90
- describe "when parent is already persisted" do
91
- it "only stores a license file for the child" do
92
- expect(Dir).to receive(:exist?).with(dir3).and_return(true)
93
- expect(File).to receive(:open).once.with(File.join(dir3, p2_filename), mode).and_yield(file)
94
- expect(file).to receive(:<<) do |yaml|
95
- yaml = YAML.load(yaml)
96
- expect(yaml["id"]).to eq(p2_id)
97
- expect(yaml["name"]).to eq(p2_pretty)
98
- expect(yaml["accepting_product"]).to eq(p1_id)
99
- expect(yaml["accepting_product_version"]).to eq(version)
100
- end
101
- expect(acc.persist(product_relationship, [p2])).to eq([])
102
- end
103
- end
104
- end
105
-
106
- describe "when the folder cannot be created" do
107
- let(:err) { StandardError.new("foo") }
108
- it "returns the error" do
109
- expect(Dir).to receive(:exist?).with(dir3).and_return(false)
110
- expect(FileUtils).to receive(:mkdir_p).and_raise(err)
111
- expect(File).to_not receive(:open)
112
- expect(acc.persist(product_relationship, [p1])).to eq([err])
113
- end
114
- end
115
-
116
- describe "when the file cannot be written" do
117
- let(:err) { StandardError.new("bar") }
118
- it "returns the error" do
119
- expect(Dir).to receive(:exist?).with(dir3).and_return(true)
120
- expect(File).to receive(:open).with(File.join(dir3, p1_filename), mode).and_raise(err)
121
- expect(acc.persist(product_relationship, [p1])).to eq([err])
122
- end
123
- end
124
- end
125
-
126
- end
127
- end
@@ -1,100 +0,0 @@
1
- require "spec_helper"
2
- require "license_acceptance/strategy/prompt"
3
- require "license_acceptance/product"
4
- require "tty-prompt"
5
-
6
- RSpec.describe LicenseAcceptance::Strategy::Prompt do
7
- let(:output) { StringIO.new }
8
- let(:config) do
9
- instance_double(LicenseAcceptance::Config, output: output)
10
- end
11
- let(:acc) { LicenseAcceptance::Strategy::Prompt.new(config) }
12
- let(:prompt) { instance_double(TTY::Prompt) }
13
- let(:p1) { instance_double(LicenseAcceptance::Product, id: "foo", pretty_name: "Pretty Name") }
14
- let(:missing_licenses) { [p1] }
15
-
16
- before do
17
- expect(TTY::Prompt).to receive(:new).at_least(:once).and_return(prompt)
18
- end
19
-
20
- describe "when the user accepts" do
21
- it "returns true" do
22
- expect(prompt).to receive(:ask).and_return("yes")
23
- msg1 = /License that need accepting:\n \* #{p1.pretty_name}/m
24
- msg2 = /product license persisted\./
25
- b = Proc.new { [] }
26
- expect(acc.request(missing_licenses, &b)).to eq(true)
27
- expect(output.string).to match(msg1)
28
- expect(output.string).to match(msg2)
29
- end
30
-
31
- describe "when there are multiple products" do
32
- let(:p2) { instance_double(LicenseAcceptance::Product, id: "bar", pretty_name: "Other") }
33
- let(:missing_licenses) { [p1, p2] }
34
- it "returns true" do
35
- expect(prompt).to receive(:ask).and_return("yes")
36
- msg1 = /Licenses that need accepting:\n \* #{p1.pretty_name}\n \* #{p2.pretty_name}/m
37
- msg2 = /product licenses persisted\./
38
- msg3 = /2 product licenses\nmust be accepted/m
39
- b = Proc.new { [] }
40
- expect(acc.request(missing_licenses, &b)).to eq(true)
41
- expect(output.string).to match(msg1)
42
- expect(output.string).to match(msg2)
43
- expect(output.string).to match(msg3)
44
- end
45
- end
46
-
47
- describe "when the callback returns an error" do
48
- it "returns true" do
49
- expect(prompt).to receive(:ask).and_return("yes")
50
- msg1 = /License that need accepting:\n \* #{p1.pretty_name}/m
51
- msg2 = /Could not persist acceptance:/
52
- b = Proc.new { [StandardError.new("foo")] }
53
- expect(acc.request(missing_licenses, &b)).to eq(true)
54
- expect(output.string).to match(msg1)
55
- expect(output.string).to match(msg2)
56
- end
57
- end
58
- end
59
-
60
- describe "when the prompt times out" do
61
- it "returns false" do
62
- expect(Timeout).to receive(:timeout).twice.and_yield
63
- expect(prompt).to receive(:ask).twice.and_raise(LicenseAcceptance::Strategy::PromptTimeout)
64
- expect(prompt).to receive(:unsubscribe).twice
65
- expect(prompt).to receive(:reader).twice
66
- msg1 = /Prompt timed out./
67
- b = Proc.new { [] }
68
- expect(acc.request(missing_licenses, &b)).to eq(false)
69
- expect(output.string).to match(msg1)
70
- end
71
- end
72
-
73
- describe "when the user declines twice" do
74
- it "returns false" do
75
- expect(prompt).to receive(:ask).twice.and_return("no")
76
- msg1 = /License that need accepting:\n \* #{p1.pretty_name}/m
77
- msg2 = /product license persisted\./
78
- b = Proc.new { raise "should not be called" }
79
- expect(acc.request(missing_licenses, &b)).to eq(false)
80
- expect(output.string).to match(msg1)
81
- expect(output.string).to_not match(msg2)
82
- end
83
- end
84
-
85
- describe "when the user declines once then accepts" do
86
- it "returns true" do
87
- expect(prompt).to receive(:ask).and_return("no")
88
- expect(prompt).to receive(:ask).and_return("yes")
89
- msg1 = /License that need accepting:\n \* #{p1.pretty_name}/m
90
- msg2 = /product license persisted\./
91
- msg3 = /If you do not accept this license you will\nnot be able to use Chef products/m
92
- b = Proc.new { [] }
93
- expect(acc.request(missing_licenses, &b)).to eq(true)
94
- expect(output.string).to match(msg1)
95
- expect(output.string).to match(msg2)
96
- expect(output.string).to match(msg3)
97
- end
98
- end
99
-
100
- end
@@ -1,55 +0,0 @@
1
- require "spec_helper"
2
- require "license_acceptance/strategy/provided_value"
3
-
4
- RSpec.describe LicenseAcceptance::Strategy::ProvidedValue do
5
- let(:acc) { LicenseAcceptance::Strategy::ProvidedValue.new(value) }
6
-
7
- describe "#accepted?" do
8
- describe "when the value is correct" do
9
- let(:value) { "accept" }
10
- it "returns true" do
11
- expect(acc.accepted?).to eq(true)
12
- end
13
- end
14
-
15
- describe "when the value is incorrect" do
16
- let(:value) { nil }
17
- it "returns false" do
18
- expect(acc.accepted?).to eq(false)
19
- end
20
- end
21
- end
22
-
23
- describe "#silent?" do
24
- describe "when the value is correct" do
25
- let(:value) { "accept-silent" }
26
- it "returns true" do
27
- expect(acc.silent?).to eq(true)
28
- end
29
- end
30
-
31
- describe "when the value is incorrect" do
32
- let(:value) { "accept" }
33
- it "returns false" do
34
- expect(acc.silent?).to eq(false)
35
- end
36
- end
37
- end
38
-
39
- describe "#no_persist?" do
40
- describe "when the value is correct" do
41
- let(:value) { "accept-no-persist" }
42
- it "returns true" do
43
- expect(acc.no_persist?).to eq(true)
44
- end
45
- end
46
-
47
- describe "when the value is incorrect" do
48
- let(:value) { "accept-silent" }
49
- it "returns false" do
50
- expect(acc.no_persist?).to eq(false)
51
- end
52
- end
53
- end
54
-
55
- end
@@ -1,25 +0,0 @@
1
- require "bundler/setup"
2
- require "license_acceptance/logger"
3
- require "logger"
4
-
5
- RSpec.configure do |config|
6
- # Enable flags like --only-failures and --next-failure
7
- config.example_status_persistence_file_path = ".rspec_status"
8
-
9
- # Disable RSpec exposing methods globally on `Module` and `main`
10
- config.disable_monkey_patching!
11
-
12
- config.filter_run :focus => true
13
- config.run_all_when_everything_filtered = true
14
- config.mock_with :rspec do |mocks|
15
- mocks.verify_partial_doubles = true
16
- end
17
-
18
- config.expect_with :rspec do |c|
19
- c.syntax = :expect
20
- end
21
-
22
- config.before(:all) do
23
- LicenseAcceptance::Logger.initialize(::Logger.new(IO::NULL))
24
- end
25
- end