Module: RSpec::ExampleGroups
- Defined in:
- opal/opal/rspec/fixes.rb
Class Method Summary collapse
-
.base_name_for(group) ⇒ Object
opal cannot use mutable strings AND opal doesnt support
\A
or\z
anchors. -
.disambiguate(name, const_scope) ⇒ Object
opal cannot use mutable strings.
Class Method Details
.base_name_for(group) ⇒ Object
opal cannot use mutable strings AND opal doesnt support \A
or \z
anchors
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'opal/opal/rspec/fixes.rb', line 26 def self.base_name_for(group) return "Anonymous" if group.description.empty? # convert to CamelCase name = ' ' + group.description name = name.gsub(/[^0-9a-zA-Z]+([0-9a-zA-Z])/) { |m| m[1].upcase } name = name.lstrip # Remove leading whitespace name = name.gsub(/\W/, '') # 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 = name.gsub(/^([^A-Z]|$)/, 'Nested\1') name end |
.disambiguate(name, const_scope) ⇒ Object
opal cannot use mutable strings
44 45 46 47 48 49 50 51 52 53 54 |
# File 'opal/opal/rspec/fixes.rb', line 44 def self.disambiguate(name, const_scope) return name unless const_scope.const_defined?(name) # Add a trailing number if needed to disambiguate from an existing constant. name = name + "_2" while const_scope.const_defined?(name) name = name.next end name end |