# Inspec use returned results from one testcase in another test case

**URL:** https://discourse.chef.io/t/inspec-use-returned-results-from-one-testcase-in-another-test-case/8079
**Category:** Chef InSpec
**Created:** [March 28, 2016, 10:38pm UTC](https://discourse.chef.io/t/inspec-use-returned-results-from-one-testcase-in-another-test-case/8079 "2016-03-28T22:38:36Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![AnotherNerdHere](https://avatars.discourse-cdn.com/v4/letter/a/85e7bf/32.png) [@AnotherNerdHere](https://discourse.chef.io/u/AnotherNerdHere)
#### Post date: [March 28, 2016, 10:38pm UTC](https://discourse.chef.io/t/inspec-use-returned-results-from-one-testcase-in-another-test-case/8079/1 "2016-03-28T22:38:37Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![chris-rock](https://avatars.discourse-cdn.com/v4/letter/c/e9c0ed/32.png) [@chris-rock](https://discourse.chef.io/u/chris-rock)
#### Post date: [March 31, 2016, 2:10pm UTC](https://discourse.chef.io/t/inspec-use-returned-results-from-one-testcase-in-another-test-case/8079/2 "2016-03-31T14:10:23Z")

</div>

> [@AnotherNerdHere](#):
>
> describe command("dig +short 8.8.8.8") doits("stdout") { should cmp '\*.'}end

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?

---

<div class="post-metadata">

### Author: ![AnotherNerdHere](https://avatars.discourse-cdn.com/v4/letter/a/85e7bf/32.png) [@AnotherNerdHere](https://discourse.chef.io/u/AnotherNerdHere)
#### Post date: [March 31, 2016, 4:06pm UTC](https://discourse.chef.io/t/inspec-use-returned-results-from-one-testcase-in-another-test-case/8079/3 "2016-03-31T16:06:29Z")

</div>

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