Adds hook scope aliases example and context#1174
Conversation
lib/rspec/core/hooks.rb
Outdated
There was a problem hiding this comment.
Given that it's technically feasible to add scope aliases, perhaps this should enumerate the keys of scope_aliases rather than hard code them?
There was a problem hiding this comment.
It's also technically feasible to add scopes. Should we add that too?
|
I've updated the PR to accommodate @JonRowe's feedback. |
lib/rspec/core/hooks.rb
Outdated
There was a problem hiding this comment.
Is there any reason this is a method and not a constant? This feels like it should be a constant (since it doesn't do any calculation or call any methods to create the hash).
|
Two other general suggestions:
|
|
uhhhh? @myronmarston: I believe u want @fj, and not me? If so, could you pls correct that mention? thanks. |
Yep, sorry about that! |
Deprecating That should be a different PR (imo).
This is a good suggestion, and I agree that we shouldn't be namespace-squatting like that. I will make this change later and update the PR accordingly. |
I agree. I think the ROI on deprecating (and eventual removal) of |
|
Leaving |
|
Also this looks ready to go in my eyes, we can do the docs etc separately. |
|
I still need to do @myronmarston's second suggestion. The PR hasn't been
|
|
BTW, since we'll have to lift I can't find any existing examples of this in the RSpec codebase and there's lots of ways to skin that cat, so I figured I'd ask first about what your preference is. |
Not sure I follow. Constants are accessible to class methods and instance methods: class Foo
CONST = 3
def can_access_const
CONST
end
def self.can_access_const
CONST
end
end |
|
@myronmarston Sorry, it was late when I wrote that and I was tired, and I'm not sure what I meant either. You are correct, of course. |
|
No worries :). |
Adds hook scope aliases `example` and `context`
This allows for nicer, more sensible naming in the context of
RSpec.configureblocks and elsewhere.For example, this block sounds like it's a hook that runs once, before any example:
But it's actually a hook that runs once before every context, which is confusing. So a better name would be:
This change adds, in hook scopes, the ability to use
:exampleas an alias for:eachand:contextas an alias for:all.See #297 for further discussion.