Sha256: c591a78d7247c7e0f79fc4f47ed70636a3e680fb96688c71113c645ab5267452

Contents?: true

Size: 1.14 KB

Versions: 26

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

26 entries across 26 versions & 3 rubygems

Version Path
vim-jar-0.1.2.0001 bundler/ruby/1.8/gems/rspec-core-2.1.0/lib/rspec/core/ruby_project.rb
vim-jar-0.1.2 bundler/ruby/1.8/gems/rspec-core-2.1.0/lib/rspec/core/ruby_project.rb
vim-jar-0.1.1 bundler/ruby/1.8/gems/rspec-core-2.1.0/lib/rspec/core/ruby_project.rb
vim-jar-0.1.0 bundler/ruby/1.8/gems/rspec-core-2.1.0/lib/rspec/core/ruby_project.rb
vim-jar-0.0.3 bundler/ruby/1.8/gems/rspec-core-2.1.0/lib/rspec/core/ruby_project.rb
vim-jar-0.0.2 bundler/ruby/1.8/gems/rspec-core-2.1.0/lib/rspec/core/ruby_project.rb
vim-jar-0.0.1 bundler/ruby/1.8/gems/rspec-core-2.1.0/lib/rspec/core/ruby_project.rb
rspec-core-2.1.0 lib/rspec/core/ruby_project.rb
rspec-core-2.0.1 lib/rspec/core/ruby_project.rb
gemrage-1.0.0 vendor/ruby/1.8/gems/rspec-core-2.0.0/lib/rspec/core/ruby_project.rb
gemrage-0.4.1 vendor/ruby/1.8/gems/rspec-core-2.0.0/lib/rspec/core/ruby_project.rb
gemrage-0.4.0 vendor/ruby/1.8/gems/rspec-core-2.0.0/lib/rspec/core/ruby_project.rb
gemrage-0.3.2 vendor/ruby/1.8/gems/rspec-core-2.0.0/lib/rspec/core/ruby_project.rb
gemrage-0.3.1 vendor/ruby/1.8/gems/rspec-core-2.0.0/lib/rspec/core/ruby_project.rb
gemrage-0.3.0 vendor/ruby/1.8/gems/rspec-core-2.0.0/lib/rspec/core/ruby_project.rb
gemrage-0.2.0 vendor/ruby/1.8/gems/rspec-core-2.0.0/lib/rspec/core/ruby_project.rb
gemrage-0.1.2 vendor/ruby/1.8/gems/rspec-core-2.0.0/lib/rspec/core/ruby_project.rb
gemrage-0.1.1 vendor/ruby/1.8/gems/rspec-core-2.0.0/lib/rspec/core/ruby_project.rb
gemrage-0.1.0 vendor/ruby/1.8/gems/rspec-core-2.0.0/lib/rspec/core/ruby_project.rb
gemrage-0.0.0 vendor/ruby/1.8/gems/rspec-core-2.0.0/lib/rspec/core/ruby_project.rb