Sha256: 8682eacd89bd31cd03af615b7f90261c792aeedc8f9001ea8f00aca062006d37

Contents?: true

Size: 1.14 KB

Versions: 16

Compression:

Stored size: 1.14 KB

Contents

# This is borrowed (slightly modified) from Scott Taylor's
# project_path project:
#   http://github.com/smtlaissezfaire/project_path

require 'pathname'

module Rspec
  module Core
    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) # :nodoc:
        $LOAD_PATH.unshift(dir) unless $LOAD_PATH.include?(dir)
      end

      def root # :nodoc:
        @project_root ||= determine_root
      end

      def determine_root # :nodoc:
        find_first_parent_containing('spec') || '.'
      end

      def find_first_parent_containing(dir) # :nodoc:
        ascend_until {|path| File.exists?(File.join(path, dir))}
      end

      def ascend_until(&block) # :nodoc:
        Pathname(File.expand_path('.')).ascend do |path|
          return path if block.call(path)
        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

16 entries across 16 versions & 1 rubygems

Version Path
rspec-core-2.0.0.beta.8 lib/rspec/core/ruby_project.rb
rspec-core-2.0.0.beta.7 lib/rspec/core/ruby_project.rb
rspec-core-2.0.0.beta.6 lib/rspec/core/ruby_project.rb
rspec-core-2.0.0.beta.5 lib/rspec/core/ruby_project.rb
rspec-core-2.0.0.beta.4 lib/rspec/core/ruby_project.rb
rspec-core-2.0.0.beta.3 lib/rspec/core/ruby_project.rb
rspec-core-2.0.0.beta.2 lib/rspec/core/ruby_project.rb
rspec-core-2.0.0.beta.1 lib/rspec/core/ruby_project.rb
rspec-core-2.0.0.a10 lib/rspec/core/ruby_project.rb
rspec-core-2.0.0.a9 lib/rspec/core/ruby_project.rb
rspec-core-2.0.0.a8 lib/rspec/core/ruby_project.rb
rspec-core-2.0.0.a7 lib/rspec/core/ruby_project.rb
rspec-core-2.0.0.a6 lib/rspec/core/ruby_project.rb
rspec-core-2.0.0.a5 lib/rspec/core/ruby_project.rb
rspec-core-2.0.0.a4 lib/rspec/core/ruby_project.rb
rspec-core-2.0.0.a3 lib/rspec/core/ruby_project.rb