-
-
Notifications
You must be signed in to change notification settings - Fork 753
Add before_register hook to RSpec World #2094
Conversation
# Invokes block before registering an example group | ||
def before_register(&block) | ||
before_register_callbacks << block | ||
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.
I think this should go on config instead of world. Config is where we let users configure callbacks.
Also, example group registration isn't really a concept we've exposed into our API up to now. It's purely an internal. I think that this feature would fit better with RSpec's terminology if it was something like on_example_group_definition
, e.g.:
RSpec.configure do |c|
c.on_example_group_definition do |example_group|
# do something with the newly defined example group
end
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.
Makes sense. I'll fix.
I updated the PR to use |
@bootstraponline I think what you have here is reasonable as far as a way to hook in to example group creation in RSpec. But to generate additional examples that are essentially clones of existing ones w/ some modifications, we should provide you with some new APIs. Here's what I'm thinking...
Then for your case I think you could do something like this: RSpec.configure do |config|
config. on_example_group_definition do |group|
group.examples.each do |example|
group.remove_example example
[{:browserName => :firefox}, {:browserName => :chrome}].each do |cap|
group.add_example example.duplicate_with(:cap => cap)
end
end
end
end Thoughts? |
That looks awesome! |
Want to open up PRs adding those APIs? (and/or add them to this one)? |
I think they're better as independent PRs. I'll work on submitting a new PR for add_example/remove_example should be easy. duplicate_with is a bit more tricky since rspec will delete tests if they share the same id so I'll have to change it to something else (maybe add a hash of the metadata?). |
I'd recommend not doing anything with the ids. In fact, don't even use rspec-core/lib/rspec/core/example_group.rb Lines 139 to 145 in b8f0270
In fact, it might be as simple as: Example.new(example.example_group_class, example.description, example.metadata, example.example_block) |
Ok, I'll try it. |
I squashed to one commit and Travis is passing. appveyor had an internal server error unrelated to the PR. |
I submitted #2095 for add/remove example. Working on duplicate_with next. |
LGTM |
Add before_register hook to RSpec World
Add before_register hook to RSpec World
Fix #2078
Use case:
Enables running an unmodified test suite on multiple Selenium browsers.