rubyrspecnewlineoptionparser

Send multiline argument to OptionParser


I have .rspec file in my project with content something like this:
--exclude-pattern spec/1_spec.rb, spec/2_spec.rb
There is pretty long line of specs, so I want to split this to several lines, but don't know how.
--exclude-pattern spec/1_spec.rb, \ spec/2_spec.rb seems not working, rspec command give error: Unmatched double quote: "--exclude-pattern 'spec/1_spec.rb, What line separator should I use?

UPDATE: I found out, that rspec uses OptionParser to parse those arguments. So I can rephrase my question:
How to send multiline argument to OptionParser


Solution

  • Did you know that you can use ERB in this file? Given you have a excluded_files.txt file in the same directory with contents:

    spec/1_spec.rb
    spec/2_spec.rb
    

    You can write your .rspec this way:

    --exclude-pattern <%= File.readlines('excluded_files.txt').map(&:strip).join(', ') %>
    

    This should result to a single string of excluded files separated by commas.

    P.S. Maybe you should use tags instead?