From a86ea8a35445b39d9a394da56ffff13d76800867 Mon Sep 17 00:00:00 2001 From: Jason Barnett Date: Tue, 22 Mar 2022 10:34:14 -0600 Subject: [PATCH 1/2] Add chef_node accessor to core api Signed-off-by: Jason Barnett --- lib/chefspec/api/core.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/chefspec/api/core.rb b/lib/chefspec/api/core.rb index 0207a750..9fc7e8a8 100644 --- a/lib/chefspec/api/core.rb +++ b/lib/chefspec/api/core.rb @@ -75,6 +75,10 @@ def chef_runner_instance # By default, run the recipe in the base `describe` block. let(:chef_run) { chef_runner.converge(described_recipe) } + # Give a default accessor for stubbing things on the node object + # associated with the runner instance. + let(:chef_node) { chef_runner.node } + # Helper method for some of the nestable test value methods like # {ClassMethods#default_attributes} and {ClassMethods#step_into}. # From 710c3eeda85c8e4dab5ad3d3e91e10069ee452d7 Mon Sep 17 00:00:00 2001 From: Jason Barnett Date: Wed, 20 Apr 2022 12:04:16 -0600 Subject: [PATCH 2/2] add stub for Chef.node Signed-off-by: Jason Barnett --- lib/chefspec/api/core.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/chefspec/api/core.rb b/lib/chefspec/api/core.rb index 9fc7e8a8..9c8600ca 100644 --- a/lib/chefspec/api/core.rb +++ b/lib/chefspec/api/core.rb @@ -21,6 +21,10 @@ module Core end end + before do + allow(::Chef).to recieve(:node).and_return(chef_node) if chefspec_platform + end + # Let variables to set data in a scoped way. Used below by # {ClassMethods#platform}. let(:chefspec_default_attributes) { chefspec_attributes(:default_attributes) }