license-acceptance 0.2.6 → 0.2.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f86114ca5b22ab56cb28a423f3c60cd092241b8541bbf569002a5003e08da1f7
4
- data.tar.gz: 1347d3b7392ecbb2730b8fb4b5a7039efede80f8518443bd816b307af0c986e4
3
+ metadata.gz: d112a4c55882d1077473a7a895c41dc1ea39a44318fd875cf67e3055bf71e3ba
4
+ data.tar.gz: f37d0e22fb520876b151b063779355eb9f8ce6453ebc53c28880f2622de03297
5
5
  SHA512:
6
- metadata.gz: d8bbb8bae60146e0736abdc9b7492b69c0b822936f13411b9159b7267d341910f2a6d6a76dd9f2e5120b7e7bb7568c88c0a8b0a9ed61d1e99b7c11f0ca0757fd
7
- data.tar.gz: b829ddf04523ec275a961449befde2f0b978e313e0264c799a77659a13fa95ff6d3b17bf00a3a5dc768867d8b1bb652fa9dbfc94746a49c5aa8834b1fce5be89
6
+ metadata.gz: 0b44866f1295dd5b862df99648fb8904e7041d90edfa502b8d2ee122d1da8bfc93075b83fa614102a190607a5b900c97479491fbad894cbcd61b69cebab7b1ea
7
+ data.tar.gz: eecca8e33010d24877e1e5839cb6bddc89c6fc8467feba8f2a41b6f5dbe06fe9ceb9fc438712999c8a7db5baa73b422e572ffe46d6eb9fec2a0df78c25159101
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- license-acceptance (0.2.5)
4
+ license-acceptance (0.2.7)
5
5
  pastel (~> 0.7)
6
6
  tomlrb (~> 1.2)
7
7
  tty-box (~> 0.3)
@@ -38,7 +38,7 @@ module LicenseAcceptance
38
38
  end
39
39
 
40
40
  def check_and_persist(product_name, version)
41
- if env_acceptance.check_no_persist(ENV) || arg_acceptance.check_no_persist(ARGV)
41
+ if accepted_no_persist?
42
42
  logger.debug("Chef License accepted with no persistence")
43
43
  return true
44
44
  end
@@ -46,7 +46,7 @@ module LicenseAcceptance
46
46
  product_reader.read
47
47
  product_relationship = product_reader.lookup(product_name, version)
48
48
 
49
- missing_licenses = file_acceptance.check(product_relationship)
49
+ missing_licenses = file_acceptance.accepted?(product_relationship)
50
50
 
51
51
  # They have already accepted all licenses and stored their acceptance in the persistent files
52
52
  if missing_licenses.empty?
@@ -54,11 +54,11 @@ module LicenseAcceptance
54
54
  return true
55
55
  end
56
56
 
57
- if env_acceptance.check(ENV) || arg_acceptance.check(ARGV)
57
+ if accepted? || accepted_silent?
58
58
  if config.persist
59
59
  errs = file_acceptance.persist(product_relationship, missing_licenses)
60
60
  if errs.empty?
61
- output_num_persisted(missing_licenses.size)
61
+ output_num_persisted(missing_licenses.size) unless accepted_silent?
62
62
  else
63
63
  output_persist_failed(errs)
64
64
  end
@@ -85,6 +85,20 @@ module LicenseAcceptance
85
85
  new(opts).check_and_persist(product_name, version)
86
86
  end
87
87
 
88
+ def accepted?
89
+ env_acceptance.accepted?(ENV) || arg_acceptance.accepted?(ARGV)
90
+ end
91
+
92
+ # no-persist is silent too
93
+ def accepted_no_persist?
94
+ env_acceptance.no_persist?(ENV) || arg_acceptance.no_persist?(ARGV)
95
+ end
96
+
97
+ # persist but be silent like no-persist
98
+ def accepted_silent?
99
+ env_acceptance.silent?(ENV) || arg_acceptance.silent?(ARGV)
100
+ end
101
+
88
102
  # In the case where users accept with a command line argument or environment variable
89
103
  # we still want to output the fact that the filesystem was changed.
90
104
  def output_num_persisted(count)
@@ -1,33 +1,32 @@
1
1
  module LicenseAcceptance
2
2
  class ArgAcceptance
3
3
 
4
- def check(argv)
5
- if argv.include?("--chef-license=accept")
6
- return true
7
- end
8
- i = argv.index("--chef-license")
9
- unless i.nil?
10
- val = argv[i+1]
11
- if val != nil && val.downcase == "accept"
12
- return true
13
- end
14
- end
15
- return false
4
+ def accepted?(argv)
5
+ look_for_value(argv, "accept")
6
+ end
7
+
8
+ def silent?(argv)
9
+ look_for_value(argv, "accept-silent")
16
10
  end
17
11
 
18
- def check_no_persist(argv)
19
- if argv.include?("--chef-license=accept-no-persist")
12
+ def no_persist?(argv)
13
+ look_for_value(argv, "accept-no-persist")
14
+ end
15
+
16
+ private
17
+
18
+ def look_for_value(argv, sought)
19
+ if argv.include?("--chef-license=#{sought}")
20
20
  return true
21
21
  end
22
22
  i = argv.index("--chef-license")
23
23
  unless i.nil?
24
24
  val = argv[i+1]
25
- if val != nil && val.downcase == "accept-no-persist"
25
+ if val != nil && val.downcase == sought
26
26
  return true
27
27
  end
28
28
  end
29
29
  return false
30
30
  end
31
-
32
31
  end
33
32
  end
@@ -12,7 +12,7 @@ module LicenseAcceptance
12
12
  def self.included(klass)
13
13
  klass.option :chef_license,
14
14
  long: "--chef-license ACCEPTANCE",
15
- description: "Accept the license for this product and any contained products ('accept' or 'accept-no-persist')",
15
+ description: "Accept the license for this product and any contained products ('accept', 'accept-no-persist', or 'accept-silent')",
16
16
  required: false
17
17
  end
18
18
 
@@ -12,7 +12,7 @@ module LicenseAcceptance
12
12
  def self.included(klass)
13
13
  klass.class_option :chef_license,
14
14
  type: :string,
15
- desc: 'Accept the license for this product and any contained products: accept, accept-no-persist'
15
+ desc: 'Accept the license for this product and any contained products: accept, accept-no-persist, accept-silent'
16
16
  end
17
17
 
18
18
  end
@@ -1,15 +1,22 @@
1
1
  module LicenseAcceptance
2
2
  class EnvAcceptance
3
3
 
4
- def check(env)
5
- if env['CHEF_LICENSE'] && env['CHEF_LICENSE'].downcase == 'accept'
6
- return true
7
- end
8
- return false
4
+ def accepted?(env)
5
+ look_for_value(env, "accept")
6
+ end
7
+
8
+ def silent?(env)
9
+ look_for_value(env, "accept-silent")
10
+ end
11
+
12
+ def no_persist?(env)
13
+ look_for_value(env, "accept-no-persist")
9
14
  end
10
15
 
11
- def check_no_persist(env)
12
- if env['CHEF_LICENSE'] && env['CHEF_LICENSE'].downcase == 'accept-no-persist'
16
+ private
17
+
18
+ def look_for_value(env, sought)
19
+ if env['CHEF_LICENSE'] && env['CHEF_LICENSE'].downcase == sought
13
20
  return true
14
21
  end
15
22
  return false
@@ -18,7 +18,7 @@ module LicenseAcceptance
18
18
 
19
19
  # For all the given products in the product set, search all possible locations for the
20
20
  # license acceptance files.
21
- def check(product_relationship)
21
+ def accepted?(product_relationship)
22
22
  searching = [product_relationship.parent] + product_relationship.children
23
23
  missing_licenses = searching.clone
24
24
  logger.debug("Searching for the following licenses: #{missing_licenses.map(&:name)}")
@@ -1,3 +1,3 @@
1
1
  module LicenseAcceptance
2
- VERSION = "0.2.6"
2
+ VERSION = "0.2.8"
3
3
  end
@@ -45,38 +45,40 @@ RSpec.describe LicenseAcceptance::Acceptor do
45
45
 
46
46
  describe "when check-no-persist environment variable is set" do
47
47
  it "returns true" do
48
- expect(env_acc).to receive(:check_no_persist).and_return(true)
48
+ expect(env_acc).to receive(:no_persist?).and_return(true)
49
49
  expect(acc.check_and_persist(product, version)).to eq(true)
50
50
  end
51
51
  end
52
52
 
53
53
  describe "when check-no-persist command line argument is set" do
54
54
  it "returns true" do
55
- expect(env_acc).to receive(:check_no_persist).and_return(false)
56
- expect(arg_acc).to receive(:check_no_persist).and_return(true)
55
+ expect(env_acc).to receive(:no_persist?).and_return(false)
56
+ expect(arg_acc).to receive(:no_persist?).and_return(true)
57
57
  expect(acc.check_and_persist(product, version)).to eq(true)
58
58
  end
59
59
  end
60
60
 
61
61
  describe "when there are no missing licenses" do
62
62
  it "returns true" do
63
- expect(env_acc).to receive(:check_no_persist).and_return(false)
64
- expect(arg_acc).to receive(:check_no_persist).and_return(false)
63
+ expect(env_acc).to receive(:no_persist?).and_return(false)
64
+ expect(arg_acc).to receive(:no_persist?).and_return(false)
65
65
  expect(reader).to receive(:read)
66
66
  expect(reader).to receive(:lookup).with(product, version).and_return(relationship)
67
- expect(file_acc).to receive(:check).with(relationship).and_return([])
67
+ expect(file_acc).to receive(:accepted?).with(relationship).and_return([])
68
68
  expect(acc.check_and_persist(product, version)).to eq(true)
69
69
  end
70
70
  end
71
71
 
72
72
  describe "when the user accepts as an environment variable" do
73
73
  it "returns true" do
74
- expect(env_acc).to receive(:check_no_persist).and_return(false)
75
- expect(arg_acc).to receive(:check_no_persist).and_return(false)
74
+ expect(env_acc).to receive(:no_persist?).and_return(false)
75
+ expect(arg_acc).to receive(:no_persist?).and_return(false)
76
76
  expect(reader).to receive(:read)
77
77
  expect(reader).to receive(:lookup).with(product, version).and_return(relationship)
78
- expect(file_acc).to receive(:check).with(relationship).and_return(missing)
79
- expect(env_acc).to receive(:check).with(ENV).and_return(true)
78
+ expect(file_acc).to receive(:accepted?).with(relationship).and_return(missing)
79
+ expect(env_acc).to receive(:accepted?).with(ENV).and_return(true)
80
+ expect(env_acc).to receive(:silent?).with(ENV).and_return(false)
81
+ expect(arg_acc).to receive(:silent?).with(ARGV).and_return(false)
80
82
  expect(file_acc).to receive(:persist).with(relationship, missing).and_return([])
81
83
  expect(acc.check_and_persist(product, version)).to eq(true)
82
84
  expect(output.string).to match(/1 product license accepted./)
@@ -86,25 +88,43 @@ RSpec.describe LicenseAcceptance::Acceptor do
86
88
  let(:opts) { { output: output, persist: false } }
87
89
 
88
90
  it "returns true" do
89
- expect(env_acc).to receive(:check_no_persist).and_return(false)
90
- expect(arg_acc).to receive(:check_no_persist).and_return(false)
91
+ expect(env_acc).to receive(:no_persist?).and_return(false)
92
+ expect(arg_acc).to receive(:no_persist?).and_return(false)
91
93
  expect(reader).to receive(:read)
92
94
  expect(reader).to receive(:lookup).with(product, version).and_return(relationship)
93
- expect(file_acc).to receive(:check).with(relationship).and_return(missing)
94
- expect(env_acc).to receive(:check).with(ENV).and_return(true)
95
+ expect(file_acc).to receive(:accepted?).with(relationship).and_return(missing)
96
+ expect(env_acc).to receive(:accepted?).with(ENV).and_return(true)
95
97
  expect(acc.check_and_persist(product, version)).to eq(true)
96
98
  expect(output.string).to_not match(/accepted./)
97
99
  end
98
100
  end
99
101
 
102
+ describe "when the silent option is used" do
103
+ let(:opts) { { output: output } }
104
+
105
+ it "returns true and silently persists the file" do
106
+ expect(env_acc).to receive(:no_persist?).and_return(false)
107
+ expect(arg_acc).to receive(:no_persist?).and_return(false)
108
+ expect(reader).to receive(:read)
109
+ expect(reader).to receive(:lookup).with(product, version).and_return(relationship)
110
+ expect(file_acc).to receive(:accepted?).with(relationship).and_return(missing)
111
+ expect(env_acc).to receive(:accepted?).with(ENV).and_return(false)
112
+ expect(arg_acc).to receive(:accepted?).with(ARGV).and_return(false)
113
+ expect(env_acc).to receive(:silent?).with(ENV).twice.and_return(true)
114
+ expect(file_acc).to receive(:persist).with(relationship, missing).and_return([])
115
+ expect(acc.check_and_persist(product, version)).to eq(true)
116
+ expect(output.string).to be_empty
117
+ end
118
+ end
119
+
100
120
  describe "when file persistance fails" do
101
121
  it "returns true" do
102
- expect(env_acc).to receive(:check_no_persist).and_return(false)
103
- expect(arg_acc).to receive(:check_no_persist).and_return(false)
122
+ expect(env_acc).to receive(:no_persist?).and_return(false)
123
+ expect(arg_acc).to receive(:no_persist?).and_return(false)
104
124
  expect(reader).to receive(:read)
105
125
  expect(reader).to receive(:lookup).with(product, version).and_return(relationship)
106
- expect(file_acc).to receive(:check).with(relationship).and_return(missing)
107
- expect(env_acc).to receive(:check).with(ENV).and_return(true)
126
+ expect(file_acc).to receive(:accepted?).with(relationship).and_return(missing)
127
+ expect(env_acc).to receive(:accepted?).with(ENV).and_return(true)
108
128
  expect(file_acc).to receive(:persist).with(relationship, missing).and_return([StandardError.new("foo")])
109
129
  expect(acc.check_and_persist(product, version)).to eq(true)
110
130
  expect(output.string).to match(/Could not persist acceptance:/)
@@ -114,29 +134,51 @@ RSpec.describe LicenseAcceptance::Acceptor do
114
134
 
115
135
  describe "when the user accepts as an arg" do
116
136
  it "returns true" do
117
- expect(env_acc).to receive(:check_no_persist).and_return(false)
118
- expect(arg_acc).to receive(:check_no_persist).and_return(false)
137
+ expect(env_acc).to receive(:no_persist?).and_return(false)
138
+ expect(arg_acc).to receive(:no_persist?).and_return(false)
119
139
  expect(reader).to receive(:read)
120
140
  expect(reader).to receive(:lookup).with(product, version).and_return(relationship)
121
- expect(file_acc).to receive(:check).with(relationship).and_return(missing)
122
- expect(env_acc).to receive(:check).and_return(false)
123
- expect(arg_acc).to receive(:check).with(ARGV).and_return(true)
141
+ expect(file_acc).to receive(:accepted?).with(relationship).and_return(missing)
142
+ expect(env_acc).to receive(:accepted?).and_return(false)
143
+ expect(arg_acc).to receive(:accepted?).with(ARGV).and_return(true)
144
+ expect(env_acc).to receive(:silent?).with(ENV).and_return(false)
145
+ expect(arg_acc).to receive(:silent?).with(ARGV).and_return(false)
124
146
  expect(file_acc).to receive(:persist).with(relationship, missing).and_return([])
125
147
  expect(acc.check_and_persist(product, version)).to eq(true)
126
148
  expect(output.string).to match(/1 product license accepted./)
127
149
  end
128
150
 
151
+ describe "when the silent option is used" do
152
+ let(:opts) { { output: output } }
153
+
154
+ it "returns true and silently persists the file" do
155
+ expect(env_acc).to receive(:no_persist?).and_return(false)
156
+ expect(arg_acc).to receive(:no_persist?).and_return(false)
157
+ expect(reader).to receive(:read)
158
+ expect(reader).to receive(:lookup).with(product, version).and_return(relationship)
159
+ expect(file_acc).to receive(:accepted?).with(relationship).and_return(missing)
160
+ expect(env_acc).to receive(:accepted?).and_return(false)
161
+ expect(arg_acc).to receive(:accepted?).with(ARGV).and_return(false)
162
+ expect(env_acc).to receive(:silent?).with(ENV).twice.and_return(false)
163
+ expect(arg_acc).to receive(:silent?).with(ARGV).twice.and_return(true)
164
+ expect(file_acc).to receive(:persist).with(relationship, missing).and_return([])
165
+ expect(acc.check_and_persist(product, version)).to eq(true)
166
+ expect(output.string).to be_empty
167
+ end
168
+ end
169
+
170
+
129
171
  describe "when persist is set to false" do
130
172
  let(:opts) { { output: output, persist: false } }
131
173
 
132
174
  it "returns true" do
133
- expect(env_acc).to receive(:check_no_persist).and_return(false)
134
- expect(arg_acc).to receive(:check_no_persist).and_return(false)
175
+ expect(env_acc).to receive(:no_persist?).and_return(false)
176
+ expect(arg_acc).to receive(:no_persist?).and_return(false)
135
177
  expect(reader).to receive(:read)
136
178
  expect(reader).to receive(:lookup).with(product, version).and_return(relationship)
137
- expect(file_acc).to receive(:check).with(relationship).and_return(missing)
138
- expect(env_acc).to receive(:check).and_return(false)
139
- expect(arg_acc).to receive(:check).with(ARGV).and_return(true)
179
+ expect(file_acc).to receive(:accepted?).with(relationship).and_return(missing)
180
+ expect(env_acc).to receive(:accepted?).and_return(false)
181
+ expect(arg_acc).to receive(:accepted?).with(ARGV).and_return(true)
140
182
  expect(acc.check_and_persist(product, version)).to eq(true)
141
183
  expect(output.string).to_not match(/accepted./)
142
184
  end
@@ -144,13 +186,13 @@ RSpec.describe LicenseAcceptance::Acceptor do
144
186
 
145
187
  describe "when file persistance fails" do
146
188
  it "returns true" do
147
- expect(env_acc).to receive(:check_no_persist).and_return(false)
148
- expect(arg_acc).to receive(:check_no_persist).and_return(false)
189
+ expect(env_acc).to receive(:no_persist?).and_return(false)
190
+ expect(arg_acc).to receive(:no_persist?).and_return(false)
149
191
  expect(reader).to receive(:read)
150
192
  expect(reader).to receive(:lookup).with(product, version).and_return(relationship)
151
- expect(file_acc).to receive(:check).with(relationship).and_return(missing)
152
- expect(env_acc).to receive(:check).and_return(false)
153
- expect(arg_acc).to receive(:check).with(ARGV).and_return(true)
193
+ expect(file_acc).to receive(:accepted?).with(relationship).and_return(missing)
194
+ expect(env_acc).to receive(:accepted?).and_return(false)
195
+ expect(arg_acc).to receive(:accepted?).with(ARGV).and_return(true)
154
196
  expect(file_acc).to receive(:persist).with(relationship, missing).and_return([StandardError.new("bar")])
155
197
  expect(acc.check_and_persist(product, version)).to eq(true)
156
198
  expect(output.string).to match(/Could not persist acceptance:/)
@@ -161,13 +203,15 @@ RSpec.describe LicenseAcceptance::Acceptor do
161
203
  describe "when the prompt is not a tty" do
162
204
  let(:opts) { { output: File.open(File::NULL, "w") } }
163
205
  it "raises a LicenseNotAcceptedError error" do
164
- expect(env_acc).to receive(:check_no_persist).and_return(false)
165
- expect(arg_acc).to receive(:check_no_persist).and_return(false)
206
+ expect(env_acc).to receive(:no_persist?).and_return(false)
207
+ expect(arg_acc).to receive(:no_persist?).and_return(false)
166
208
  expect(reader).to receive(:read)
167
209
  expect(reader).to receive(:lookup).with(product, version).and_return(relationship)
168
- expect(file_acc).to receive(:check).with(relationship).and_return(missing)
169
- expect(env_acc).to receive(:check).and_return(false)
170
- expect(arg_acc).to receive(:check).and_return(false)
210
+ expect(file_acc).to receive(:accepted?).with(relationship).and_return(missing)
211
+ expect(env_acc).to receive(:accepted?).and_return(false)
212
+ expect(arg_acc).to receive(:accepted?).and_return(false)
213
+ expect(env_acc).to receive(:silent?).and_return(false)
214
+ expect(arg_acc).to receive(:silent?).and_return(false)
171
215
  expect(prompt_acc).to_not receive(:request)
172
216
  expect { acc.check_and_persist(product, version) }.to raise_error(LicenseAcceptance::LicenseNotAcceptedError)
173
217
  end
@@ -175,13 +219,15 @@ RSpec.describe LicenseAcceptance::Acceptor do
175
219
 
176
220
  describe "when the user accepts with the prompt" do
177
221
  it "returns true" do
178
- expect(env_acc).to receive(:check_no_persist).and_return(false)
179
- expect(arg_acc).to receive(:check_no_persist).and_return(false)
222
+ expect(env_acc).to receive(:no_persist?).and_return(false)
223
+ expect(arg_acc).to receive(:no_persist?).and_return(false)
180
224
  expect(reader).to receive(:read)
181
225
  expect(reader).to receive(:lookup).with(product, version).and_return(relationship)
182
- expect(file_acc).to receive(:check).with(relationship).and_return(missing)
183
- expect(env_acc).to receive(:check).and_return(false)
184
- expect(arg_acc).to receive(:check).and_return(false)
226
+ expect(file_acc).to receive(:accepted?).with(relationship).and_return(missing)
227
+ expect(env_acc).to receive(:accepted?).and_return(false)
228
+ expect(arg_acc).to receive(:accepted?).and_return(false)
229
+ expect(env_acc).to receive(:silent?).and_return(false)
230
+ expect(arg_acc).to receive(:silent?).and_return(false)
185
231
  expect(prompt_acc).to receive(:request).with(missing).and_yield.and_return(true)
186
232
  expect(file_acc).to receive(:persist).with(relationship, missing)
187
233
  expect(acc.check_and_persist(product, version)).to eq(true)
@@ -191,13 +237,15 @@ RSpec.describe LicenseAcceptance::Acceptor do
191
237
  let(:opts) { { output: output, persist: false } }
192
238
 
193
239
  it "returns true" do
194
- expect(env_acc).to receive(:check_no_persist).and_return(false)
195
- expect(arg_acc).to receive(:check_no_persist).and_return(false)
240
+ expect(env_acc).to receive(:no_persist?).and_return(false)
241
+ expect(arg_acc).to receive(:no_persist?).and_return(false)
196
242
  expect(reader).to receive(:read)
197
243
  expect(reader).to receive(:lookup).with(product, version).and_return(relationship)
198
- expect(file_acc).to receive(:check).with(relationship).and_return(missing)
199
- expect(env_acc).to receive(:check).and_return(false)
200
- expect(arg_acc).to receive(:check).and_return(false)
244
+ expect(file_acc).to receive(:accepted?).with(relationship).and_return(missing)
245
+ expect(env_acc).to receive(:accepted?).and_return(false)
246
+ expect(arg_acc).to receive(:accepted?).and_return(false)
247
+ expect(env_acc).to receive(:silent?).and_return(false)
248
+ expect(arg_acc).to receive(:silent?).and_return(false)
201
249
  expect(prompt_acc).to receive(:request).with(missing).and_yield.and_return(true)
202
250
  expect(acc.check_and_persist(product, version)).to eq(true)
203
251
  end
@@ -206,13 +254,15 @@ RSpec.describe LicenseAcceptance::Acceptor do
206
254
 
207
255
  describe "when the user declines with the prompt" do
208
256
  it "raises a LicenseNotAcceptedError error" do
209
- expect(env_acc).to receive(:check_no_persist).and_return(false)
210
- expect(arg_acc).to receive(:check_no_persist).and_return(false)
257
+ expect(env_acc).to receive(:no_persist?).and_return(false)
258
+ expect(arg_acc).to receive(:no_persist?).and_return(false)
211
259
  expect(reader).to receive(:read)
212
260
  expect(reader).to receive(:lookup).with(product, version).and_return(relationship)
213
- expect(file_acc).to receive(:check).with(relationship).and_return(missing)
214
- expect(env_acc).to receive(:check).and_return(false)
215
- expect(arg_acc).to receive(:check).and_return(false)
261
+ expect(file_acc).to receive(:accepted?).with(relationship).and_return(missing)
262
+ expect(env_acc).to receive(:accepted?).and_return(false)
263
+ expect(arg_acc).to receive(:accepted?).and_return(false)
264
+ expect(env_acc).to receive(:silent?).and_return(false)
265
+ expect(arg_acc).to receive(:silent?).and_return(false)
216
266
  expect(prompt_acc).to receive(:request).with(missing).and_return(false)
217
267
  expect { acc.check_and_persist(product, version) }.to raise_error(LicenseAcceptance::LicenseNotAcceptedError)
218
268
  end
@@ -4,33 +4,53 @@ require "license_acceptance/arg_acceptance"
4
4
  RSpec.describe LicenseAcceptance::ArgAcceptance do
5
5
  let(:acc) { LicenseAcceptance::ArgAcceptance.new }
6
6
 
7
- describe "#check" do
8
- it "returns true if the args contain the required flag with spaces" do
9
- expect(acc.check(["--chef-license", "accept"])).to eq(true)
7
+ describe "with an accept option" do
8
+ describe "#accepted?" do
9
+ it "returns true if the args contain the required flag with spaces" do
10
+ expect(acc.accepted?(["--chef-license", "accept"])).to eq(true)
11
+ end
12
+
13
+ it "returns true if the args contain the required flag with equal" do
14
+ expect(acc.accepted?(["--chef-license=accept"])).to eq(true)
15
+ end
16
+
17
+ it "returns false if the args do not contain the required value" do
18
+ expect(acc.accepted?(["--chef-license"])).to eq(false)
19
+ expect(acc.accepted?(["--chef-license=foo"])).to eq(false)
20
+ expect(acc.accepted?(["--chef-license", "foo"])).to eq(false)
21
+ end
10
22
  end
11
23
 
12
- it "returns true if the args contain the required flag with equal" do
13
- expect(acc.check(["--chef-license=accept"])).to eq(true)
14
- end
24
+ describe "#silent?" do
25
+ it "returns true if the args contain the required flag with spaces" do
26
+ expect(acc.silent?(["--chef-license", "accept-silent"])).to eq(true)
27
+ end
15
28
 
16
- it "returns false if the args do not contain the required value" do
17
- expect(acc.check(["--chef-license"])).to eq(false)
29
+ it "returns true if the args contain the required flag with equal" do
30
+ expect(acc.silent?(["--chef-license=accept-silent"])).to eq(true)
31
+ end
32
+
33
+ it "returns false if the args do not contain the required value" do
34
+ expect(acc.silent?(["--chef-license"])).to eq(false)
35
+ expect(acc.silent?(["--chef-license=accept"])).to eq(false)
36
+ expect(acc.silent?(["--chef-license", "accept"])).to eq(false)
37
+ end
18
38
  end
19
39
  end
20
40
 
21
- describe "#check_no_persist" do
41
+ describe "#no_persist?" do
22
42
  it "returns true if the args contain the required flag with spaces" do
23
- expect(acc.check_no_persist(["--chef-license", "accept-no-persist"])).to eq(true)
43
+ expect(acc.no_persist?(["--chef-license", "accept-no-persist"])).to eq(true)
24
44
  end
25
45
 
26
46
  it "returns true if the args contain the required flag with equal" do
27
- expect(acc.check_no_persist(["--chef-license=accept-no-persist"])).to eq(true)
47
+ expect(acc.no_persist?(["--chef-license=accept-no-persist"])).to eq(true)
28
48
  end
29
49
 
30
50
  it "returns false if the args do not contain the required value" do
31
- expect(acc.check_no_persist(["--chef-license"])).to eq(false)
32
- expect(acc.check_no_persist(["--chef-license=accept"])).to eq(false)
33
- expect(acc.check_no_persist(["--chef-license","accept"])).to eq(false)
51
+ expect(acc.no_persist?(["--chef-license"])).to eq(false)
52
+ expect(acc.no_persist?(["--chef-license=accept"])).to eq(false)
53
+ expect(acc.no_persist?(["--chef-license", "accept"])).to eq(false)
34
54
  end
35
55
  end
36
56
 
@@ -4,39 +4,61 @@ require "license_acceptance/env_acceptance"
4
4
  RSpec.describe LicenseAcceptance::EnvAcceptance do
5
5
  let(:acc) { LicenseAcceptance::EnvAcceptance.new }
6
6
 
7
- describe "#check" do
8
- it "returns true if the env contains the correct key and value" do
9
- env = {"CHEF_LICENSE" => "accept"}
10
- expect(acc.check(env)).to eq(true)
11
- end
7
+ describe "when passed an accept value" do
8
+ describe "#accepted?" do
9
+ it "returns true if the env contains the correct key and value" do
10
+ env = {"CHEF_LICENSE" => "accept"}
11
+ expect(acc.accepted?(env)).to eq(true)
12
+ end
12
13
 
13
- it "returns false if the env has a key but nil value" do
14
- env = {"CHEF_LICENSE" => nil}
15
- expect(acc.check(env)).to eq(false)
14
+ it "returns false if the env has a key but nil value" do
15
+ env = {"CHEF_LICENSE" => nil}
16
+ expect(acc.accepted?(env)).to eq(false)
17
+ end
18
+
19
+ it "returns false if the env has a key but incorrect value" do
20
+ env = {"CHEF_LICENSE" => "foo"}
21
+ expect(acc.accepted?(env)).to eq(false)
22
+ end
16
23
  end
17
24
 
18
- it "returns false if the env has a key but incorrect value" do
19
- env = {"CHEF_LICENSE" => "foo"}
20
- expect(acc.check(env)).to eq(false)
25
+ describe "#silent?" do
26
+ it "returns true if the env contains the correct key and value" do
27
+ env = {"CHEF_LICENSE" => "accept-silent"}
28
+ expect(acc.silent?(env)).to eq(true)
29
+ end
30
+
31
+ it "returns false if the env has a key but nil value" do
32
+ env = {"CHEF_LICENSE" => nil}
33
+ expect(acc.silent?(env)).to eq(false)
34
+ end
35
+
36
+ it "returns false if the env has a key but incorrect value" do
37
+ env = {"CHEF_LICENSE" => "foo"}
38
+ expect(acc.silent?(env)).to eq(false)
39
+ env = {"CHEF_LICENSE" => "accept"}
40
+ expect(acc.silent?(env)).to eq(false)
41
+ end
21
42
  end
43
+
22
44
  end
23
45
 
24
- describe "#check_no_persist" do
46
+ describe "#no_persist?" do
25
47
  it "returns true if the env contains the correct key and value" do
26
48
  env = {"CHEF_LICENSE" => "accept-no-persist"}
27
- expect(acc.check_no_persist(env)).to eq(true)
49
+ expect(acc.no_persist?(env)).to eq(true)
28
50
  end
29
51
 
30
52
  it "returns false if the env has a key but nil value" do
31
53
  env = {"CHEF_LICENSE" => nil}
32
- expect(acc.check_no_persist(env)).to eq(false)
54
+ expect(acc.no_persist?(env)).to eq(false)
33
55
  end
34
56
 
35
57
  it "returns false if the env has a key but incorrect value" do
36
58
  env = {"CHEF_LICENSE" => "foo"}
37
- expect(acc.check_no_persist(env)).to eq(false)
59
+ expect(acc.no_persist?(env)).to eq(false)
38
60
  env = {"CHEF_LICENSE" => "accept"}
39
- expect(acc.check_no_persist(env)).to eq(false)
61
+ expect(acc.no_persist?(env)).to eq(false)
40
62
  end
41
63
  end
42
64
 
@@ -23,7 +23,7 @@ RSpec.describe LicenseAcceptance::FileAcceptance do
23
23
  describe "when there is an existing license file" do
24
24
  it "returns an empty missing product list" do
25
25
  expect(File).to receive(:exist?).with(File.join(dir1, p1_filename)).and_return(true)
26
- expect(acc.check(product_relationship)).to eq([])
26
+ expect(acc.accepted?(product_relationship)).to eq([])
27
27
  end
28
28
  end
29
29
 
@@ -31,7 +31,7 @@ RSpec.describe LicenseAcceptance::FileAcceptance do
31
31
  it "returns the product in the missing product list" do
32
32
  expect(File).to receive(:exist?).with(File.join(dir1, p1_filename)).and_return(false)
33
33
  expect(File).to receive(:exist?).with(File.join(dir2, p1_filename)).and_return(false)
34
- expect(acc.check(product_relationship)).to eq([p1])
34
+ expect(acc.accepted?(product_relationship)).to eq([p1])
35
35
  end
36
36
  end
37
37
 
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: 0.2.6
4
+ version: 0.2.8
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-04-11 00:00:00.000000000 Z
11
+ date: 2019-04-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pastel