Permalink
Browse files

trust the load path (more to do, but good start)

  • Loading branch information...
1 parent 9a8f902 commit 643bdd9c1a3f517a43392702c0fd65902844970a @dchelimsky committed Aug 20, 2009
View
@@ -2,7 +2,7 @@
gem 'hoe', '>=2.0.0'
require 'hoe'
-$:.unshift(File.join(File.dirname(__FILE__), 'lib'))
+$:.unshift 'lib'
require 'spec/version'
require 'spec/rake/spectask'
@@ -40,10 +40,10 @@ task :post_blog do
end
# Some of the tasks are in separate files since they are also part of the website documentation
-load File.dirname(__FILE__) + '/resources/rake/examples.rake'
-load File.dirname(__FILE__) + '/resources/rake/examples_with_rcov.rake'
-load File.dirname(__FILE__) + '/resources/rake/failing_examples_with_html.rake'
-load File.dirname(__FILE__) + '/resources/rake/verify_rcov.rake'
+load 'resources/rake/examples.rake'
+load 'resources/rake/examples_with_rcov.rake'
+load 'resources/rake/failing_examples_with_html.rake'
+load 'resources/rake/verify_rcov.rake'
if RUBY_VERSION =~ /^1.8/
task :default => [:verify_rcov, :features]
@@ -1,4 +1,3 @@
-require File.dirname(__FILE__) + '/spec_helper'
require 'spec/runner/formatter/progress_bar_formatter'
# Example of a formatter with custom bactrace printing. Run me with:
@@ -7,7 +7,7 @@ def open_and_handle_with(pathname, processor)
end
if __FILE__ == $0
- require File.dirname(__FILE__) + '/io_processor'
+ require 'examples/passing/io_processor'
require 'pathname'
accessor = FileAccessor.new
@@ -1,4 +1,4 @@
-require File.dirname(__FILE__) + '/file_accessor'
+require 'examples/passing/file_accessor'
require 'stringio'
describe "A FileAccessor" do
@@ -1,4 +1,3 @@
-$:.unshift File.join(File.dirname(__FILE__), "/../../lib")
require 'spec/runner/formatter/nested_text_formatter'
class FilteredFormatter < Spec::Runner::Formatter::NestedTextFormatter
@@ -1,4 +1,4 @@
-require File.dirname(__FILE__) + '/io_processor'
+require 'examples/passing/io_processor'
require 'stringio'
describe "An IoProcessor" do
@@ -1,4 +1,4 @@
-require File.dirname(__FILE__) + '/stack'
+require 'examples/passing/stack'
class StackExamples < Spec::ExampleGroup
describe(Stack)
@@ -1,5 +1,5 @@
-require File.dirname(__FILE__) + "/stack"
-require File.dirname(__FILE__) + '/shared_stack_examples'
+require 'examples/passing/stack'
+require 'examples/passing/shared_stack_examples'
describe Stack, " (empty)" do
before(:each) do
@@ -1,5 +1,5 @@
-require File.dirname(__FILE__) + '/stack'
-require File.dirname(__FILE__) + '/shared_stack_examples'
+require 'examples/passing/stack'
+require 'examples/passing/shared_stack_examples'
describe Stack do
@@ -7,7 +7,6 @@ Feature: define matcher outside rspec
Scenario: define a matcher with default messages
Given a file named "test_multiples.rb" with:
"""
- $:.unshift File.join(File.dirname(__FILE__), "/../../lib")
require 'test/unit'
require 'spec/expectations'
View
@@ -3,8 +3,8 @@
require 'spec/expectations'
require 'forwardable'
require 'tempfile'
-require File.dirname(__FILE__) + '/../../spec/ruby_forker'
-require File.dirname(__FILE__) + '/matchers/smart_match'
+require 'spec/ruby_forker'
+require 'features/support/matchers/smart_match'
class RspecWorld
@@ -125,7 +125,7 @@ def self.attr_accessor(*names)
# Defines a new task, using the name +name+.
def initialize(name=:spec)
@name = name
- @libs = [File.expand_path(File.dirname(__FILE__) + '/../../../lib')]
+ @libs = ['lib']
@pattern = nil
@spec_files = nil
@spec_opts = []
@@ -38,9 +38,8 @@ class NoisyBacktraceTweaker < BacktraceTweaker
# Tweaks raised Exceptions to mask noisy (unneeded) parts of the backtrace
class QuietBacktraceTweaker < BacktraceTweaker
unless defined?(IGNORE_PATTERNS)
- root_dir = File.expand_path(File.join(__FILE__, '..', '..', '..', '..'))
- spec_files = Dir["#{root_dir}/lib/*"].map do |path|
- subpath = path[root_dir.length..-1]
+ spec_files = Dir["lib/*"].map do |path|
+ subpath = path[1..-1]
/#{subpath}/
end
IGNORE_PATTERNS = spec_files + [
@@ -178,7 +178,7 @@ def get_type_from_options(options)
end
def mock_framework_path(framework_name)
- File.expand_path(File.join(File.dirname(__FILE__), "/../adapters/mock_frameworks/#{framework_name}"))
+ "spec/adapters/mock_frameworks/#{framework_name}"
end
def scope_and_options(*args) # :nodoc:
@@ -1,4 +1,4 @@
-require File.join(File.dirname(__FILE__), "/load-diff-lcs")
+require 'spec/runner/differs/load-diff-lcs'
require 'pp'
module Spec
@@ -1,4 +1,3 @@
-$:.push File.join(File.dirname(__FILE__), *%w[.. .. lib])
require 'spec'
# Uncommenting next line will break the output feature (no output!!)
@@ -4,7 +4,6 @@
require 'rubygems' unless ENV['NO_RUBYGEMS']
require 'autotest'
end
-dir = File.dirname(__FILE__)
require 'spec/spec_helper'
-require File.expand_path("#{dir}/../../lib/autotest/rspec")
-require File.expand_path("#{dir}/autotest_matchers")
+require 'autotest/rspec'
+require 'spec/autotest/autotest_matchers'
@@ -1,8 +1,8 @@
-require File.dirname(__FILE__) + "/autotest_helper"
+require 'spec/autotest/autotest_helper'
describe Autotest::Rspec, "discovery" do
it "adds the rspec autotest plugin" do
Autotest.should_receive(:add_discovery)
- require File.dirname(__FILE__) + "/../../lib/autotest/discover"
+ load File.expand_path(File.dirname(__FILE__) + "/../../lib/autotest/discover.rb")
end
end
@@ -1,4 +1,4 @@
-require File.dirname(__FILE__) + "/autotest_helper"
+require 'spec/autotest/autotest_helper'
describe "failed_results_re" do
it "should match a failure" do
@@ -1,4 +1,4 @@
-require File.dirname(__FILE__) + "/autotest_helper"
+require 'spec/autotest/autotest_helper'
describe Autotest::Rspec do
describe "adding spec.opts --options" do
View
@@ -1,6 +0,0 @@
-if __FILE__ == $0
- dir = File.dirname(__FILE__)
- Dir["#{dir}/**/*_spec.rb"].reverse.each do |file|
- require file
- end
-end
@@ -1,4 +1,4 @@
-require File.dirname(__FILE__) + '/test_unit_spec_helper'
+require 'spec/spec/interop/test/unit/test_unit_spec_helper'
describe "ExampleGroup with test/unit/interop" do
include TestUnitSpecHelper
@@ -1,5 +1,5 @@
require 'spec/spec_helper'
-require File.dirname(__FILE__) + '/../../../../ruby_forker'
+require 'spec/ruby_forker'
module TestUnitSpecHelper
include RubyForker
@@ -1,4 +1,4 @@
-require File.dirname(__FILE__) + '/test_unit_spec_helper'
+require 'spec/spec/interop/test/unit/test_unit_spec_helper'
describe "Test::Unit::TestCase" do
include TestUnitSpecHelper
@@ -1,4 +1,4 @@
-require File.dirname(__FILE__) + '/test_unit_spec_helper'
+require 'spec/spec/interop/test/unit/test_unit_spec_helper'
describe "TestSuiteAdapter" do
include TestUnitSpecHelper
@@ -1,5 +1,5 @@
require 'spec/spec_helper'
-require File.dirname(__FILE__) + '/../../ruby_forker'
+require 'spec/ruby_forker'
describe "The bin/spec script" do
include RubyForker
@@ -1,5 +1,5 @@
require 'spec/spec_helper'
-require File.dirname(__FILE__) + '/../../../lib/spec/rake/spectask.rb'
+require 'spec/rake/spectask'
module Spec
module Rake
@@ -8,27 +8,27 @@ module Runner
describe "#mock_with" do
it "should default mock framework to rspec" do
- config.mock_framework.should =~ /\/spec\/adapters\/mock_frameworks\/rspec$/
+ config.mock_framework.should =~ /^spec\/adapters\/mock_frameworks\/rspec$/
end
it "should set rspec mocking explicitly" do
config.mock_with(:rspec)
- config.mock_framework.should =~ /\/spec\/adapters\/mock_frameworks\/rspec$/
+ config.mock_framework.should =~ /^spec\/adapters\/mock_frameworks\/rspec$/
end
it "should set mocha" do
config.mock_with(:mocha)
- config.mock_framework.should =~ /\/spec\/adapters\/mock_frameworks\/mocha$/
+ config.mock_framework.should =~ /^spec\/adapters\/mock_frameworks\/mocha$/
end
it "should set flexmock" do
config.mock_with(:flexmock)
- config.mock_framework.should =~ /\/spec\/adapters\/mock_frameworks\/flexmock$/
+ config.mock_framework.should =~ /^spec\/adapters\/mock_frameworks\/flexmock$/
end
it "should set rr" do
config.mock_with(:rr)
- config.mock_framework.should =~ /\/spec\/adapters\/mock_frameworks\/rr$/
+ config.mock_framework.should =~ /^spec\/adapters\/mock_frameworks\/rr$/
end
it "should set an arbitrary adapter module" do
@@ -1,5 +1,5 @@
require 'spec/spec_helper'
-require File.dirname(__FILE__) + '/resources/custom_example_group_runner'
+require 'spec/spec/runner/resources/custom_example_group_runner'
describe "OptionParser" do
before(:each) do
@@ -1,5 +1,5 @@
require 'spec/spec_helper'
-require File.dirname(__FILE__) + '/resources/custom_example_group_runner'
+require 'spec/spec/runner/resources/custom_example_group_runner'
module Spec
module Runner
@@ -4,9 +4,8 @@ module Spec
module Runner
describe CommandLine do
it "should not output twice" do
- dir = File.dirname(__FILE__)
- Dir.chdir("#{dir}/../../..") do
- output =`ruby #{dir}/output_one_time_fixture_runner.rb`
+ Dir.chdir(".") do
+ output =`ruby spec/spec/runner/output_one_time_fixture_runner.rb`
output.should include("1 example, 0 failures")
output.should_not include("0 examples, 0 failures")
end
View
@@ -1,16 +1,14 @@
require 'stringio'
-dir = File.dirname(__FILE__)
-lib_path = File.expand_path("#{dir}/../lib")
+lib_path = File.dirname(__FILE__) + '/../lib'
$LOAD_PATH.unshift lib_path unless $LOAD_PATH.include?(lib_path)
$_spec_spec = true # Prevents Kernel.exit in various places
require 'spec'
require 'spec/mocks'
-spec_classes_path = File.expand_path("#{dir}/../spec/spec/spec_classes")
-require spec_classes_path unless $LOAD_PATH.include?(spec_classes_path)
-require File.dirname(__FILE__) + '/../lib/spec/runner/differs/default'
-require File.dirname(__FILE__) + '/support/macros'
+require 'spec/spec/spec_classes'
+require 'spec/runner/differs/default'
+require 'spec/support/macros'
def jruby?
::RUBY_PLATFORM == 'java'

1 comment on commit 643bdd9

marekj commented on 643bdd9 Mar 9, 2011

classic commit message. I'll use this example to show how we should use require with canonical names rather than require locations. glad I've found it.

Please sign in to comment.