Inspec use returned results from one testcase in another test case

Hi,

as the subject line say I’d like to use returned results from one testcase in another test case
here is a simple use case: assume you have a test case that look like:
> describe command(“dig +short 8.8.8.8”) do
> its(“stdout”) { should cmp ‘*.’}
> end

The dig command returns a IP address. I would like to take the returned IP addres and use it in the succeeding test(s) for a simple example
> describe command("ping ") do
> its(“stdout”) { should cmp ‘’}
> end

Yes that code will not work, I know that. Its only to explain a use case. What I really what to know is something like this possible? If so can you provide a commented example? If not, could I do something like this using custom resources? if so can you provide an example?

Thanks.

Hi @AnotherNerdHere
Thanks for bringing up that question. In your case, you do not really want to run a test, you want to use a result from a resource in a test. So in your case you could do

ip = command("dig +short 8.8.8.8").stdout
# some stuff to extract the ip properly, use ruby to manipulate

# you can easiliy use variables in parameters
describe command("ping #{ip}") do
   its("stdout") { should cmp ''}
end

I hope that answers your question?

Thanks Chris. That helps greatly. I really appreciate the example.