license-acceptance 0.0.1 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (37) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +2 -0
  3. data/Gemfile.lock +97 -0
  4. data/config/product_info.toml +1 -0
  5. data/lib/license_acceptance/acceptor.rb +117 -0
  6. data/lib/license_acceptance/arg_acceptance.rb +33 -0
  7. data/lib/license_acceptance/cli_flags/mixlib_cli.rb +22 -0
  8. data/lib/license_acceptance/cli_flags/thor.rb +21 -0
  9. data/lib/license_acceptance/config.rb +65 -0
  10. data/lib/license_acceptance/env_acceptance.rb +19 -0
  11. data/lib/license_acceptance/file_acceptance.rb +97 -0
  12. data/lib/license_acceptance/logger.rb +19 -0
  13. data/lib/license_acceptance/product.rb +23 -0
  14. data/lib/license_acceptance/product_reader.rb +108 -0
  15. data/lib/license_acceptance/product_relationship.rb +13 -0
  16. data/lib/license_acceptance/prompt_acceptance.rb +104 -0
  17. data/lib/license_acceptance/version.rb +3 -0
  18. data/spec/license_acceptance/acceptor_spec.rb +222 -0
  19. data/spec/license_acceptance/arg_acceptance_spec.rb +37 -0
  20. data/spec/license_acceptance/cli_flags/mixlib_cli_spec.rb +14 -0
  21. data/spec/license_acceptance/cli_flags/thor_spec.rb +14 -0
  22. data/spec/license_acceptance/config_spec.rb +113 -0
  23. data/spec/license_acceptance/env_acceptance_spec.rb +43 -0
  24. data/spec/license_acceptance/file_acceptance_spec.rb +121 -0
  25. data/spec/license_acceptance/product_reader_spec.rb +139 -0
  26. data/spec/license_acceptance/product_spec.rb +13 -0
  27. data/spec/license_acceptance/prompt_acceptance_spec.rb +100 -0
  28. data/spec/spec_helper.rb +25 -0
  29. metadata +184 -22
  30. data/.gitignore +0 -11
  31. data/.rspec +0 -3
  32. data/.travis.yml +0 -7
  33. data/LICENSE +0 -1
  34. data/README.md +0 -35
  35. data/lib/license/acceptance/version.rb +0 -5
  36. data/lib/license/acceptance.rb +0 -8
  37. data/license-acceptance.gemspec +0 -42
@@ -0,0 +1,13 @@
1
+ require "spec_helper"
2
+ require "license_acceptance/product"
3
+
4
+ RSpec.describe LicenseAcceptance::Product do
5
+ let(:instance) { LicenseAcceptance::Product.new("name", "Pretty Name", "filename") }
6
+
7
+ it "can lookup the product attributes" do
8
+ expect(instance.name).to eq("name")
9
+ expect(instance.pretty_name).to eq("Pretty Name")
10
+ expect(instance.filename).to eq("filename")
11
+ end
12
+
13
+ end
@@ -0,0 +1,100 @@
1
+ require "spec_helper"
2
+ require "license_acceptance/prompt_acceptance"
3
+ require "license_acceptance/product"
4
+ require "tty-prompt"
5
+
6
+ RSpec.describe LicenseAcceptance::PromptAcceptance do
7
+ let(:output) { StringIO.new }
8
+ let(:config) do
9
+ instance_double(LicenseAcceptance::Config, output: output)
10
+ end
11
+ let(:acc) { LicenseAcceptance::PromptAcceptance.new(config) }
12
+ let(:prompt) { instance_double(TTY::Prompt) }
13
+ let(:p1) { instance_double(LicenseAcceptance::Product, name: "name", 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, name: "other_name", 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::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
@@ -0,0 +1,25 @@
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
metadata CHANGED
@@ -1,29 +1,85 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: license-acceptance
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - tyler-ball
8
8
  autorequire:
9
- bindir: exe
9
+ bindir: bin
10
10
  cert_chain: []
11
- date: 2019-03-01 00:00:00.000000000 Z
11
+ date: 2019-04-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: bundler
14
+ name: pastel
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '2.0'
20
- type: :development
19
+ version: '0.7'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: tomlrb
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.2'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.2'
41
+ - !ruby/object:Gem::Dependency
42
+ name: tty-box
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0.3'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '0.3'
55
+ - !ruby/object:Gem::Dependency
56
+ name: tty-platform
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0.2'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0.2'
69
+ - !ruby/object:Gem::Dependency
70
+ name: tty-prompt
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0.18'
76
+ type: :runtime
21
77
  prerelease: false
22
78
  version_requirements: !ruby/object:Gem::Requirement
23
79
  requirements:
24
80
  - - "~>"
25
81
  - !ruby/object:Gem::Version
26
- version: '2.0'
82
+ version: '0.18'
27
83
  - !ruby/object:Gem::Dependency
28
84
  name: rake
29
85
  requirement: !ruby/object:Gem::Requirement
@@ -52,27 +108,133 @@ dependencies:
52
108
  - - "~>"
53
109
  - !ruby/object:Gem::Version
54
110
  version: '3.0'
55
- description: License stuff
111
+ - !ruby/object:Gem::Dependency
112
+ name: pry
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '0.12'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '0.12'
125
+ - !ruby/object:Gem::Dependency
126
+ name: pry-byebug
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: '3.6'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: '3.6'
139
+ - !ruby/object:Gem::Dependency
140
+ name: pry-stack_explorer
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - "~>"
144
+ - !ruby/object:Gem::Version
145
+ version: '0.4'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - "~>"
151
+ - !ruby/object:Gem::Version
152
+ version: '0.4'
153
+ - !ruby/object:Gem::Dependency
154
+ name: mixlib-cli
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - "~>"
158
+ - !ruby/object:Gem::Version
159
+ version: '1.7'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - "~>"
165
+ - !ruby/object:Gem::Version
166
+ version: '1.7'
167
+ - !ruby/object:Gem::Dependency
168
+ name: thor
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - "~>"
172
+ - !ruby/object:Gem::Version
173
+ version: '0.20'
174
+ type: :development
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - "~>"
179
+ - !ruby/object:Gem::Version
180
+ version: '0.20'
181
+ - !ruby/object:Gem::Dependency
182
+ name: climate_control
183
+ requirement: !ruby/object:Gem::Requirement
184
+ requirements:
185
+ - - "~>"
186
+ - !ruby/object:Gem::Version
187
+ version: '0.2'
188
+ type: :development
189
+ prerelease: false
190
+ version_requirements: !ruby/object:Gem::Requirement
191
+ requirements:
192
+ - - "~>"
193
+ - !ruby/object:Gem::Version
194
+ version: '0.2'
195
+ description: Chef End User License Agreement Acceptance for Ruby products
56
196
  email:
57
- - tyleraball@gmail.com
197
+ - tball@chef.io
58
198
  executables: []
59
199
  extensions: []
60
200
  extra_rdoc_files: []
61
201
  files:
62
- - ".gitignore"
63
- - ".rspec"
64
- - ".travis.yml"
65
202
  - Gemfile
66
- - LICENSE
67
- - README.md
203
+ - Gemfile.lock
68
204
  - Rakefile
69
- - lib/license/acceptance.rb
70
- - lib/license/acceptance/version.rb
71
- - license-acceptance.gemspec
72
- homepage: https://github.com/tyler-ball
205
+ - config/product_info.toml
206
+ - lib/license_acceptance/acceptor.rb
207
+ - lib/license_acceptance/arg_acceptance.rb
208
+ - lib/license_acceptance/cli_flags/mixlib_cli.rb
209
+ - lib/license_acceptance/cli_flags/thor.rb
210
+ - lib/license_acceptance/config.rb
211
+ - lib/license_acceptance/env_acceptance.rb
212
+ - lib/license_acceptance/file_acceptance.rb
213
+ - lib/license_acceptance/logger.rb
214
+ - lib/license_acceptance/product.rb
215
+ - lib/license_acceptance/product_reader.rb
216
+ - lib/license_acceptance/product_relationship.rb
217
+ - lib/license_acceptance/prompt_acceptance.rb
218
+ - lib/license_acceptance/version.rb
219
+ - spec/license_acceptance/acceptor_spec.rb
220
+ - spec/license_acceptance/arg_acceptance_spec.rb
221
+ - spec/license_acceptance/cli_flags/mixlib_cli_spec.rb
222
+ - spec/license_acceptance/cli_flags/thor_spec.rb
223
+ - spec/license_acceptance/config_spec.rb
224
+ - spec/license_acceptance/env_acceptance_spec.rb
225
+ - spec/license_acceptance/file_acceptance_spec.rb
226
+ - spec/license_acceptance/product_reader_spec.rb
227
+ - spec/license_acceptance/product_spec.rb
228
+ - spec/license_acceptance/prompt_acceptance_spec.rb
229
+ - spec/spec_helper.rb
230
+ homepage: https://chef.io
73
231
  licenses:
74
- - Nonstandard
75
- metadata: {}
232
+ - Apache-2.0
233
+ metadata:
234
+ allowed_push_host: https://rubygems.org
235
+ homepage_uri: https://chef.io
236
+ source_code_uri: https://github.com/chef/license-acceptance
237
+ changelog_uri: https://github.com/chef/license-acceptance/blob/master/CHANGELOG.md
76
238
  post_install_message:
77
239
  rdoc_options: []
78
240
  require_paths:
@@ -88,8 +250,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
88
250
  - !ruby/object:Gem::Version
89
251
  version: '0'
90
252
  requirements: []
91
- rubygems_version: 3.0.2
253
+ rubygems_version: 3.0.3
92
254
  signing_key:
93
255
  specification_version: 4
94
- summary: I don't know how to spell license apparently
256
+ summary: Chef End User License Agreement Acceptance
95
257
  test_files: []
data/.gitignore DELETED
@@ -1,11 +0,0 @@
1
- /.bundle/
2
- /.yardoc
3
- /_yardoc/
4
- /coverage/
5
- /doc/
6
- /pkg/
7
- /spec/reports/
8
- /tmp/
9
-
10
- # rspec failure tracking
11
- .rspec_status
data/.rspec DELETED
@@ -1,3 +0,0 @@
1
- --format documentation
2
- --color
3
- --require spec_helper
data/.travis.yml DELETED
@@ -1,7 +0,0 @@
1
- ---
2
- sudo: false
3
- language: ruby
4
- cache: bundler
5
- rvm:
6
- - 2.6.0
7
- before_install: gem install bundler -v 2.0.1
data/LICENSE DELETED
@@ -1 +0,0 @@
1
- All rights reserved
data/README.md DELETED
@@ -1,35 +0,0 @@
1
- # License::Acceptance
2
-
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/license/acceptance`. To experiment with that code, run `bin/console` for an interactive prompt.
4
-
5
- TODO: Delete this and the text above, and describe your gem
6
-
7
- ## Installation
8
-
9
- Add this line to your application's Gemfile:
10
-
11
- ```ruby
12
- gem 'license-acceptance'
13
- ```
14
-
15
- And then execute:
16
-
17
- $ bundle
18
-
19
- Or install it yourself as:
20
-
21
- $ gem install license-acceptance
22
-
23
- ## Usage
24
-
25
- TODO: Write usage instructions here
26
-
27
- ## Development
28
-
29
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
-
31
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
-
33
- ## Contributing
34
-
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/license-acceptance.