-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Get rid of the code poking around RSpec's internals #2365
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
Conversation
So we shouldn't be doing this:
We're reaching into RSpec's internals and this gem is no longer supposed to be doing that. I would like us to eliminate this, and if that requires refactoring the world to not be so global, thats a good thing. |
I think I've found a better solution. |
Better viewed as https://github.com/rspec/rspec-rails/pull/2365/files?diff=split&w=1 |
spec/spec_helper.rb
Outdated
end | ||
|
||
config.include RSpec::Rails::FeatureCheck |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was included in Helpers
that didn't hesitate to include itself in RSpec.configuration
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean does it have any effect? It can't have been used very often...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
36 failures, 100% in generator specs, all undefined method 'type_metatag'
.
Besides type_metatag
, generator specs use no methods from FeatureCheck
.
I'll include this module exclusively to generator specs.
Frankly, I don't see a good reason for this method to exist:
def type_metatag(type)
"type: :#{type}"
end
but I'd prefer to avoid this unrelated refactoring here.
spec/spec_helper.rb
Outdated
end | ||
|
||
config.include RSpec::Rails::FeatureCheck |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean does it have any effect? It can't have been used very often...
spec/spec_helper.rb
Outdated
end | ||
|
||
config.include RSpec::Rails::FeatureCheck, type: :generator |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we not just include this where it's used?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can, but type_metatag
is used in every one of them except for install generator spec.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I intended to get rid of this method altogether, replacing all usages to type: :some_type
, and this include
as well.
Ok to keep it here and remove in a follow-up?
Or keep type_metatag
and inline include
s into generator specs?
Or keep this include as is and leave type_metatag
alone?
I don't have a preference here, up to you.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So you can remove this from here, and add it here:
module RSpec
module Rails
module Specs
module Generators
module Macros
# spec/support/generators.rb:18
def self.included(klass)
klass.extend(Macros)
klass.include(RSpec::Rails::FeatureCheck)
end
Which I think is neater until a later refactoring is done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point. Done.
Our previous code was prone to out-of-sync worlds: with_isolated_config do RSpec::Core::ExampleGroup.describe('a view') { it { } } RSpec.configuration.world.example_groups # => [] end
Problem
We used to access and replace
RSpec.configuration
andRSpec.world
in several places.This was prone to error, since those two can run out of sync, e.g.:
This case specifically is due to in
RSpec::Core::ExampleGroup.describe
:Also, we were using this:
RSpec::Core::Configuration.new
gets its own world:which is an
RSpec::Core::World::Null
.I have strong doubts if it would make sense to change the Core to:
Not to say that those hooks and helpers dig too deep into RSpec's internals.
Solution
It's our lucky day! RSpec provides sandboxing out of the box.