Sha256: ee65b880d1198e801c7eab516e129a198c6a39cdc845fd7a3ab98fafda218a8e

Contents?: true

Size: 1.41 KB

Versions: 24

Compression:

Stored size: 1.41 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.map { |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

24 entries across 24 versions & 10 rubygems

Version Path
swift-pyrite-0.1.1 vendor/bundle/ruby/2.0.0/gems/rspec-core-3.3.2/lib/rspec/core/ruby_project.rb
swift-pyrite-0.1.0 vendor/bundle/ruby/2.0.0/gems/rspec-core-3.3.2/lib/rspec/core/ruby_project.rb
suzuko-0.1.8 vendor/bundle/ruby/2.0.0/gems/rspec-core-3.2.3/lib/rspec/core/ruby_project.rb
suzuko-0.1.7 vendor/bundle/ruby/2.0.0/gems/rspec-core-3.2.3/lib/rspec/core/ruby_project.rb
mastermind_adeybee-0.1.4 vendor/bundle/ruby/2.2.0/gems/rspec-core-3.3.2/lib/rspec/core/ruby_project.rb
sc_core-0.0.7 test/dummy/vendor/bundle/ruby/2.2.0/gems/rspec-core-3.3.2/lib/rspec/core/ruby_project.rb
mastermind_adeybee-0.1.3 vendor/bundle/ruby/2.2.0/gems/rspec-core-3.3.2/lib/rspec/core/ruby_project.rb
mastermind_adeybee-0.1.2 vendor/bundle/ruby/2.2.0/gems/rspec-core-3.3.2/lib/rspec/core/ruby_project.rb
mastermind_adeybee-0.1.1 vendor/bundle/ruby/2.2.0/gems/rspec-core-3.3.2/lib/rspec/core/ruby_project.rb
sublimetheme-1.0.1 path/gems/rspec-core-3.3.2/lib/rspec/core/ruby_project.rb
vagrant-cloudstack-1.2.0 vendor/bundle/gems/rspec-core-3.3.2/lib/rspec/core/ruby_project.rb
sublimetheme-1.0.0 path/gems/rspec-core-3.3.2/lib/rspec/core/ruby_project.rb
geminfo-0.1.0 path/gems/rspec-core-3.3.2/lib/rspec/core/ruby_project.rb
solidus_backend-1.0.0.pre3 vendor/bundle/gems/rspec-core-3.3.1/lib/rspec/core/ruby_project.rb
solidus_backend-1.0.0.pre2 vendor/bundle/gems/rspec-core-3.3.1/lib/rspec/core/ruby_project.rb
scoot-0.0.4 .bundle/gems/ruby/2.2.0/gems/rspec-core-3.3.2/lib/rspec/core/ruby_project.rb
rspec-core-3.3.2 lib/rspec/core/ruby_project.rb
solidus_backend-1.0.0.pre vendor/bundle/gems/rspec-core-3.3.1/lib/rspec/core/ruby_project.rb
rspec-core-3.3.1 lib/rspec/core/ruby_project.rb
rspec-core-3.3.0 lib/rspec/core/ruby_project.rb