I have specs that have:
describe "can translate" do
let(:from){591}
it "#{from}" do
expect(Translator.three_digits(from)).to eq 'five hundred ninety two'
end
end
but 591 is hard-coded and repeated which I want to eliminate...
so how can I refer to from
in the it
description?
I tried having let(:from){591}
and then using it "#{@from}"
but that doesn't show it
I also tried using it "#{from}"
but that gives an error undefined local variable or method
'from' for #<Class:0x00000001bc4110> (NameError)
as it's looking for a locally scoped variable.
I can avoid all these scope issues with constants, i.e.
describe "can translate" do
FROM=592
it "#{FROM}" do
expect(Translator.three_digits(FROM)).to eq 'five hundred ninety two'
end
end
With that when I get an eror I actually get A ruby file called translator.rb can translate 591
(or whatever number, the key this is that it prints out unlike all my attempt with the variable).
`
but this seems like a poor approach. I prefer to avoid constant when possible and I want to do this test for several values in a row, so I need something I can change from case to case and a CONSTANT seems inappropriate.
I also tried before :all with both local and instance variables but with no success.
If I hard code the it and literally put 591 as the text and the test fails then the 591 prints out which is what I want. However I cannot get the same result working though any variable that I also use in the test.