"for" loop in inspec

I’m attempting to use a for loop to save myself some typing with inspec. My first attemtp looks like this:

for i in 1..2 
  describe group('testgroup#{i}') do
    it { should exist }
  end
end

But inspec doesn’t seem to like that:

  Group testgroup#{i}
     ∅  should exist
     expected Group testgroup#{i} to exist
  Group testgroup#{i}
     ∅  should exist
     expected Group testgroup#{i} to exist

I’m a bit of a n00b in Ruby, but it somes from an example which seems to be correct.

Any help appreciated :slight_smile:

You need to use double quotes when using string interpolation (i.e., the #{ruby code} thing).

1 Like

Thanks, that worked a treat.

I’m a bash refugee, acclimatisation may take some time :slight_smile:

Tick Man, could you post your fixed/final loop that worked, please?
This was we have a visual reference.
Thanks!

Y.

for i in 1..2 
  describe group("testgroup#{i}") do
    it { should exist }
  end
end
1 Like