module RSpec::Core::RubyProject

def add_dir_to_load_path(dir) # :nodoc:

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

def add_to_load_path(*dirs)

def add_to_load_path(*dirs)
  dirs.map {|dir| add_dir_to_load_path(File.join(root, dir))}
end

def ascend_until # :nodoc:

:nodoc:
def ascend_until # :nodoc:
  Pathname(File.expand_path('.')).ascend do |path|
    return path if yield(path)
  end
end

def determine_root # :nodoc:

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

def find_first_parent_containing(dir) # :nodoc:

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

def root # :nodoc:

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