I have this Spec file:
require 'spec_helper'
for i in 1..3
describe file ("/var/tmp/efl_test_0#{i}_link" )do
it { should be_linked_to "/tmp/efl_test_0#{i}" }
end
end
The expected results are:
/var/tmp/efl_test01_link should be_linke_to /tmp/efl_test01
/var/tmp/efl_test02_link should be_linke_to /tmp/efl_test02
/var/tmp/efl_test03_link should be_linke_to /tmp/efl_test03
The actual results are:
Failure/Error: it { should be_linked_to "/tmp/efl_test_0#{i}" }
stat -c %N /var/tmp/efl_test_01_link | egrep -e "-> ./tmp/efl_test_03."
Failure/Error: it { should be_linked_to "/tmp/efl_test_0#{i}" }
stat -c %N /var/tmp/efl_test_02_link | egrep -e "-> ./tmp/efl_test_03."
Failure/Error: it { should be_linked_to "/tmp/efl_test_0#{i}" }
stat -c %N /var/tmp/efl_test_03_link | egrep -e "-> ./tmp/efl_test_03."
Each link is compared to the 03
target. The problem is something about the loop I guess.
What have I done wrong?
This could be an artifact of how
i
is captured as a closure and lazy-evaluated bydescribe
later on. At that point it's been incremented. You may need to deliberately capture it:Normally you'd use
3.times do
to be more conventional Ruby. Thefor
construct is hardly ever used.