Skip to content

Minor improvements #2362

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

Merged
merged 3 commits into from
Jul 27, 2020
Merged

Minor improvements #2362

merged 3 commits into from
Jul 27, 2020

Conversation

pirj
Copy link
Member

@pirj pirj commented Jul 25, 2020

Follow-up to #2360

Explanations in commit messages.

pirj added 2 commits July 25, 2020 03:16
This happens in some circumstances:

    bundle exec rails new ./tmp/example_app --no-rc --skip-javascript --skip-bootsnap --skip-sprockets --skip-git --skip-test-unit --skip-listen --skip-bundle --template=example_app_generator/generate_app.rb

        Gem::RuntimeRequirementNotMetError: spring requires Ruby version >= 2.4.0. The current ruby version is 2.3.0.
        An error occurred while installing spring (2.1.0), and Bundler cannot continue.
@pirj pirj self-assigned this Jul 25, 2020
@pirj pirj requested review from JonRowe and benoittgt July 25, 2020 01:03
@@ -4,6 +4,7 @@ module Helpers
def with_isolated_config
original_config = RSpec.configuration
RSpec.configuration = RSpec::Core::Configuration.new
RSpec.configuration.world = RSpec.world
Copy link
Member

Choose a reason for hiding this comment

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

The whole point of isolated configuration is to be isolated from the global test run, we don't want the child configuration sharing the parent world, else those specs get counted in various places. What were you seeing that made you want to do this?

Copy link
Member Author

Choose a reason for hiding this comment

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

Sorry, I disagree. with_isolated_config sounds like the configuration is isolated, not that what is inside the block should be in a different world.

We wrap each example to run in its own world:

  config.around(:example) do |example|
    real_world = RSpec.world
    RSpec.instance_variable_set(:@world, RSpec::Core::World.new)
    example.run
    RSpec.instance_variable_set(:@world, real_world)
  end

Also, all current usages of with_isolated_config wrap the whole example it is used in, there are no separate "inside" and "outside" example parts that would be prone to affect each other.

WDYT of making with_isolated_config a metadata-induced around hook to make this more obvious?

Copy link
Member

Choose a reason for hiding this comment

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

Wow I had no idea we did that, ok, well you need that world, I don't think you can rely on the global here...

Copy link
Member Author

@pirj pirj Jul 26, 2020

Choose a reason for hiding this comment

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

So it seems that the real problem, that prevents us from using a unique isolated configuration is in RSpec::Core::ExampleGroup.describe:

RSpec.world.example_groups

Should it be a RSpec.configuration.world.example_groups?

This results in the following when called from within with_isolated_config:

image

I don't think you can rely on the global here...

The whole point is that I don't rely on the global, real one. The global is kept in real_world during the examples, and RSpec.world is assigned (using instance_variable_set) a World.new.
But RSpec::Core::Configuration.new gets its own world:

  def with_isolated_config
    original_config = RSpec.configuration
    RSpec.configuration = RSpec::Core::Configuration.new

which is an RSpec::Core::World::Null.

I strongly doubt it would make sense to change the Core to:

- RSpec.world.example_groups
+ RSpec.configuration.world.example_groups

But in this case, setting an isolated world initialized specifically for this example to an isolated config that was also initialized for this example makes total sense.

Copy link
Member

Choose a reason for hiding this comment

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

Can you drop this change for now, and open another PR to work on this? I'm happy to merge the rest of these changes, but I'd like to look at this a bit more

Copy link
Member Author

Choose a reason for hiding this comment

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

Makes sense. Done.

group.run(failure_reporter)
expect(failure_reporter.exceptions).to eq []
expect(run_count).to eq 1
group = RSpec::Core::ExampleGroup.describe 'a view', type: :view do
Copy link
Member

Choose a reason for hiding this comment

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

Can you restore this, it was a regression check specifically for configuration hooks added (7 years ago!!) in #833

Copy link
Member Author

Choose a reason for hiding this comment

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

Aha, got it 👍

Copy link
Member

Choose a reason for hiding this comment

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

Happy for the doc string / or a comment to be changed to mention this though, as I had to check to find it 😂

The example is hard to comprehend

In this example, we're making sure that `view` is available in hooks.
There's no big difference in globally defined hooks and local hooks, so
it's not necessary to define one on the `configuration`, and thus
`with_isolated_config` becomes unnecessary as well.
@pirj pirj force-pushed the minor-improvements branch from 5b6c3d6 to 9ed3e46 Compare July 26, 2020 11:26
@pirj pirj requested a review from JonRowe July 26, 2020 16:57
@JonRowe JonRowe mentioned this pull request Jul 27, 2020
1 task
@pirj pirj force-pushed the minor-improvements branch from 9ed3e46 to c75b172 Compare July 27, 2020 22:01
@pirj pirj merged commit 7f0c6c9 into master Jul 27, 2020
@pirj pirj deleted the minor-improvements branch July 27, 2020 23:14
JonRowe pushed a commit that referenced this pull request Aug 3, 2020
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.

3 participants