Method: WithPublic#with_public

Defined in:
lib/with_public.rb

#with_public(*methods) ⇒ Module

Returns a refiner module to make target methods public

Examples:

Make Foo#bar public

RSpec.describe Foo do
  using Foo.with_public(:bar)
  # Calling Foo#bar will not raise NoMethodError in this context.
end

Parameters:

  • methods (Array<Symbol>)

    Method symbols to be made public

Returns:

  • (Module)

    a refinement module to make given methods public



17
18
19
20
21
22
23
24
25
26
# File 'lib/with_public.rb', line 17

def with_public(*methods)
  target = self
  Module.new.tap do |refiner|
    refiner.module_eval do
      refine target do
        public(*methods)
      end
    end
  end
end