Module: Selective::Ruby::RSpec::Monkeypatches

Defined in:
lib/selective/ruby/rspec/monkeypatches.rb

Defined Under Namespace

Modules: Configuration, Example, Hooks, MetaHashPopulator, RSpec, Reporter, RequireEachHooks, Runner, World

Constant Summary collapse

MAP =
{
  "BaseTextFormatter" => [:message, :dump_pending, :seed, :close],
  "ProgressFormatter" => [:start_dump],
  "DocumentationFormatter" => [:message],
  "ProfileFormatter" => [:dump_profile]
}
HOOKS =
%i(before prepend_before after append_after)

Class Method Summary collapse

Class Method Details

.apply(config) ⇒ Object



191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
# File 'lib/selective/ruby/rspec/monkeypatches.rb', line 191

def self.apply(config)
  ::RSpec::Support.require_rspec_core("formatters/base_text_formatter")

  MAP.each do |module_name, _methods|
    ::RSpec::Core::Formatters
      .const_get(module_name)
      .prepend(Selective::Ruby::RSpec::Monkeypatches.const_get(module_name))
  end

  # We'd like to prepend to ::RSpec::Core::Hooks here but there is
  # a bug in < Ruby 3.0 that prevents us from doing so. Instead,
  # we extend the ExampleGroup class which is where the Hooks module
  # is included.
  if config[:require_each_hooks]
    ::RSpec::Core::ExampleGroup.extend(RequireEachHooks)
  else
    ::RSpec::Core::ExampleGroup.extend(Hooks)
  end

  ::RSpec.singleton_class.prepend(RSpec)
  ::RSpec::Core::Reporter.prepend(Reporter)
  ::RSpec::Core::Configuration.prepend(Configuration)
  ::RSpec::Core::World.prepend(World)
  ::RSpec::Core::Runner.prepend(Runner)
  ::RSpec::Core::Example.prepend(Example)
  ::RSpec::Core::Metadata::HashPopulator.prepend(MetaHashPopulator)
end