Sha256: 1173d9c2bf66cb25c9412da6028c80f1fc6417565ff72fd7cef706a6587825a7

Contents?: true

Size: 1.12 KB

Versions: 19

Compression:

Stored size: 1.12 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 # :nodoc:
        Pathname(File.expand_path('.')).ascend do |path|
          return path if yield(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

19 entries across 19 versions & 2 rubygems

Version Path
rspec-core-2.7.0.rc1 lib/rspec/core/ruby_project.rb
messagebus_ruby_api-0.4.7 spec/ruby/1.9.1/gems/rspec-core-2.5.1/lib/rspec/core/ruby_project.rb
messagebus_ruby_api-0.4.4 spec/ruby/1.9.1/gems/rspec-core-2.5.1/lib/rspec/core/ruby_project.rb
rspec-core-2.6.4 lib/rspec/core/ruby_project.rb
rspec-core-2.6.3 lib/rspec/core/ruby_project.rb
rspec-core-2.6.3.beta1 lib/rspec/core/ruby_project.rb
rspec-core-2.6.2.rc lib/rspec/core/ruby_project.rb
rspec-core-2.6.0 lib/rspec/core/ruby_project.rb
rspec-core-2.6.0.rc6 lib/rspec/core/ruby_project.rb
rspec-core-2.5.2 lib/rspec/core/ruby_project.rb
rspec-core-2.6.0.rc4 lib/rspec/core/ruby_project.rb
rspec-core-2.6.0.rc2 lib/rspec/core/ruby_project.rb
rspec-core-2.5.1 lib/rspec/core/ruby_project.rb
rspec-core-2.5.0 lib/rspec/core/ruby_project.rb
rspec-core-2.4.0 lib/rspec/core/ruby_project.rb
rspec-core-2.3.1 lib/rspec/core/ruby_project.rb
rspec-core-2.3.0 lib/rspec/core/ruby_project.rb
rspec-core-2.2.1 lib/rspec/core/ruby_project.rb
rspec-core-2.2.0 lib/rspec/core/ruby_project.rb