Sha256: 2bcf61807fec98e0d31f2e294c513d93f7be911d2755978fc894247efb6f9959

Contents?: true

Size: 1.11 KB

Versions: 7

Compression:

Stored size: 1.11 KB

Contents

class ::RSpec::Core::Formatters::Loader
  def string_const?(str)
    # Incompatible regex (\A flag and \z flag)
    # str.is_a?(String) && /\A[A-Z][a-zA-Z0-9_:]*\z/ =~ str
    str.is_a?(String) && /^[A-Z][a-zA-Z0-9_:]*$/ =~ str
  end

  def underscore(camel_cased_word)
    # string mutation
    word = camel_cased_word.to_s.dup
    word = word.gsub(/::/, '/')
    word = word.gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
    word = word.gsub(/([a-z\d])([A-Z])/, '\1_\2')
    word = word.tr("-", "_")
    word.downcase
  end

  def custom_formatter(formatter_ref)
    if Class === formatter_ref
      formatter_ref
    elsif string_const?(formatter_ref)
      # retry not supported on opal
      # begin
      #   formatter_ref.gsub(/^::/, '').split('::').inject(Object) { |a, e| a.const_get e }
      # rescue NameError
      #   require(path_for(formatter_ref)) ? retry : raise
      # end
      while true
        begin
          return formatter_ref.gsub(/^::/, '').split('::').inject(Object) { |a, e| a.const_get e }
        rescue NameError
          raise unless require(path_for(formatter_ref))
        end
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 2 rubygems

Version Path
opal-rspec-0.6.2 opal/opal/rspec/fixes/rspec/core/formatters/loader.rb
opal-rspec-0.6.1 opal/opal/rspec/fixes/rspec/core/formatters/loader.rb
opal-rspec-0.6.0 opal/opal/rspec/fixes/rspec/core/formatters/loader.rb
opal-rspec-0.6.0.beta1 opal/opal/rspec/fixes/rspec/core/formatters/loader.rb
opal-connect-rspec-0.5.0 opal/opal/rspec/fixes/rspec/core/formatters/loader.rb
opal-rspec-0.5.0 opal/opal/rspec/fixes/rspec/core/formatters/loader.rb
opal-rspec-0.5.0.beta3 opal/opal/rspec/fixes/rspec/core/formatters/loader.rb