"for" loop in inspec


#1

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:


#2

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


#3

Thanks, that worked a treat.

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


#4

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

Y.


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