Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make World.reset also reset example group counts #2723

Merged
merged 1 commit into from May 2, 2020
Merged

Make World.reset also reset example group counts #2723

merged 1 commit into from May 2, 2020

Conversation

agis
Copy link
Contributor

@agis agis commented Apr 24, 2020

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 #2721

@JonRowe
Copy link
Member

JonRowe commented Apr 24, 2020

Can we get a spec for this? Something along the lines of creating a world, adding some examples and showing that the hash is not 0 unless reset?

@agis
Copy link
Contributor Author

agis commented Apr 24, 2020

@JonRowe I was instead thinking something on a higher-level, like:

require "rspec/core"
require "stringio"

# RSpec.describe "foo" do
#   it "bar" do
#     expect(true).to be true
#   end
# end

def truncate_timings(output)
	output.gsub(/Finished in.*\n/, '')
end

expected_output = StringIO.new
actual_output = StringIO.new

opts = RSpec::Core::ConfigurationOptions.new(["./foo_spec.rb[1:1]"])
RSpec::Core::Runner.new(opts).run(nil, $stderr)
expected_output = truncate_timings(expected_output.string)

RSpec.clear_examples

opts = RSpec::Core::ConfigurationOptions.new(["./foo_spec.rb[1:1]"])
# without the fix, the following invocation executes 0 examples
RSpec::Core::Runner.new(opts).run(nil, $stderr)
actual_output = truncate_timings(actual_output.string)

# expected_output == actual_output

Thoughts? I think this way it's more apparent what the fix is about.

If that seems good, could you point me to some similar specs from RSpec's codebase which I can follow as examples?

That said, I don't really like the part with comparing the outputs, perhaps there's a more future-proof way of doing this? The point is to verify that the correct example ran once in each invocation.

@JonRowe
Copy link
Member

JonRowe commented Apr 29, 2020

We have a bunch of integration specs in spec/integration might be worth putting something together like you describe, I would also like a unit level spec that says that this count is reset after reset too though..

@agis
Copy link
Contributor Author

agis commented Apr 30, 2020

We have a bunch of integration specs in spec/integration might be worth putting something together like you describe, I would also like a unit level spec that says that this count is reset after reset too though..

We have a bunch of integration specs in spec/integration might be worth putting something together like you describe, I would also like a unit level spec that says that this count is reset after reset too though..

@JonRowe Added unit and integration specs (see #2723 (comment) though).

Copy link
Member

@JonRowe JonRowe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work, some stylistic changes and a fix for your aruba issue.

spec/integration/filtering_spec.rb Outdated Show resolved Hide resolved
spec/integration/filtering_spec.rb Outdated Show resolved Hide resolved
spec/integration/filtering_spec.rb Outdated Show resolved Hide resolved
spec/integration/filtering_spec.rb Outdated Show resolved Hide resolved
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 #2721
Copy link
Member

@JonRowe JonRowe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great! I'll merge on green, thanks so much! 💜 ❤️ 💚 💛 🧡

@JonRowe JonRowe merged commit 34d907e into rspec:master May 2, 2020
@agis agis deleted the gh-2721-world-reset branch May 2, 2020 17:28
JonRowe added a commit that referenced this pull request May 2, 2020
JonRowe added a commit that referenced this pull request May 2, 2020
Make World.reset also reset example group counts
JonRowe added a commit that referenced this pull request May 2, 2020
agis added a commit to skroutz/rspecq that referenced this pull request Aug 8, 2020
That is fortunately only needed in rspec-core versions equal or less than 3.9.1,
since 3.9.2 includes the relevant fix[1].

[1] rspec/rspec-core#2723
agis added a commit to skroutz/rspecq that referenced this pull request Aug 8, 2020
That is fortunately only needed in rspec-core versions equal or less than 3.9.1,
since 3.9.2 includes the relevant fix[1].

[1] rspec/rspec-core#2723
agis added a commit to skroutz/rspecq that referenced this pull request Aug 8, 2020
This is fortunately only needed in rspec-core versions equal or less than 3.9.1,
since 3.9.2 includes the relevant fix[1].

[1] rspec/rspec-core#2723
MatheusRich pushed a commit to MatheusRich/rspec-core that referenced this pull request Oct 30, 2020
Make World.reset also reset example group counts
MatheusRich pushed a commit to MatheusRich/rspec-core that referenced this pull request Oct 30, 2020
yujinakayama pushed a commit to yujinakayama/rspec-monorepo that referenced this pull request Oct 6, 2021
…-core#2721-world-reset

Make World.reset also reset example group counts

---
This commit was imported from rspec/rspec-core@16f21bd.
yujinakayama pushed a commit to yujinakayama/rspec-monorepo that referenced this pull request Oct 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

How to run second test example with RSpec::Core::Runner for the same test file
2 participants