Module: RSpec::ExampleGroups

Extended by:
Support::RecursiveConstMethods
Defined in:
lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-core-3.12.0/lib/rspec/core/example_group.rb

Overview

Namespace for the example group subclasses generated by top-level ‘describe`.

Class Method Summary collapse

Methods included from Support::RecursiveConstMethods

const_defined_on?, constants_defined_on, get_const_defined_on, normalize_const_name, recursive_const_defined?, recursive_const_get

Class Method Details

.assign_const(group) ⇒ Object



842
843
844
845
846
847
848
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-core-3.12.0/lib/rspec/core/example_group.rb', line 842

def self.assign_const(group)
  base_name   = base_name_for(group)
  const_scope = constant_scope_for(group)
  name        = disambiguate(base_name, const_scope)

  const_scope.const_set(name, group)
end

.base_name_for(group) ⇒ Object



862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-core-3.12.0/lib/rspec/core/example_group.rb', line 862

def self.base_name_for(group)
  return "Anonymous".dup if group.description.empty?

  # Convert to CamelCase.
  name = ' ' + group.description
  name.gsub!(/[^0-9a-zA-Z]+([0-9a-zA-Z])/) do
    match = ::Regexp.last_match[1]
    match.upcase!
    match
  end

  name.lstrip!                # Remove leading whitespace
  name.gsub!(/\W/, ''.freeze) # JRuby, RBX and others don't like non-ascii in const names

  # Ruby requires first const letter to be A-Z. Use `Nested`
  # as necessary to enforce that.
  name.gsub!(/\A([^A-Z]|\z)/, 'Nested\1'.freeze)

  name
end

.constant_scope_for(group) ⇒ Object



850
851
852
853
854
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-core-3.12.0/lib/rspec/core/example_group.rb', line 850

def self.constant_scope_for(group)
  const_scope = group.superclass
  const_scope = self if const_scope == ::RSpec::Core::ExampleGroup
  const_scope
end

.disambiguate(name, const_scope) ⇒ Object



895
896
897
898
899
900
901
902
903
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-core-3.12.0/lib/rspec/core/example_group.rb', line 895

def self.disambiguate(name, const_scope)
  return name unless const_defined_on?(const_scope, name)

  # Add a trailing number if needed to disambiguate from an existing
  # constant.
  name << "_2"
  name.next! while const_defined_on?(const_scope, name)
  name
end

.remove_all_constantsObject



856
857
858
859
860
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-core-3.12.0/lib/rspec/core/example_group.rb', line 856

def self.remove_all_constants
  constants.each do |constant|
    __send__(:remove_const, constant)
  end
end