Thoughts on making spec type inference extendable?

11 views
Skip to first unread message

brent.w...@gmail.com

unread,
Dec 3, 2018, 12:31:23 PM12/3/18
to rspec
Hi there,

We have a bunch of similar specs that share helpers in a subdirectory of `spec/` and were wondering if we could just extend rspec-rails' type inference based on the spec file's location to give them all a specific "type" and include helpers based on that type. When we popped open the source code we found that the mapping of types to locations happens in a hash constant (`RSpec::Rails::DIRECTORY_MAPPINGS`) that is marked as private.

Would the maintainers be open to a PR that opened up a public API for registering new type/file location configurations? If so I'd be happy to open something!

Cheers,

Brent

brent.w...@gmail.com

unread,
Dec 3, 2018, 12:38:18 PM12/3/18
to rspec
Of course as soon as I posted this I found `RSpec::Core::Configuration#define_derived_metadata` which will do exactly what we want without muddling the `rspec-rails` magic so I'm going to go that route for now. If folks think making the type inference API extendable, though, I'd be happy open a PR.

Jon Rowe

unread,
Dec 3, 2018, 12:48:33 PM12/3/18
to rs...@googlegroups.com
Hi Brent

We don’t actually want to extend the type inference api, as we consider it a legacy feature at this point, explicit meta data is far more readable and less magic. 

So an alternative solution would be to tag the top level describes with the key, or keys you wish to trigger these shared examples, and have them automatically included via the metadata filtering. The docs you may be looking for are here: https://relishapp.com/rspec/rspec-core/v/3-8/docs/helper-methods/define-helper-methods-in-a-module

Cheers
Jon Rowe
---------------------------
Reply all
Reply to author
Forward
0 new messages