I heard a rumor that InSpec now supports referencing Chef node attributes within InSpec test files run by Test Kitchen. But I can’t find any documentation on it.
I’m trying to write an InSpec test for a Chef cookbook. The test will be run by Test Kitchen. The cookbook sets an attribute foo to a certain value depending on environmental factors. I want my InSpec test to access the value of that foo attribute. But I can’t figure out how to access node attributes from within my InSpec test file.
This doesn’t work for me (although it worked in Serverspec test files):
foo = node['foo'] describe file(foo) do . . .
When I do that, I get this error from InSpec:
./test/smoke/default/default_test.rb:14:in `load_with_context': undefined local variable or method `node' for #<#<Class:0x000000036afb28>:0x000000036af420> (NameError)
I’d appreciate any info on this. It seems like a basic capability to me. The fact that I’ve had such a hard time finding info about it makes me think I’m just not understanding something fundamental about how InSpec is supposed to be used to write integration tests for cookbooks.