varvet / pundit

Minimal authorization through OO design and pure Ruby classes
MIT License
8.24k stars 627 forks source link

Reasons for rspec patching in the main namespace? #668

Closed metacritical closed 2 years ago

metacritical commented 3 years ago

So i was pointed out to the Pundit source, and i am just curious if patching Rspec inside Pundit namespace would be considered "namespace pollution" ? Also what are some merits and demerits to this design approach?

module Pundit
  module RSpec
    module Matchers
      extend ::RSpec::Matchers::DSL
dgmstuart commented 2 years ago

Thanks for the comment.

I think there's a misunderstanding here: we're not opening up RSpec and modifying the behaviour (so-called "monkeypatching") - instead we're defining our own module Pundit::RSpec::Matchers, which includes behaviour from an RSpec module.

We name the module in this way to make it clear that it contains matchers which are compatible with RSpec, but the module is completely separate from the RSpec code.

Does that make sense?