/usr/lib/ruby/vendor_ruby/cheffish/rspec/chef_run_support.rb is in ruby-cheffish 4.0.0-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 | require 'chef_zero/rspec'
require 'chef/server_api'
require 'cheffish/rspec/repository_support'
require 'uri'
require 'cheffish/chef_run'
require 'cheffish/rspec/recipe_run_wrapper'
require 'cheffish/rspec/matchers'
module Cheffish
module RSpec
module ChefRunSupport
include ChefZero::RSpec
include RepositorySupport
def self.extended(klass)
klass.class_eval do
include ChefRunSupportInstanceMethods
end
end
def when_the_chef_12_server(*args, **options, &block)
if Gem::Version.new(ChefZero::VERSION) >= Gem::Version.new('3.1')
when_the_chef_server(*args, :osc_compat => false, :single_org => false, **options, &block)
end
end
def with_converge(&recipe)
before :each do
r = recipe(&recipe)
r.converge
end
end
module ChefRunSupportInstanceMethods
def rest
::Chef::ServerAPI.new(Chef::Config.chef_server_url, api_version: "0")
end
def get(path, *args)
if path[0] == '/'
path = URI.join(rest.url, path)
end
rest.get(path, *args)
end
def chef_config
{}
end
def expect_recipe(str=nil, file=nil, line=nil, &recipe)
r = recipe(str, file, line, &recipe)
r.converge
expect(r)
end
def expect_converge(str=nil, file=nil, line=nil, &recipe)
expect { converge(str, file, line, &recipe) }
end
def recipe(str=nil, file=nil, line=nil, &recipe)
if !recipe
if file && line
recipe = proc { eval(str, nil, file, line) }
else
recipe = proc { eval(str) }
end
end
RecipeRunWrapper.new(chef_config, &recipe)
end
def converge(str=nil, file=nil, line=nil, &recipe)
r = recipe(str, file, line, &recipe)
r.converge
r
end
def chef_client
@chef_client ||= ChefRun.new(chef_config)
end
end
end
end
end
|