Module: RSpec::Puppet::FunctionExampleGroup
- Includes:
- FunctionMatchers, ManifestMatchers, Support
- Defined in:
- lib/rspec-puppet/example/function_example_group.rb
Defined Under Namespace
Classes: V3FunctionWrapper, V4FunctionWrapper
Instance Attribute Summary
Attributes included from Support
Instance Method Summary collapse
- #call_function(function_name, *args) ⇒ Object
- #catalogue ⇒ Object
- #find_function(function_name = self.class.top_level_description) ⇒ Object
- #rspec_puppet_cleanup ⇒ Object
- #scope ⇒ Object
-
#subject ⇒ Object
(at least) rspec 3.5 doesn’t seem to memoize ‘subject` when called from a before(:each) hook, so we need to memoize it ourselves.
Methods included from Support
#build_catalog, #build_catalog_without_cache, #build_catalog_without_cache_v2, #build_code, #class_name, #environment, #escape_special_chars, #facts_hash, #find_pretend_platform, #fixture_spec_hiera_conf, #guess_type_from_path, #import_str, #load_catalogue, #munge_facts, #node_params_hash, #nodename, #param_str, #param_str_from_hash, #post_cond, #pre_cond, #ref, #rspec_compatibility, #sanitise_resource_title, #sensitive, #server_facts_hash, #setup_puppet, #site_pp_str, #str_from_value, #stub_facts!, #stub_file_consts, #test_manifest, #trusted_external_data_hash, #trusted_facts_hash, #with_vardir
Methods included from GenericMatchers
Methods included from ManifestMatchers
#have_class_count, #have_resource_count, #method_missing
Methods included from FunctionMatchers
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class RSpec::Puppet::ManifestMatchers
Instance Method Details
#call_function(function_name, *args) ⇒ Object
105 106 107 108 109 |
# File 'lib/rspec-puppet/example/function_example_group.rb', line 105 def call_function(function_name, *args) # function = find_function(function_name) # function.execute(*args) scope.call_function(function_name, args) end |
#catalogue ⇒ Object
114 115 116 |
# File 'lib/rspec-puppet/example/function_example_group.rb', line 114 def catalogue @catalogue ||= compiler.catalog end |
#find_function(function_name = self.class.top_level_description) ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/rspec-puppet/example/function_example_group.rb', line 82 def find_function(function_name = self.class.top_level_description) with_vardir do env = adapter.current_environment if Puppet.version.to_f >= 4.0 context_overrides = compiler.context_overrides func = nil loaders = Puppet.lookup(:loaders) Puppet.override(context_overrides, "rspec-test scope") do func = V4FunctionWrapper.new(function_name, loaders.private_environment_loader.load(:function, function_name), context_overrides) @scope = context_overrides[:global_scope] end return func if func.func end if Puppet::Parser::Functions.function(function_name) V3FunctionWrapper.new(function_name, scope.method("function_#{function_name}".intern)) else nil end end end |
#rspec_puppet_cleanup ⇒ Object
118 119 120 121 122 123 |
# File 'lib/rspec-puppet/example/function_example_group.rb', line 118 def rspec_puppet_cleanup @subject = nil @catalogue = nil @compiler = nil @scope = nil end |
#scope ⇒ Object
110 111 112 |
# File 'lib/rspec-puppet/example/function_example_group.rb', line 110 def scope @scope ||= build_scope(compiler, nodename(:function)) end |
#subject ⇒ Object
(at least) rspec 3.5 doesn’t seem to memoize ‘subject` when called from a before(:each) hook, so we need to memoize it ourselves.
78 79 80 |
# File 'lib/rspec-puppet/example/function_example_group.rb', line 78 def subject @subject ||= find_function end |