Module: WithPublic

Defined in:
lib/with_public.rb,
lib/with_public/version.rb

Overview

A module to define with_public method to Module class. With this module, one can test private methods without Object#send.

Constant Summary collapse

VERSION =
'1.0.0'

Instance Method Summary collapse

Instance Method Details

#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