ruby on rails - How can I add a variable to an "it" statement in an rspec? -


if have

let(:analysis_file_1) { "./spec/test_files/analysis1.json" } ... "should have message x" 

i'd print out value of analysis_file_1 in "it" statement.

but doesn't work:

it "#{analysis_file_1} should have message x" 

it errors out

in `block in <top (required)>': undefined local variable or method `analysis_file_1' #<class:0x007f865a219c00> (nameerror) 

is there way use let defined variable in message?

you can define constant this:

analysis_file_1 = "./spec/test_files/analysis1.json"  "#{analysis_file_1} should have message x" 

or in case have multiple analysis files can put them in array:

["./spec/test_files/analysis1.json", "./spec/test_files/analysis2.json", "./spec/test_files/analysis3.json"].each |analysis_file|   "#{analysis_file} should have message x"     # spec here   end end 

Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

Function that returns a formatted array in VBA -