Module: RSpec::ExampleGroups
- Defined in:
- opal/opal/rspec/fixes/rspec/example_groups.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
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'opal/opal/rspec/fixes/rspec/example_groups.rb', line 3 def self.base_name_for(group) return "Anonymous" if group.description.empty? # convert to CamelCase name = ' ' + group.description # replaced gsub! with name = name.gsub (mutable strings) name = name.gsub(/[^0-9a-zA-Z]+([0-9a-zA-Z])/) { Regexp.last_match[1].upcase } # mutable strings on these 2 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.gsub!(/\A([^A-Z]|\z)/, 'Nested\1') # opal-rspec, mutable strings, also substituted in ^ for \A since \A and $ for \z is not supported in JS regex name = name.gsub(/^([^A-Z]|$)/, 'Nested\1') name end |
.disambiguate(name, const_scope) ⇒ Object
opal cannot use mutable strings
26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'opal/opal/rspec/fixes/rspec/example_groups.rb', line 26 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 = name + "_2" while const_defined_on?(const_scope, name) name = name.next end name end |