Module: RSpec::ExampleGroups Private
Do not use. This module is for internal use only.
Relationships & Source Files | |
Super Chains via Extension / Inclusion / Inheritance | |
Class Chain:
|
|
Defined in: | rspec-core/lib/rspec/core/example_group.rb |
Overview
Namespace for the example group subclasses generated by top-level describe
.
Class Method Summary
- .assign_const(group) Internal use only
-
.base_name_for(group)
(also: ._base_name_for)
See additional method definition at line 862.
- .constant_scope_for(group) Internal use only
- .disambiguate(name, const_scope) Internal use only
- .remove_all_constants Internal use only
-
._base_name_for(group)
private
Alias for .base_name_for.
Support::RecursiveConstMethods
- Extended
const_defined_on? | See additional method definition at line 31. |
constants_defined_on | See additional method definition at line 41. |
get_const_defined_on | See additional method definition at line 35. |
normalize_const_name, recursive_const_defined?, recursive_const_get |
Class Method Details
._base_name_for(group) (private)
Alias for .base_name_for.
# File 'rspec-core/lib/rspec/core/example_group.rb', line 886
alias _base_name_for base_name_for
.assign_const(group)
[ GitHub ]# File 'rspec-core/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) Also known as: ._base_name_for
See additional method definition at line 862.
# File 'rspec-core/lib/rspec/core/example_group.rb', line 887
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)
[ GitHub ]# File 'rspec-core/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)
[ GitHub ]# File 'rspec-core/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_constants
[ GitHub ]# File 'rspec-core/lib/rspec/core/example_group.rb', line 856
def self.remove_all_constants constants.each do |constant| __send__(:remove_const, constant) end end