Sha256: b47bf08c3747dd7f6143c706d194877ad82a7034a6ac40ef5105e5f6ef42a9a0

Contents?: true

Size: 1.42 KB

Versions: 7325

Compression:

Stored size: 1.42 KB

Contents

# This is borrowed (slightly modified) from Scott Taylor's
# project_path project:
#   http://github.com/smtlaissezfaire/project_path
module RSpec
  module Core
    # @private
    module RubyProject
      def add_to_load_path(*dirs)
        dirs.each { |dir| add_dir_to_load_path(File.join(root, dir)) }
      end

      def add_dir_to_load_path(dir)
        $LOAD_PATH.unshift(dir) unless $LOAD_PATH.include?(dir)
      end

      def root
        @project_root ||= determine_root
      end

      def determine_root
        find_first_parent_containing('spec') || '.'
      end

      def find_first_parent_containing(dir)
        ascend_until { |path| File.exist?(File.join(path, dir)) }
      end

      def ascend_until
        fs = File::SEPARATOR
        escaped_slash = "\\#{fs}"
        special = "_RSPEC_ESCAPED_SLASH_"
        project_path = File.expand_path(".")
        parts = project_path.gsub(escaped_slash, special).squeeze(fs).split(fs).map do |x|
          x.gsub(special, escaped_slash)
        end

        until parts.empty?
          path = parts.join(fs)
          path = fs if path == ""
          return path if yield(path)
          parts.pop
        end
      end

      module_function :add_to_load_path
      module_function :add_dir_to_load_path
      module_function :root
      module_function :determine_root
      module_function :find_first_parent_containing
      module_function :ascend_until
    end
  end
end

Version data entries

7,325 entries across 7,243 versions & 118 rubygems

Version Path
cybrid_api_bank_ruby-0.123.149 vendor/bundle/ruby/3.3.0/gems/rspec-core-3.13.2/lib/rspec/core/ruby_project.rb
cybrid_api_id_ruby-0.123.149 vendor/bundle/ruby/3.3.0/gems/rspec-core-3.13.2/lib/rspec/core/ruby_project.rb
cybrid_api_organization_ruby-0.123.149 vendor/bundle/ruby/3.3.0/gems/rspec-core-3.13.2/lib/rspec/core/ruby_project.rb
cybrid_api_bank_ruby-0.123.148 vendor/bundle/ruby/3.3.0/gems/rspec-core-3.13.2/lib/rspec/core/ruby_project.rb
cybrid_api_id_ruby-0.123.148 vendor/bundle/ruby/3.3.0/gems/rspec-core-3.13.2/lib/rspec/core/ruby_project.rb
cybrid_api_organization_ruby-0.123.148 vendor/bundle/ruby/3.3.0/gems/rspec-core-3.13.2/lib/rspec/core/ruby_project.rb
cybrid_api_bank_ruby-0.123.147 vendor/bundle/ruby/3.3.0/gems/rspec-core-3.13.2/lib/rspec/core/ruby_project.rb
cybrid_api_organization_ruby-0.123.147 vendor/bundle/ruby/3.3.0/gems/rspec-core-3.13.2/lib/rspec/core/ruby_project.rb
cybrid_api_id_ruby-0.123.147 vendor/bundle/ruby/3.3.0/gems/rspec-core-3.13.2/lib/rspec/core/ruby_project.rb
ory-client-1.16.2 vendor/bundle/ruby/3.1.0/gems/rspec-core-3.13.2/lib/rspec/core/ruby_project.rb
avalara_sdk-24.12.2 vendor/bundle/ruby/2.7.0/gems/rspec-core-3.11.0/lib/rspec/core/ruby_project.rb
cybrid_api_bank_ruby-0.123.145 vendor/bundle/ruby/3.3.0/gems/rspec-core-3.13.2/lib/rspec/core/ruby_project.rb
cybrid_api_organization_ruby-0.123.145 vendor/bundle/ruby/3.3.0/gems/rspec-core-3.13.2/lib/rspec/core/ruby_project.rb
cybrid_api_id_ruby-0.123.145 vendor/bundle/ruby/3.3.0/gems/rspec-core-3.13.2/lib/rspec/core/ruby_project.rb
cybrid_api_bank_ruby-0.123.144 vendor/bundle/ruby/3.3.0/gems/rspec-core-3.13.2/lib/rspec/core/ruby_project.rb
cybrid_api_id_ruby-0.123.144 vendor/bundle/ruby/3.3.0/gems/rspec-core-3.13.2/lib/rspec/core/ruby_project.rb
cybrid_api_organization_ruby-0.123.144 vendor/bundle/ruby/3.3.0/gems/rspec-core-3.13.2/lib/rspec/core/ruby_project.rb
ory-client-1.16.1 vendor/bundle/ruby/3.1.0/gems/rspec-core-3.13.2/lib/rspec/core/ruby_project.rb
ory-client-1.16.0 vendor/bundle/ruby/3.1.0/gems/rspec-core-3.13.2/lib/rspec/core/ruby_project.rb
cybrid_api_bank_ruby-0.123.143 vendor/bundle/ruby/3.3.0/gems/rspec-core-3.13.2/lib/rspec/core/ruby_project.rb