Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

names

  • Loading branch information...
commit 8f88c6cc45fc1675023e5313516d28f33f4c3ab8 1 parent f227f48
@dchelimsky dchelimsky authored
View
3  lib/rspec/core/load_path.rb
@@ -1,4 +1,3 @@
require 'rspec/core/ruby_project'
-Rspec::Core::RubyProject.add_to_load_path('lib')
-Rspec::Core::RubyProject.add_to_load_path('spec')
+Rspec::Core::RubyProject.add_to_load_path('lib', 'spec')
View
30 lib/rspec/core/ruby_project.rb
@@ -1,13 +1,21 @@
+# 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(dir)
- dir = File.join(root, dir)
+ 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:
- require 'pathname'
@project_root ||= determine_root
end
@@ -15,26 +23,22 @@ def determine_root # :nodoc:
find_first_parent_containing('spec') || '.'
end
- def find_first_parent_containing(dir)
- # This is borrowed (slightly modified) from Scott Taylor's
- # project_path project:
- # http://github.com/smtlaissezfaire/project_path
- find_directory_parent('.') do |path|
- File.exists?(File.join(path, dir))
- end
+ def find_first_parent_containing(dir) # :nodoc:
+ ascend_while {|path| File.exists?(File.join(path, dir))}
end
- def find_directory_parent(path_start, &block)
- Pathname(File.expand_path(path_start)).ascend do |path|
+ def ascend_while(&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 :find_directory_parent
+ module_function :ascend_while
end
end
end
View
20 spec/rspec/core/ruby_project_spec.rb
@@ -1,19 +1,23 @@
module Rspec
module Core
describe RubyProject do
+
describe "#determine_root" do
- context "no parent with spec directory" do
- it "returns the current directory" do
- RubyProject.stub(:find_first_parent_containing).and_return(nil)
- RubyProject.determine_root.should == '.'
+
+ context "with ancestor containing spec directory" do
+ it "returns ancestor containing the spec directory" do
+ RubyProject.stub(:ascend_while).and_return('foodir')
+ RubyProject.determine_root.should == 'foodir'
end
end
- context "has parent with spec directory" do
- it "returns the directory containing the spec directory" do
- RubyProject.stub(:find_directory_parent).and_return('foodir')
- RubyProject.determine_root.should == 'foodir'
+
+ context "without ancestor containing spec directory" do
+ it "returns current working directory" do
+ RubyProject.stub(:find_first_parent_containing).and_return(nil)
+ RubyProject.determine_root.should == '.'
end
end
+
end
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.