chef-cleanroom 1.0.4 → 1.0.5
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 +4 -4
- data/.expeditor/buildkite/verify.ps1 +17 -0
- data/.expeditor/buildkite/verify.sh +12 -0
- data/.expeditor/config.yml +46 -0
- data/.expeditor/update_version.sh +12 -0
- data/.expeditor/verify.pipeline.yml +52 -0
- data/.rspec +4 -0
- data/.rubocop.yml +5 -0
- data/Gemfile +1 -1
- data/Rakefile +15 -10
- data/VERSION +1 -0
- data/chef-cleanroom.gemspec +15 -15
- data/lib/cleanroom/errors.rb +2 -2
- data/lib/cleanroom/rspec.rb +2 -2
- data/lib/cleanroom/version.rb +1 -1
- data/lib/cleanroom.rb +6 -5
- data/spec/functional/cleanroom_spec.rb +16 -16
- data/spec/spec_helper.rb +5 -6
- data/spec/unit/cleanroom_spec.rb +43 -41
- data/spec/unit/rspec_spec.rb +21 -21
- metadata +28 -7
- data/.travis.yml +0 -12
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e42a72a1052b8b5ccc5f43b721182480ca7f2c3ba3a101b2374cfbc736955922
|
4
|
+
data.tar.gz: fbd9245605d08efe5c31a5cc857835f9906dfa73bb869630a520b125b223f0cb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 61caf5f3663b6787fd5e66682b4c7fbb1133d5f1bba091449bfe295045184669327f053431d10759c0ce5e44048aedd3e60bd17bd1f8dd0eef89673d1b2dfbb2
|
7
|
+
data.tar.gz: ddc69a1d4aaf3567d9ce6963003980ad11485d703f60bb271f5d73f640f2788607e68ae5096e47c365268753855750b5ce81ad4e28c39f04f1fb532b9cf18a7e
|
@@ -0,0 +1,17 @@
|
|
1
|
+
Write-Output "--- system details"
|
2
|
+
$Properties = 'Caption', 'CSName', 'Version', 'BuildType', 'OSArchitecture'
|
3
|
+
Get-CimInstance Win32_OperatingSystem | Select-Object $Properties | Format-Table -AutoSize
|
4
|
+
|
5
|
+
ruby -v
|
6
|
+
If ($lastexitcode -ne 0) { Throw $lastexitcode }
|
7
|
+
|
8
|
+
bundle --version
|
9
|
+
If ($lastexitcode -ne 0) { Throw $lastexitcode }
|
10
|
+
|
11
|
+
Write-Output "--- bundle install"
|
12
|
+
bundle install
|
13
|
+
If ($lastexitcode -ne 0) { Throw $lastexitcode }
|
14
|
+
|
15
|
+
Write-Output "+++ bundle exec rake"
|
16
|
+
bundle exec rake unit functional
|
17
|
+
If ($lastexitcode -ne 0) { Throw $lastexitcode }
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# Documentation available at https://expeditor.chef.io/docs/getting-started/
|
2
|
+
---
|
3
|
+
|
4
|
+
project:
|
5
|
+
alias: chef-cleanroom
|
6
|
+
|
7
|
+
# Slack channel in Chef Software slack to send notifications about build failures, etc
|
8
|
+
slack:
|
9
|
+
notify_channel: releng-notify
|
10
|
+
|
11
|
+
# This publish is triggered by the `built_in:publish_rubygems` artifact_action.
|
12
|
+
rubygems:
|
13
|
+
- chef-cleanroom
|
14
|
+
|
15
|
+
github:
|
16
|
+
# This deletes the GitHub PR branch after successfully merged into the release branch
|
17
|
+
delete_branch_on_merge: true
|
18
|
+
# The tag format to use (e.g. v1.0.0)
|
19
|
+
version_tag_format: "v{{version}}"
|
20
|
+
# allow bumping the minor release via label
|
21
|
+
minor_bump_labels:
|
22
|
+
- "Expeditor: Bump Version Minor"
|
23
|
+
# allow bumping the major release via label
|
24
|
+
major_bump_labels:
|
25
|
+
- "Expeditor: Bump Version Major"
|
26
|
+
|
27
|
+
subscriptions:
|
28
|
+
# These actions are taken, in order they are specified, anytime a Pull Request is merged.
|
29
|
+
- workload: pull_request_merged:{{github_repo}}:{{release_branch}}:*
|
30
|
+
actions:
|
31
|
+
- built_in:bump_version:
|
32
|
+
ignore_labels:
|
33
|
+
- "Expeditor: Skip Version Bump"
|
34
|
+
- "Expeditor: Skip All"
|
35
|
+
- bash:.expeditor/update_version.sh:
|
36
|
+
only_if: built_in:bump_version
|
37
|
+
- built_in:build_gem:
|
38
|
+
only_if: built_in:bump_version
|
39
|
+
|
40
|
+
- workload: project_promoted:{{agent_id}}:*
|
41
|
+
actions:
|
42
|
+
- built_in:publish_rubygems
|
43
|
+
|
44
|
+
pipelines:
|
45
|
+
- verify:
|
46
|
+
description: Pull Request validation tests
|
@@ -0,0 +1,12 @@
|
|
1
|
+
#!/bin/sh
|
2
|
+
#
|
3
|
+
# After a PR merge, Chef Expeditor will bump the PATCH version in the VERSION file.
|
4
|
+
# It then executes this file to update any other files/components with that new version.
|
5
|
+
#
|
6
|
+
|
7
|
+
set -evx
|
8
|
+
|
9
|
+
sed -i -r "s/^(\s*)VERSION = \".+\"/\1VERSION = \"$(cat VERSION)\"/" lib/cleanroom/version.rb
|
10
|
+
|
11
|
+
# Once Expeditor finishes executing this script, it will commit the changes and push
|
12
|
+
# the commit as a new tag corresponding to the value in the VERSION file.
|
@@ -0,0 +1,52 @@
|
|
1
|
+
---
|
2
|
+
expeditor:
|
3
|
+
defaults:
|
4
|
+
buildkite:
|
5
|
+
retry:
|
6
|
+
automatic:
|
7
|
+
limit: 1
|
8
|
+
timeout_in_minutes: 30
|
9
|
+
|
10
|
+
steps:
|
11
|
+
|
12
|
+
- label: run-lint-and-specs-ruby-2.7
|
13
|
+
command:
|
14
|
+
- .expeditor/buildkite/verify.sh
|
15
|
+
expeditor:
|
16
|
+
cached_folders:
|
17
|
+
- vendor
|
18
|
+
executor:
|
19
|
+
docker:
|
20
|
+
image: ruby:2.7-buster
|
21
|
+
|
22
|
+
- label: run-lint-and-specs-ruby-3.0
|
23
|
+
command:
|
24
|
+
- .expeditor/buildkite/verify.sh
|
25
|
+
expeditor:
|
26
|
+
cached_folders:
|
27
|
+
- vendor
|
28
|
+
executor:
|
29
|
+
docker:
|
30
|
+
image: ruby:3.0-buster
|
31
|
+
|
32
|
+
- label: run-lint-and-specs-ruby-3.1
|
33
|
+
command:
|
34
|
+
- .expeditor/buildkite/verify.sh
|
35
|
+
expeditor:
|
36
|
+
cached_folders:
|
37
|
+
- vendor
|
38
|
+
executor:
|
39
|
+
docker:
|
40
|
+
image: ruby:3.1-buster
|
41
|
+
|
42
|
+
- label: ":windows: :ruby:"
|
43
|
+
command:
|
44
|
+
- /workdir/.expeditor/buildkite/verify.ps1
|
45
|
+
expeditor:
|
46
|
+
cached_folders:
|
47
|
+
- vendor
|
48
|
+
executor:
|
49
|
+
docker:
|
50
|
+
host_os: windows
|
51
|
+
image: rubydistros/windows-2019:3.1
|
52
|
+
shell: ["powershell", "-Command"]
|
data/.rspec
ADDED
data/.rubocop.yml
ADDED
data/Gemfile
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
source
|
1
|
+
source "https://rubygems.org"
|
2
2
|
gemspec
|
data/Rakefile
CHANGED
@@ -1,19 +1,24 @@
|
|
1
|
-
require
|
1
|
+
require "bundler/gem_tasks"
|
2
2
|
|
3
|
-
require
|
4
|
-
|
3
|
+
require "rspec/core/rake_task"
|
4
|
+
%i{unit functional}.each do |type|
|
5
5
|
RSpec::Core::RakeTask.new(type) do |t|
|
6
6
|
t.pattern = "spec/#{type}/**/*_spec.rb"
|
7
7
|
t.rspec_opts = [].tap do |a|
|
8
|
-
a.push(
|
9
|
-
a.push(
|
10
|
-
end.join(
|
8
|
+
a.push("--color")
|
9
|
+
a.push("--format progress")
|
10
|
+
end.join(" ")
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
14
|
-
|
15
|
-
|
16
|
-
|
14
|
+
require "chefstyle"
|
15
|
+
require "rubocop/rake_task"
|
16
|
+
desc "Run Chefstyle tests"
|
17
|
+
RuboCop::RakeTask.new(:style) do |task|
|
18
|
+
task.options += ["--display-cop-names", "--no-color"]
|
17
19
|
end
|
18
20
|
|
19
|
-
|
21
|
+
desc "Run all tests"
|
22
|
+
task test: %i{style unit functional}
|
23
|
+
|
24
|
+
task default: :test
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
1.0.5
|
data/chef-cleanroom.gemspec
CHANGED
@@ -1,15 +1,14 @@
|
|
1
|
-
|
2
|
-
lib = File.expand_path('../lib', __FILE__)
|
1
|
+
lib = File.expand_path("lib", __dir__)
|
3
2
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require
|
3
|
+
require "cleanroom"
|
5
4
|
|
6
5
|
Gem::Specification.new do |spec|
|
7
|
-
spec.name =
|
6
|
+
spec.name = "chef-cleanroom"
|
8
7
|
spec.version = Cleanroom::VERSION
|
9
|
-
spec.author =
|
10
|
-
spec.email =
|
11
|
-
spec.summary =
|
12
|
-
spec.description = <<-EOH.gsub(/^ {4}/,
|
8
|
+
spec.author = "Seth Vargo"
|
9
|
+
spec.email = "sethvargo@gmail.com"
|
10
|
+
spec.summary = "(More) safely evaluate Ruby DSLs with cleanroom"
|
11
|
+
spec.description = <<-EOH.gsub(/^ {4}/, "").gsub(/\r?\n/, " ").strip
|
13
12
|
Ruby is an excellent programming language for creating and managing custom
|
14
13
|
DSLs, but how can you securely evaluate a DSL while explicitly controlling
|
15
14
|
the methods exposed to the user? Our good friends instance_eval and
|
@@ -20,18 +19,19 @@ Gem::Specification.new do |spec|
|
|
20
19
|
limiting the information exposed by a DSL while giving users the ability to
|
21
20
|
write awesome code!
|
22
21
|
EOH
|
23
|
-
spec.homepage =
|
24
|
-
spec.license =
|
22
|
+
spec.homepage = "https://github.com/chef/cleanroom"
|
23
|
+
spec.license = "Apache-2.0"
|
25
24
|
|
26
|
-
spec.required_ruby_version =
|
25
|
+
spec.required_ruby_version = ">= 1.9.3"
|
27
26
|
|
28
27
|
spec.files = `git ls-files -z`.split("\x0")
|
29
28
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
30
29
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
31
|
-
spec.require_paths = [
|
30
|
+
spec.require_paths = ["lib"]
|
32
31
|
|
33
|
-
spec.add_development_dependency
|
32
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
34
33
|
|
35
|
-
spec.add_development_dependency
|
36
|
-
spec.add_development_dependency
|
34
|
+
spec.add_development_dependency "bundler"
|
35
|
+
spec.add_development_dependency "chefstyle"
|
36
|
+
spec.add_development_dependency "rake"
|
37
37
|
end
|
data/lib/cleanroom/errors.rb
CHANGED
@@ -23,11 +23,11 @@ module Cleanroom
|
|
23
23
|
end
|
24
24
|
|
25
25
|
def to_s
|
26
|
-
<<-EOH.gsub(/\r?\n/,
|
26
|
+
<<-EOH.gsub(/\r?\n/, " ")
|
27
27
|
Undefined local variable or method `#{@name}' for #{@instance}. It may have
|
28
28
|
been removed for the purposes of evaluating the DSL or for added security. If
|
29
29
|
you feel you have reached this message in error, please open an issue.
|
30
|
-
EOH
|
30
|
+
EOH
|
31
31
|
end
|
32
32
|
end
|
33
33
|
end
|
data/lib/cleanroom/rspec.rb
CHANGED
data/lib/cleanroom/version.rb
CHANGED
data/lib/cleanroom.rb
CHANGED
@@ -14,8 +14,8 @@
|
|
14
14
|
# limitations under the License.
|
15
15
|
#
|
16
16
|
|
17
|
-
require_relative
|
18
|
-
require_relative
|
17
|
+
require_relative "cleanroom/errors"
|
18
|
+
require_relative "cleanroom/version"
|
19
19
|
|
20
20
|
module Cleanroom
|
21
21
|
#
|
@@ -102,7 +102,7 @@ module Cleanroom
|
|
102
102
|
#
|
103
103
|
def cleanroom
|
104
104
|
exposed = exposed_methods.keys
|
105
|
-
parent =
|
105
|
+
parent = name || "Anonymous"
|
106
106
|
|
107
107
|
Class.new(Object) do
|
108
108
|
class << self
|
@@ -126,8 +126,8 @@ module Cleanroom
|
|
126
126
|
end
|
127
127
|
|
128
128
|
exposed.each do |exposed_method|
|
129
|
-
define_method(exposed_method) do |*args, &block|
|
130
|
-
__instance__.public_send(exposed_method, *args, &block)
|
129
|
+
define_method(exposed_method) do |*args, **kwargs, &block|
|
130
|
+
__instance__.public_send(exposed_method, *args, **kwargs, &block)
|
131
131
|
end
|
132
132
|
end
|
133
133
|
|
@@ -155,6 +155,7 @@ module Cleanroom
|
|
155
155
|
#
|
156
156
|
def from_superclass(m, default = nil)
|
157
157
|
return default if superclass == Cleanroom
|
158
|
+
|
158
159
|
superclass.respond_to?(m) ? superclass.send(m) : default
|
159
160
|
end
|
160
161
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
3
|
describe Cleanroom do
|
4
4
|
let(:klass) do
|
@@ -33,56 +33,56 @@ describe Cleanroom do
|
|
33
33
|
|
34
34
|
let(:instance) { klass.new }
|
35
35
|
|
36
|
-
describe
|
37
|
-
let(:path) { tmp_path(
|
36
|
+
describe "#evaluate_file" do
|
37
|
+
let(:path) { tmp_path("file.rb") }
|
38
38
|
|
39
39
|
before do
|
40
|
-
File.open(path,
|
41
|
-
f.write <<-EOH.gsub(/^ {10}/,
|
40
|
+
File.open(path, "w") do |f|
|
41
|
+
f.write <<-EOH.gsub(/^ {10}/, "")
|
42
42
|
method_1 'hello'
|
43
43
|
method_2 false
|
44
44
|
EOH
|
45
45
|
end
|
46
46
|
end
|
47
47
|
|
48
|
-
it
|
48
|
+
it "evaluates the file" do
|
49
49
|
instance.evaluate_file(path)
|
50
|
-
expect(instance.method_1).to eq(
|
50
|
+
expect(instance.method_1).to eq("hello")
|
51
51
|
expect(instance.method_2).to be(false)
|
52
52
|
end
|
53
53
|
end
|
54
54
|
|
55
|
-
describe
|
55
|
+
describe "#evaluate" do
|
56
56
|
let(:contents) do
|
57
|
-
<<-EOH.gsub(/^ {8}/,
|
57
|
+
<<-EOH.gsub(/^ {8}/, "")
|
58
58
|
method_1 'hello'
|
59
59
|
method_2 false
|
60
60
|
EOH
|
61
61
|
end
|
62
62
|
|
63
|
-
it
|
63
|
+
it "evaluates the file" do
|
64
64
|
instance.evaluate(contents)
|
65
|
-
expect(instance.method_1).to eq(
|
65
|
+
expect(instance.method_1).to eq("hello")
|
66
66
|
expect(instance.method_2).to be(false)
|
67
67
|
end
|
68
68
|
end
|
69
69
|
|
70
|
-
describe
|
71
|
-
it
|
70
|
+
describe "security" do
|
71
|
+
it "restricts access to __instance__" do
|
72
72
|
expect {
|
73
73
|
instance.evaluate("__instance__")
|
74
74
|
}.to raise_error(Cleanroom::InaccessibleError)
|
75
75
|
end
|
76
76
|
|
77
|
-
it
|
77
|
+
it "restricts access to __instance__ using :send" do
|
78
78
|
expect {
|
79
79
|
instance.evaluate("send(:__instance__)")
|
80
80
|
}.to raise_error(Cleanroom::InaccessibleError)
|
81
81
|
end
|
82
82
|
|
83
|
-
it
|
83
|
+
it "restricts access to defining new methods" do
|
84
84
|
expect {
|
85
|
-
instance.evaluate <<-EOH.gsub(/^ {12}/,
|
85
|
+
instance.evaluate <<-EOH.gsub(/^ {12}/, "")
|
86
86
|
self.class.class_eval do
|
87
87
|
def new_method
|
88
88
|
__instance__.method_3
|
data/spec/spec_helper.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require "rspec"
|
2
|
+
require "fileutils"
|
3
3
|
|
4
|
-
require
|
4
|
+
require "cleanroom"
|
5
5
|
|
6
6
|
RSpec.configure do |config|
|
7
7
|
config.filter_run(focus: true)
|
@@ -19,7 +19,7 @@ RSpec.configure do |config|
|
|
19
19
|
end
|
20
20
|
|
21
21
|
# Run specs in a random order
|
22
|
-
config.order =
|
22
|
+
config.order = "random"
|
23
23
|
end
|
24
24
|
|
25
25
|
#
|
@@ -31,6 +31,5 @@ end
|
|
31
31
|
# @return [String]
|
32
32
|
#
|
33
33
|
def tmp_path(*paths)
|
34
|
-
|
35
|
-
File.join('tmp', *paths)
|
34
|
+
File.join("tmp", *paths)
|
36
35
|
end
|
data/spec/unit/cleanroom_spec.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
3
|
describe Cleanroom do
|
4
4
|
let(:klass) do
|
@@ -16,33 +16,33 @@ describe Cleanroom do
|
|
16
16
|
|
17
17
|
let(:instance) { klass.new }
|
18
18
|
|
19
|
-
describe
|
19
|
+
describe ".included" do
|
20
20
|
let(:klass) { Class.new { include Cleanroom } }
|
21
21
|
|
22
|
-
it
|
22
|
+
it "extends the ClassMethods" do
|
23
23
|
expect(klass).to be_a(Cleanroom::ClassMethods)
|
24
24
|
end
|
25
25
|
|
26
|
-
it
|
26
|
+
it "includes the InstanceMethods" do
|
27
27
|
expect(instance).to be_a(Cleanroom::InstanceMethods)
|
28
28
|
end
|
29
29
|
end
|
30
30
|
|
31
|
-
describe
|
31
|
+
describe ".extended" do
|
32
32
|
let(:klass) { Class.new { extend Cleanroom } }
|
33
33
|
|
34
|
-
it
|
34
|
+
it "extends the ClassMethods" do
|
35
35
|
expect(klass).to be_a(Cleanroom::ClassMethods)
|
36
36
|
end
|
37
37
|
|
38
|
-
it
|
38
|
+
it "includes the InstanceMethods" do
|
39
39
|
expect(instance).to be_a(Cleanroom::InstanceMethods)
|
40
40
|
end
|
41
41
|
end
|
42
42
|
|
43
|
-
describe
|
44
|
-
let(:path) {
|
45
|
-
let(:contents) {
|
43
|
+
describe ".evaluate_file" do
|
44
|
+
let(:path) { "/path/to/file" }
|
45
|
+
let(:contents) { "contents" }
|
46
46
|
|
47
47
|
before do
|
48
48
|
allow(File).to receive(:expand_path)
|
@@ -56,25 +56,25 @@ describe Cleanroom do
|
|
56
56
|
allow(klass).to receive(:evaluate)
|
57
57
|
end
|
58
58
|
|
59
|
-
it
|
59
|
+
it "gets the absolute path to the file" do
|
60
60
|
expect(File).to receive(:expand_path).with(path).once
|
61
61
|
klass.evaluate_file(instance, path)
|
62
62
|
end
|
63
63
|
|
64
|
-
it
|
64
|
+
it "reads the contents to a string" do
|
65
65
|
expect(IO).to receive(:read).with(path).once
|
66
66
|
klass.evaluate_file(instance, path)
|
67
67
|
end
|
68
68
|
|
69
|
-
it
|
69
|
+
it "evaluates the contents" do
|
70
70
|
expect(klass).to receive(:evaluate).with(instance, contents, path, 1).once
|
71
71
|
klass.evaluate_file(instance, path)
|
72
72
|
end
|
73
73
|
end
|
74
74
|
|
75
|
-
describe
|
76
|
-
let(:cleanroom) { double(
|
77
|
-
let(:cleanroom_instance) { double(
|
75
|
+
describe ".evaluate" do
|
76
|
+
let(:cleanroom) { double("Cleanroom.cleanroom") }
|
77
|
+
let(:cleanroom_instance) { double("Cleanroom.cleanroom_instance") }
|
78
78
|
|
79
79
|
let(:string) { '"hello"' }
|
80
80
|
|
@@ -89,18 +89,18 @@ describe Cleanroom do
|
|
89
89
|
.and_return(cleanroom)
|
90
90
|
end
|
91
91
|
|
92
|
-
it
|
92
|
+
it "creates a new cleanroom object" do
|
93
93
|
expect(cleanroom).to receive(:new).with(instance).once
|
94
94
|
klass.evaluate(instance, string)
|
95
95
|
end
|
96
96
|
|
97
|
-
it
|
97
|
+
it "evaluates against the new cleanroom object" do
|
98
98
|
expect(cleanroom_instance).to receive(:instance_eval).with(string).once
|
99
99
|
klass.evaluate(instance, string)
|
100
100
|
end
|
101
101
|
end
|
102
102
|
|
103
|
-
describe
|
103
|
+
describe ".expose" do
|
104
104
|
let(:klass) do
|
105
105
|
Class.new do
|
106
106
|
include Cleanroom
|
@@ -108,38 +108,40 @@ describe Cleanroom do
|
|
108
108
|
def public_method; end
|
109
109
|
|
110
110
|
protected
|
111
|
+
|
111
112
|
def protected_method; end
|
112
113
|
|
113
114
|
private
|
115
|
+
|
114
116
|
def private_method; end
|
115
117
|
end
|
116
118
|
end
|
117
119
|
|
118
|
-
it
|
120
|
+
it "exposes the method when it is public" do
|
119
121
|
expect { klass.expose(:public_method) }.to_not raise_error
|
120
122
|
expect(klass.exposed_methods).to include(:public_method)
|
121
123
|
end
|
122
124
|
|
123
|
-
it
|
125
|
+
it "raises an exception if the method is not defined" do
|
124
126
|
expect { klass.expose(:no_method) }.to raise_error(NameError)
|
125
127
|
end
|
126
128
|
|
127
|
-
it
|
129
|
+
it "raises an exception if the method is protected" do
|
128
130
|
expect { klass.expose(:protected_method) }.to raise_error(NameError)
|
129
131
|
end
|
130
132
|
|
131
|
-
it
|
133
|
+
it "raises an exception if the method is private" do
|
132
134
|
expect { klass.expose(:private_method) }.to raise_error(NameError)
|
133
135
|
end
|
134
136
|
end
|
135
137
|
|
136
|
-
describe
|
137
|
-
it
|
138
|
+
describe ".exposed_methods" do
|
139
|
+
it "returns a hash" do
|
138
140
|
expect(klass.exposed_methods).to be_a(Hash)
|
139
141
|
end
|
140
142
|
end
|
141
143
|
|
142
|
-
describe
|
144
|
+
describe ".cleanroom" do
|
143
145
|
let(:klass) do
|
144
146
|
Class.new do
|
145
147
|
include Cleanroom
|
@@ -156,19 +158,19 @@ describe Cleanroom do
|
|
156
158
|
end
|
157
159
|
end
|
158
160
|
|
159
|
-
it
|
161
|
+
it "creates a new anonymous class each time" do
|
160
162
|
a, b = klass.send(:cleanroom), klass.send(:cleanroom)
|
161
163
|
expect(a).to_not be(b)
|
162
164
|
end
|
163
165
|
|
164
|
-
it
|
166
|
+
it "creates a method for each exposed one on the proxy object" do
|
165
167
|
cleanroom = klass.send(:cleanroom)
|
166
168
|
|
167
169
|
expect(cleanroom).to be_public_method_defined(:method_1)
|
168
170
|
expect(cleanroom).to be_public_method_defined(:method_2)
|
169
171
|
end
|
170
172
|
|
171
|
-
it
|
173
|
+
it "calls the proxied method" do
|
172
174
|
cleanroom = klass.send(:cleanroom).new(instance)
|
173
175
|
cleanroom.method_1
|
174
176
|
cleanroom.method_2
|
@@ -177,7 +179,7 @@ describe Cleanroom do
|
|
177
179
|
expect(instance.instance_variable_get(:@method_2)).to be(true)
|
178
180
|
end
|
179
181
|
|
180
|
-
it
|
182
|
+
it "prevents calls to the instance directly" do
|
181
183
|
cleanroom = klass.send(:cleanroom).new(instance)
|
182
184
|
expect {
|
183
185
|
cleanroom.__instance__
|
@@ -189,25 +191,25 @@ describe Cleanroom do
|
|
189
191
|
end
|
190
192
|
end
|
191
193
|
|
192
|
-
describe
|
193
|
-
let(:path) {
|
194
|
+
describe "#evaluate_file" do
|
195
|
+
let(:path) { "/path/to/file" }
|
194
196
|
|
195
197
|
before do
|
196
198
|
allow(klass).to receive(:evaluate_file)
|
197
199
|
.with(instance, path)
|
198
200
|
end
|
199
201
|
|
200
|
-
it
|
202
|
+
it "delegates to the class method" do
|
201
203
|
expect(klass).to receive(:evaluate_file).with(instance, path)
|
202
204
|
instance.evaluate_file(path)
|
203
205
|
end
|
204
206
|
|
205
|
-
it
|
207
|
+
it "returns self" do
|
206
208
|
expect(instance.evaluate_file(path)).to be(instance)
|
207
209
|
end
|
208
210
|
end
|
209
211
|
|
210
|
-
describe
|
212
|
+
describe "#evaluate" do
|
211
213
|
let(:string) { '"hello"' }
|
212
214
|
|
213
215
|
before do
|
@@ -215,17 +217,17 @@ describe Cleanroom do
|
|
215
217
|
.with(instance, string)
|
216
218
|
end
|
217
219
|
|
218
|
-
it
|
220
|
+
it "delegates to the class method" do
|
219
221
|
expect(klass).to receive(:evaluate).with(instance, string)
|
220
222
|
instance.evaluate(string)
|
221
223
|
end
|
222
224
|
|
223
|
-
it
|
225
|
+
it "returns self" do
|
224
226
|
expect(instance.evaluate(string)).to be(instance)
|
225
227
|
end
|
226
228
|
end
|
227
229
|
|
228
|
-
context
|
230
|
+
context "when evaluating a DSL subclass" do
|
229
231
|
let(:parent) do
|
230
232
|
Class.new do
|
231
233
|
include Cleanroom
|
@@ -244,19 +246,19 @@ describe Cleanroom do
|
|
244
246
|
|
245
247
|
let(:instance) { child.new }
|
246
248
|
|
247
|
-
it
|
249
|
+
it "inherits the parent DSL methods" do
|
248
250
|
expect {
|
249
251
|
instance.evaluate("parent_method")
|
250
252
|
}.to_not raise_error
|
251
253
|
end
|
252
254
|
|
253
|
-
it
|
255
|
+
it "allows for custom DSL methods" do
|
254
256
|
expect {
|
255
257
|
instance.evaluate("child_method")
|
256
258
|
}.to_not raise_error
|
257
259
|
end
|
258
260
|
|
259
|
-
it
|
261
|
+
it "does not change the parent DSL" do
|
260
262
|
expect {
|
261
263
|
parent.new.evaluate("child_method")
|
262
264
|
}.to raise_error(NameError)
|
data/spec/unit/rspec_spec.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require "spec_helper"
|
2
|
+
require "cleanroom/rspec"
|
3
3
|
|
4
|
-
describe
|
4
|
+
describe "RSpec matchers" do
|
5
5
|
let(:klass) do
|
6
6
|
Class.new do
|
7
7
|
include Cleanroom
|
@@ -15,61 +15,61 @@ describe 'RSpec matchers' do
|
|
15
15
|
|
16
16
|
let(:instance) { klass.new }
|
17
17
|
|
18
|
-
describe
|
19
|
-
context
|
20
|
-
it
|
18
|
+
describe "#be_an_exposed_method_on" do
|
19
|
+
context "when given a class" do
|
20
|
+
it "is true when the method is exposed" do
|
21
21
|
expect(:method_1).to be_an_exposed_method_on(klass)
|
22
22
|
end
|
23
23
|
|
24
|
-
it
|
24
|
+
it "is false when the method exists, but is not exposed" do
|
25
25
|
expect(:method_2).to_not be_an_exposed_method_on(klass)
|
26
26
|
end
|
27
27
|
|
28
|
-
it
|
28
|
+
it "is false when the method is not exposed" do
|
29
29
|
expect(:method_3).to_not be_an_exposed_method_on(klass)
|
30
30
|
end
|
31
31
|
end
|
32
32
|
|
33
|
-
context
|
34
|
-
it
|
33
|
+
context "when given an instance" do
|
34
|
+
it "is true when the method is exposed" do
|
35
35
|
expect(:method_1).to be_an_exposed_method_on(instance)
|
36
36
|
end
|
37
37
|
|
38
|
-
it
|
38
|
+
it "is false when the method exists, but is not exposed" do
|
39
39
|
expect(:method_2).to_not be_an_exposed_method_on(instance)
|
40
40
|
end
|
41
41
|
|
42
|
-
it
|
42
|
+
it "is false when the method is not exposed" do
|
43
43
|
expect(:method_3).to_not be_an_exposed_method_on(instance)
|
44
44
|
end
|
45
45
|
end
|
46
46
|
end
|
47
47
|
|
48
|
-
describe
|
49
|
-
context
|
50
|
-
it
|
48
|
+
describe "#have_exposed_method" do
|
49
|
+
context "when given a class" do
|
50
|
+
it "is true when the method is exposed" do
|
51
51
|
expect(klass).to have_exposed_method(:method_1)
|
52
52
|
end
|
53
53
|
|
54
|
-
it
|
54
|
+
it "is false when the method exists, but is not exposed" do
|
55
55
|
expect(klass).to_not have_exposed_method(:method_2)
|
56
56
|
end
|
57
57
|
|
58
|
-
it
|
58
|
+
it "is false when the method is not exposed" do
|
59
59
|
expect(klass).to_not have_exposed_method(:method_3)
|
60
60
|
end
|
61
61
|
end
|
62
62
|
|
63
|
-
context
|
64
|
-
it
|
63
|
+
context "when given an instance" do
|
64
|
+
it "is true when the method is exposed" do
|
65
65
|
expect(instance).to have_exposed_method(:method_1)
|
66
66
|
end
|
67
67
|
|
68
|
-
it
|
68
|
+
it "is false when the method exists, but is not exposed" do
|
69
69
|
expect(instance).to_not have_exposed_method(:method_2)
|
70
70
|
end
|
71
71
|
|
72
|
-
it
|
72
|
+
it "is false when the method is not exposed" do
|
73
73
|
expect(instance).to_not have_exposed_method(:method_3)
|
74
74
|
end
|
75
75
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: chef-cleanroom
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Seth Vargo
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-05-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -38,6 +38,20 @@ dependencies:
|
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: chefstyle
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: rake
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -65,13 +79,20 @@ executables: []
|
|
65
79
|
extensions: []
|
66
80
|
extra_rdoc_files: []
|
67
81
|
files:
|
82
|
+
- ".expeditor/buildkite/verify.ps1"
|
83
|
+
- ".expeditor/buildkite/verify.sh"
|
84
|
+
- ".expeditor/config.yml"
|
85
|
+
- ".expeditor/update_version.sh"
|
86
|
+
- ".expeditor/verify.pipeline.yml"
|
68
87
|
- ".gitignore"
|
69
|
-
- ".
|
88
|
+
- ".rspec"
|
89
|
+
- ".rubocop.yml"
|
70
90
|
- CHANGELOG.md
|
71
91
|
- Gemfile
|
72
92
|
- LICENSE
|
73
93
|
- README.md
|
74
94
|
- Rakefile
|
95
|
+
- VERSION
|
75
96
|
- chef-cleanroom.gemspec
|
76
97
|
- lib/cleanroom.rb
|
77
98
|
- lib/cleanroom/errors.rb
|
@@ -85,7 +106,7 @@ homepage: https://github.com/chef/cleanroom
|
|
85
106
|
licenses:
|
86
107
|
- Apache-2.0
|
87
108
|
metadata: {}
|
88
|
-
post_install_message:
|
109
|
+
post_install_message:
|
89
110
|
rdoc_options: []
|
90
111
|
require_paths:
|
91
112
|
- lib
|
@@ -100,8 +121,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
100
121
|
- !ruby/object:Gem::Version
|
101
122
|
version: '0'
|
102
123
|
requirements: []
|
103
|
-
rubygems_version: 3.
|
104
|
-
signing_key:
|
124
|
+
rubygems_version: 3.3.7
|
125
|
+
signing_key:
|
105
126
|
specification_version: 4
|
106
127
|
summary: "(More) safely evaluate Ruby DSLs with cleanroom"
|
107
128
|
test_files:
|