-
-
Notifications
You must be signed in to change notification settings - Fork 762
How to run second test example with RSpec::Core::Runner for the same test file #2721
Comments
Hi @myronmarston , I saw you shared some knowledge with a bit similar problem rspec/rspec#27 Maybe you will be able to point me where to look for? Thank you. |
Hey @ArturT! |
You've only cleared your examples, not your filters, so you end up building combined filters. There is a private api on configuration to reset your filters, but the public way to fix this is to change |
@pirj @JonRowe Thank you for the help. The
I added I suspect RSpec config from options = RSpec::Core::ConfigurationOptions.new(cli_args)
RSpec.configuration.load_spec_files
RSpec::Core::Runner.new(options).run($stderr, $stdout)
RSpec.reset I'm not sure what's the good direction to go. Should I somehow try to force Ruby to reload the content of Any tips would be great. Thank you. |
Yes However you can also use |
@JonRowe Thanks for tips. I can't find a definition for There is a method I found that clear_examples already calls |
I'm too bumping into the same issue when using (Note: I've tried Anyway, I did some digging around and this is what I've found so far. The reason that the example is not executed, is not because the filters are wrong. It's because the example metadata that RSpec populates are wrong, the second time the file is loaded. So if you have a spec file like this: # foo_spec.rb
describe "foo"
it "bar" do
expect(true).to be true
end
end The expected filter to run the example would be 2.times do
RSpec.clear_examples
RSpec.world.prepare_example_filtering
opts = RSpec::Core::ConfigurationOptions.new(["foo_spec[1:1]"])
RSpec::Core::Runner.new(opts).run($stdout, $stderr)
end The filter ( rspec-core/lib/rspec/core/metadata.rb Lines 185 to 189 in b77634d
That rspec-core/lib/rspec/core/world.rb Lines 34 to 38 in b77634d
So I haven't had the time to investigate further, so I don't know if there's anything that we can do in RSpec to make it handle such cases in a backwards compatible way. I'm not even sure that this behavior of the @JonRowe, @pirj, @myronmarston any ideas? |
The issue you've encountered @agis is due to the filters not reseting between runs, |
@JonRowe To make sure I understand, by "filters" you're referring # 1st iteration/run
=> #<RSpec::Core::FilterManager:0x000055698a282028
@exclusions=
#<RSpec::Core::FilterRules:0x000055698a282000
@opposite=#<RSpec::Core::InclusionRules:0x000055698a281fb0 @opposite=#<RSpec::Core::FilterRules:0x000055698a282000 ...>, @rules={:ids=>{"./spec/controllers/validation_controller_spec.rb"=>["1:1:1"]}}>,
@rules={}>,
@inclusions=
#<RSpec::Core::InclusionRules:0x000055698a281fb0
@opposite=#<RSpec::Core::FilterRules:0x000055698a282000 @opposite=#<RSpec::Core::InclusionRules:0x000055698a281fb0 ...>, @rules={}>,
@rules={:ids=>{"./spec/controllers/validation_controller_spec.rb"=>["1:1:1"]}}>>
# 2nd iteration/run
=> #<RSpec::Core::FilterManager:0x000055699d80f0c8
@exclusions=
#<RSpec::Core::FilterRules:0x000055699d80f0a0
@opposite=#<RSpec::Core::InclusionRules:0x000055699d80f050 @opposite=#<RSpec::Core::FilterRules:0x000055699d80f0a0 ...>, @rules={:ids=>{"./spec/controllers/validation_controller_spec.rb"=>["1:1:1"]}}>,
@rules={}>,
@inclusions=
#<RSpec::Core::InclusionRules:0x000055699d80f050
@opposite=#<RSpec::Core::FilterRules:0x000055699d80f0a0 @opposite=#<RSpec::Core::InclusionRules:0x000055699d80f050 ...>, @rules={}>,
@rules={:ids=>{"./spec/controllers/validation_controller_spec.rb"=>["1:1:1"]}}>> They do seem set up properly to me, but perhaps I'm missing something? |
Ah sorry I think I'm getting two people confused here, if the id is generating |
Good to know, I've found the culprit and I'm opening a new PR soon. |
Glad you discovered this @agis. We've found this behavior was interrupting with our use case, too (as we are also working on a solution that is reusing the runner and wanted to avoid reloading the whole config). At the time we didn't think the lack of reset for the count was a bug - just thought our use case lies outside of what RSpec interface expects. Glad this has been cleared up! For what it's worth, we ended up resetting the hash by the hacky |
@shadre wow, that would've definitely saved me 2 or 3 hours of debugging 😅 Nevertheless it's good to know you've found the solution. |
Yeah, I'm gutted to know you could have avoided that. :( Glad you too got it working, though! |
Make World.reset also reset example group counts
Make World.reset also reset example group counts
If we don't reset example group counts in custom runners that run from the same process, example metadata end up being published with incorrect scoped IDs. World#example_group_counts_by_spec_file is merely added for testability. Fixes rspec#2721
Make World.reset also reset example group counts
…-core#2721-world-reset Make World.reset also reset example group counts --- This commit was imported from rspec/rspec-core@16f21bd.
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-processI 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 exampleB1
from the test filespec/example_spec.rb
for which we already run first test exampleA1
but the second test exampleB1
is ignored. I don't know how to force RSpec to runB1
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
Steps to reproduce
Source code: https://github.com/ArturT/rspec-test-examples
Script to run tests:
Expected behavior
Actual behavior
The text was updated successfully, but these errors were encountered: