-
-
Notifications
You must be signed in to change notification settings - Fork 760
Adds hook scope aliases example
and context
#1174
Conversation
elsif args.any? { |a| a.is_a?(Symbol) } | ||
raise ArgumentError.new("You must explicitly give a scope (:each, :all, or :suite) when using symbols as metadata for a hook.") | ||
raise ArgumentError.new("You must explicitly give a scope (:each, :all, or :suite) or scope alias (:example or :context) when using symbols as metadata for a hook.") |
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's also technically feasible to add scopes. Should we add that too?
I've updated the PR to accommodate @JonRowe's feedback. |
:example => :each, | ||
:context => :all, | ||
} | ||
end |
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.
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.configure
blocks 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
:example
as an alias for:each
and:context
as an alias for:all
.See #297 for further discussion.