How to run second test example with RSpec::Core::Runner for the same test file
Created by: ArturT
Subject of the issue
I use RSpec::Core::Runner
to run specs https://relishapp.com/rspec/rspec-core/v/3-3/docs/running-specs-multiple-times-with-different-runner-options-in-the-same-process
I run test files and test examples (i.e. spec/example_spec.rb[1:1]) at the same time. I'm getting test files and test example paths from external API. Sometimes it can happen that RSpec::Core::Runner
will have to run a second test example B1
from the test file spec/example_spec.rb
for which we already run first test example A1
but the second test example B1
is ignored. I don't know how to force RSpec to run B1
test :(
I tried to dig into the source code of RSpec for the last 3 days but I'm stuck. Any help or tips where can I look for a solution would be great.
Your environment
- Ruby version: 2.6.5
- rspec-core version: 3.9.1
Steps to reproduce
Source code: https://github.com/ArturT/rspec-test-examples
# spec/example_spec.rb
describe 'Example 1' do
it 'A1' do
expect(true).to be true
end
it 'B1' do
expect(true).to be true
end
end
# spec/example2_spec.rb
describe 'Example 2' do
it 'A2' do
expect(true).to be true
end
it 'B2' do
expect(true).to be true
end
end
# spec/example3_spec.rb
describe 'Example 3' do
it 'A3' do
expect(true).to be true
end
it 'B3' do
expect(true).to be true
end
end
Script to run tests:
# run_tests.rb
puts 'Run tests'
require 'rspec/core'
def start_runner(cli_args)
puts '-'*50
args = ['--format', 'documentation'] + cli_args
options = RSpec::Core::ConfigurationOptions.new(args)
RSpec::Core::Runner.new(options).run($stderr, $stdout)
RSpec.clear_examples
end
cli_args = ['spec/example_spec.rb[1:1]', 'spec/example2_spec.rb']
start_runner(cli_args)
cli_args = ['spec/example_spec.rb[1:2]', 'spec/example3_spec.rb']
start_runner(cli_args)
Expected behavior
$ ruby run_tests.rb
Run tests
--------------------------------------------------
Run options: include {:ids=>{"./spec/example_spec.rb"=>["1:1"]}}
Example 1
A1
Example 2
A2
B2
Finished in 0.00182 seconds (files took 0.16182 seconds to load)
3 examples, 0 failures
--------------------------------------------------
Run options: include {:ids=>{"./spec/example_spec.rb"=>["1:2"]}}
Example 1
B1 <---- example B1 should run here
Example 3
A3
B3
Finished in 0.00056 seconds (files took 0.00535 seconds to load)
2 examples, 0 failures
Actual behavior
$ ruby run_tests.rb
Run tests
--------------------------------------------------
Run options: include {:ids=>{"./spec/example_spec.rb"=>["1:1"]}}
Example 1
A1
Example 2
A2
B2
Finished in 0.00182 seconds (files took 0.16182 seconds to load)
3 examples, 0 failures
--------------------------------------------------
Run options: include {:ids=>{"./spec/example_spec.rb"=>["1:2"]}}
Example 3
A3
B3
Finished in 0.00056 seconds (files took 0.00535 seconds to load)
2 examples, 0 failures