I’m developing a converter, and I use the rspec to check the values which were converted are correct. In order to check the value, I need to load the converted file (written in JSON). So I readied a method to load converted files in spec_helper.rb. I call this method in each spec file with :before hooks (But it’s not the essence of this question).
Then, I want to run the same rspec tests for multiple converted results. This is a just image.
file_names = [ 'file1', 'file2', 'file3' ] # OR use Dir.glob to get some file paths
file_names.each do |file|
all_rspec_tests( file )
end
Please tell me the best practice where I iterate some file names. I tried a few patterns.
1) In Rakefile, We can’t pass the variable with RakeTask. Then I used ENV (Environment variable), like this: how to pass command-line parameter to Rspec script?
It didn’t work expectedly. In particular, a RakeTast does not run as sequential (looks like running on the other thread), so each test didn’t run correctly.
2) Make a module and extend RSpec with it like this:
Run the same spec multiple times w/ different filters
But It’s a pattern for using JavaScript. And I don’t know this method will be success.
I usually use:
But you need a folder ‘spec’ with two files custom_formatter.rb and environment.rb
custom_formatter.rb:
environment.rb: