So I dug into the RSpec code a little more and I did find a 'solution'. 
While `config.files_to_run = ['path/to/a_spec.rb[1:1:2:1:1:1]']` will run 
into loading issues, 
`config.instance_variable_set(:@files_or_directories_to_run ,  
['path/to/a_spec.rb[1:1:2:1:1:1]'])` will work. This seems to be because 
`@files_or_directories_to_run` is where the paths provided on the command 
line are stored when the command is parsed.

It's odd that, essentially, some kinds of configuration can only be 
provided via the command line, instead of any needed configuration being 
possible via the configuration object in code form.


Eric K

On Sunday, April 12, 2020 at 8:43:01 PM UTC-7, Eric Kessler wrote:
>
>
>
> On Thursday, April 9, 2020 at 3:17:56 AM UTC-7, Jon Rowe wrote:
>>
>> Ah if you want to build something programmatic, you can use the 
>> configuration object.
>>
>> See: 
>> http://rspec.info/documentation/3.9/rspec-core/RSpec/Core/Configuration.html#files_to_run-instance_method
>>
>> You could use that to configure rspec to run a certain files contents e.g:
>>
>> ```
>> RSpec.configure do |config|
>>   filename = File.expand_path('../files.txt', __dir__)
>>   if File.exist?(filename)
>>     specs = File.read(filename).split("\n")
>>     puts "Loading #{specs.size} spec files from files.txt"
>>     config.files_to_run = specs
>>   end
>> end
>> ```
>>
>
>
> This approach is promising and I'm giving it a try. However, 
> `config.files_to_run` does not seem to accept the `file[x:x]` notation 
> because it will try to `#load` the files and that notation is not a valid 
> file path.
>
> Thanks,
> Eric K
>  
>
>>
>> Cheers
>> Jon Rowe
>> ---------------------------
>> [email protected]
>> jonrowe.co.uk
>>
>> On 9 April 2020 at 11:02, Eric Kessler wrote:
>>
>> On Thursday, April 9, 2020 at 2:44:17 AM UTC-7, Jon Rowe wrote:
>>
>> RSpec does not have this built in, but you don’t need it to be in order 
>> to achieve this, here is how to do that from a linux command line.
>>
>> `rspec $(cat your_file.txt)`
>>
>>
>>
>> That is a straightforward way of building a command line, yes, and I 
>> could certainly build such a command in pure Ruby (which would be my 
>> preference because I need cross-platform compatibility) before handing it 
>> off to whatever child process I need to execute it. However, I am cautious 
>> of that kind of approach because surely there is some practical limitation 
>> to how long a command can be. Yes, the internal test runner can easily 
>> iterate over an array that has a million or so entries but won't the 
>> Linux/Windows/OSX terminal that I have to feed the initial rspec command 
>> into complain about the command length at some point?
>>
>> I'm looking for a general and reliable solution so that I don't have to 
>> worry about losing tests if the command gets cut short or have to come up 
>> with a new approach if the terminal errors out on the input or something. 
>> Currently, my alternative idea would be to build a string containing Ruby 
>> code that sucks in the file as an array and then hands that array to the 
>> RSpec test runner to execute. It isn't as elegant but I'm at least pretty 
>> certain that it will consistently work.
>>
>>
>> Eric K
>>
>>  
>>
>>

-- 
You received this message because you are subscribed to the Google Groups 
"rspec" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rspec/14d7e035-f804-4caf-9b61-15e3ce61bd46%40googlegroups.com.

Reply via email to