Skip to content

Commit

Permalink
Patching mate.rb to find rspec in vendor/gems as well as vendor/plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
purp authored and dchelimsky committed Oct 14, 2010
1 parent 46267d1 commit 7a5dd4e
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions Support/lib/spec/mate.rb
Original file line number Diff line number Diff line change
@@ -1,20 +1,28 @@
# This is based on Florian Weber's TDDMate

ENV['TM_PROJECT_DIRECTORY'] ||= File.dirname(ENV['TM_FILEPATH'])
rspec_rails_plugin = File.join(ENV['TM_PROJECT_DIRECTORY'],'vendor','plugins','rspec','lib')

def has_spec_autorun?(directory)
File.exists?(File.join(directory, %w(spec autorun.rb)))
end

# Load spec/autorun
if File.exist?(File.join(ENV['TM_PROJECT_DIRECTORY'], 'Gemfile'))
require "rubygems"
require "bundler"
Bundler.setup
elsif File.directory?(rspec_rails_plugin)
$LOAD_PATH.unshift(rspec_rails_plugin)
elsif ENV['TM_RSPEC_HOME']
rspec_lib = File.join(ENV['TM_RSPEC_HOME'], 'lib')
unless File.directory?(rspec_lib)
raise "TM_RSPEC_HOME points to a bad location: #{ENV['TM_RSPEC_HOME']}"
else
# Find it the old-fashioned way: in vendor/plugins, or in vendor/gems,
# or at TM_RSPEC_HOME
rspec_locs = Dir.glob(File.join(ENV['TM_PROJECT_DIRECTORY'],'vendor','{plugins,gems}','rspec{,-[0-9]*}', 'lib'))
rspec_locs << File.join(ENV['TM_RSPEC_HOME'], 'lib') if ENV['TM_RSPEC_HOME']
rspec_root = rspec_locs.reject { |dir| !has_spec_autorun?(dir) }.first

if rspec_root
$LOAD_PATH.unshift(rspec_root)
elsif ENV['TM_RSPEC_HOME']
raise "TM_RSPEC_HOME points to a bad location: #{ENV['TM_RSPEC_HOME']}" unless File.directory?(File.join(ENV['TM_RSPEC_HOME'], 'lib'))
end
$LOAD_PATH.unshift(rspec_lib)
end

begin
Expand Down

0 comments on commit 7a5dd4e

Please sign in to comment.