Skip to content

Please allow passing :caller into Metadata to make life easier for extensions

gitlab-qa-bot requested to merge github/fork/glv/master into master

Created by: glv

A recent change to rspec-core broke rspec-unit in a rather ugly way. This pull request would put things right without losing the benefits of the earlier change.

rspec/rspec-core@f78ff619e5e07dc099646444b08d7654516f9666 changed the way location metadata is discovered. Part of that change meant that the caller trace is no longer passed into Metadata from outside. I agree that it shouldn't be required, but it would be very helpful it it could be passed in from outside.

The fix in rspec-unit is fairly ugly, and that leads me to suspect that it may make other kinds of RSpec extensions more difficult.

glv/rspec-unit@851160bc2cc8b53fd19b7b1c3a69a854a8267e61 shows what I had to do to rspec-unit to deal with this. In test_case.rb, I have to let RSpec set all the metadata for examples and example groups, and then override :file_path, :line_number, and :location. And I have to do that by calling two private methods on ExampleGroup (#file_and_line_number_from and #location_from). Yuck.

This pull requests allows callers of ExampleGroup.set_it_up and Example.new to optionally pass in the caller trace.

Merge request reports