Class: ArTestRunner
- Inherits:
-
Object
- Object
- ArTestRunner
- Defined in:
- lib/ar_test_runner.rb
Constant Summary collapse
- ADAPTERS =
%w( mysql postgresql sqlite sqlite3 firebird db2 oracle sybase openbase frontbase jdbcmysql jdbcpostgresql jdbcsqlite3 jdbcderby jdbch2 jdbchsqldb )
- REQUIRE_ALL_GLOB =
%w(vendor/plugins/*/init.rb lib/*.rb)
- DEFAULT_REQUIRES =
[File.(File.join(File.dirname(__FILE__), 'ar_test_runner_includes.rb'))]
Instance Attribute Summary collapse
-
#auto_skip ⇒ Object
readonly
Returns the value of attribute auto_skip.
Class Method Summary collapse
-
.run! ⇒ Object
run the whole thing.
Instance Method Summary collapse
-
#activerecord_dir ⇒ Object
Get the activerecord from AR_DIR or default to app’s LOADPATH ENV should be set.
-
#adapter ⇒ Object
the database adapter to use.
-
#default_activerecord_dir ⇒ Object
The default activerecord directory used by the app (in LOADPATH).
-
#default_app_files ⇒ Object
Gather the default files.
-
#expanded_files ⇒ Object
list of files to include absolute or relative to RAILS_ROOT an expression sent to Dir.glob is ok FILE=config/ar_test_runner_init.rb,model/*.rb.
-
#plugins ⇒ Object
list of comma delimited plugins (relative to RAILS_ROOT) to include PLUGIN=smsonrails.
-
#required_files ⇒ Object
a list of files to require run running the ActiveRecord test suite.
-
#requires ⇒ Object
list of strings to require.
-
#run ⇒ Object
Run the unit tests.
-
#skip_files!(orig_files) ⇒ Object
update orig_files to skip the files we want to exclude Note: this is not the best way.
-
#skipped_files ⇒ Object
list of file names and dirs to skip over.
- #use_all_app_files? ⇒ Boolean
Instance Attribute Details
#auto_skip ⇒ Object (readonly)
Returns the value of attribute auto_skip.
4 5 6 |
# File 'lib/ar_test_runner.rb', line 4 def auto_skip @auto_skip end |
Class Method Details
.run! ⇒ Object
run the whole thing
13 14 15 |
# File 'lib/ar_test_runner.rb', line 13 def self.run! new.run end |
Instance Method Details
#activerecord_dir ⇒ Object
Get the activerecord from AR_DIR or default to app’s LOADPATH ENV should be set
61 62 63 64 65 66 67 68 |
# File 'lib/ar_test_runner.rb', line 61 def activerecord_dir @activerecord_dir ||= begin ar_dir = (ENV['AR_DIR']||= default_activerecord_dir) error_and_exit "Pass in the path to ActiveRecord. Eg: AR_DIR=/Library/Ruby/Gems/1.8/gems/activerecord-2.3.2" if ar_dir.nil? error_and_exit "Invalid ActiveRecord directory: #{ar_dir}" unless File.directory?(ar_dir) ar_dir end end |
#adapter ⇒ Object
the database adapter to use
44 45 46 47 48 49 50 |
# File 'lib/ar_test_runner.rb', line 44 def adapter @adapter ||= begin adpt = ENV['DB']||'mysql' error_and_exit("Database type not supported #{@adapter}") unless ADAPTERS.include?(adpt) adpt end end |
#default_activerecord_dir ⇒ Object
The default activerecord directory used by the app (in LOADPATH)
53 54 55 56 57 |
# File 'lib/ar_test_runner.rb', line 53 def default_activerecord_dir @default_activerecord_dir ||= if (activerecord_lib_dir = $LOAD_PATH.detect {|f| f =~ /activerecord/}) File.(File.dirname(activerecord_lib_dir)) end end |
#default_app_files ⇒ Object
Gather the default files
104 105 106 107 108 109 |
# File 'lib/ar_test_runner.rb', line 104 def default_app_files @default_app_files ||= REQUIRE_ALL_GLOB.inject([]) do |list, files| list.concat Dir.glob(files).collect{ |f| File.(f) } list end end |
#expanded_files ⇒ Object
list of files to include absolute or relative to RAILS_ROOT an expression sent to Dir.glob is ok FILE=config/ar_test_runner_init.rb,model/*.rb
Create a file like ar_test_runner_init.rb and include custom files
require 'mygem'
require '../../blah.rb'
77 78 79 80 81 82 |
# File 'lib/ar_test_runner.rb', line 77 def @expanded_files ||= split_file_names('FILE').inject([]) do |files, file| files.concat Dir.glob(file) files end end |
#plugins ⇒ Object
list of comma delimited plugins (relative to RAILS_ROOT) to include
PLUGIN=smsonrails
86 87 88 89 90 |
# File 'lib/ar_test_runner.rb', line 86 def plugins @plugins ||= split_file_names 'PLUGIN' do |p| File.join('vendor/plugins', p, 'init.rb') end end |
#required_files ⇒ Object
a list of files to require run running the ActiveRecord test suite
32 33 34 35 36 37 38 39 40 41 |
# File 'lib/ar_test_runner.rb', line 32 def required_files return @required_files unless @required_files.nil? @required_files = DEFAULT_REQUIRES.dup @required_files.concat(requires) @required_files.concat(plugins) @required_files.concat() @required_files.concat(default_app_files) if use_all_app_files? skip_files!(@required_files) @required_files end |
#requires ⇒ Object
list of strings to require. Similar to FILES but does not expand the path. Use with gems
REQUIRE=mygem/gem, gemsuper
95 96 97 |
# File 'lib/ar_test_runner.rb', line 95 def requires @requires ||= split_input 'REQUIRE' end |
#run ⇒ Object
Run the unit tests
18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/ar_test_runner.rb', line 18 def run old_dir, old_env = Dir.pwd, ENV['RUBYOPT'] print_info return true if ENV['DRY_RUN'] == 'true' Dir.chdir( activerecord_dir ) ENV['RUBYOPT'] = required_files.collect{ |f| "-r#{f}" }.join(' ')#"-r rubygems -ractiverecord.rb -r#{init_file}" load File.join( activerecord_dir, "Rakefile" ) Rake::Task[ "test_#{adapter}" ].invoke Dir.chdir( old_dir ) ENV['RUBYOPT'] = old_env end |
#skip_files!(orig_files) ⇒ Object
update orig_files to skip the files we want to exclude Note: this is not the best way. Loads this under the context of the activerecord version of the app
114 115 116 117 118 119 120 121 122 |
# File 'lib/ar_test_runner.rb', line 114 def skip_files!(orig_files) return orig_files if skipped_files.empty? && !use_all_app_files? #include activerecord require File.join(activerecord_dir, 'lib', 'activerecord.rb') #load each file now to see if it fails. orig_files.collect! { |f| require_file?(f) ? f : nil }.compact! end |
#skipped_files ⇒ Object
list of file names and dirs to skip over
99 100 101 |
# File 'lib/ar_test_runner.rb', line 99 def skipped_files @skipped_files ||= split_input 'SKIP' end |
#use_all_app_files? ⇒ Boolean
124 125 126 127 128 129 |
# File 'lib/ar_test_runner.rb', line 124 def use_all_app_files? if ENV['AR_RUN_DEFAULT'].nil? ENV['AR_RUN_DEFAULT'] = (plugins.empty? && requires.empty? && .empty?).to_s end ENV['AR_RUN_DEFAULT'] end |