Module: RSpec::Support::WithKeywordsWhenNeeded

Defined in:
lib/rspec/support/with_keywords_when_needed.rb

Instance Method Summary collapse

Instance Method Details

#class_exec(klass, *args, &block) ⇒ Object

Remove this in RSpec 4 in favour of explicitly passed in kwargs where this is used. Works around a warning in Ruby 2.7



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

def class_exec(klass, *args, &block)
  if MethodSignature.new(block).has_kw_args_in?(args)
    binding.eval(<<-CODE, __FILE__, __LINE__)
    kwargs = args.pop
    klass.class_exec(*args, **kwargs, &block)
    CODE
  else
    klass.class_exec(*args, &block)
  end
end