1 gem 'test-unit', '1.2.3' if RUBY_VERSION.to_f >= 1.9
3 Dir["#{RAILS_ROOT}/vendor/gems/*"].each do |subdir|
4 rspec_gem_dir = subdir if subdir.gsub("#{RAILS_ROOT}/vendor/gems/","") =~ /^(\w+-)?rspec-(\d+)/ && File.exist?("#{subdir}/lib/spec/rake/spectask.rb")
6 rspec_plugin_dir = File.expand_path(File.dirname(__FILE__) + '/../../vendor/plugins/rspec')
8 if rspec_gem_dir && (test ?d, rspec_plugin_dir)
9 raise "\n#{'*'*50}\nYou have rspec installed in both vendor/gems and vendor/plugins\nPlease pick one and dispose of the other.\n#{'*'*50}\n\n"
13 $LOAD_PATH.unshift("#{rspec_gem_dir}/lib")
14 elsif File.exist?(rspec_plugin_dir)
15 $LOAD_PATH.unshift("#{rspec_plugin_dir}/lib")
18 # Don't load rspec if running "rake gems:*"
19 unless ARGV.any? {|a| a =~ /^gems/}
22 require 'spec/rake/spectask'
23 rescue MissingSourceFile
29 # if rspec-rails is a configured gem, this will output helpful material and exit ...
30 require File.expand_path(File.join(File.dirname(__FILE__),"..","..","config","environment"))
32 # ... otherwise, do this:
36 * You are trying to run an rspec rake task defined in
38 * but rspec can not be found in vendor/gems, vendor/plugins or system gems.
48 Rake.application.instance_variable_get('@tasks').delete('default')
50 spec_prereq = File.exist?(File.join(RAILS_ROOT, 'config', 'database.yml')) ? "db:test:prepare" : :noop
54 task :default => :spec
55 task :stats => "spec:statsetup"
57 desc "Run all specs in spec directory (excluding plugin specs)"
58 Spec::Rake::SpecTask.new(:spec => spec_prereq) do |t|
59 t.spec_opts = ['--options', "\"#{RAILS_ROOT}/spec/spec.opts\""]
60 t.spec_files = FileList['spec/**/*_spec.rb']
64 desc "Run all specs in spec directory with RCov (excluding plugin specs)"
65 Spec::Rake::SpecTask.new(:rcov) do |t|
66 t.spec_opts = ['--options', "\"#{RAILS_ROOT}/spec/spec.opts\""]
67 t.spec_files = FileList['spec/**/*_spec.rb']
69 t.rcov_opts = lambda do
70 IO.readlines("#{RAILS_ROOT}/spec/rcov.opts").map {|l| l.chomp.split " "}.flatten
74 desc "Print Specdoc for all specs (excluding plugin specs)"
75 Spec::Rake::SpecTask.new(:doc) do |t|
76 t.spec_opts = ["--format", "specdoc", "--dry-run"]
77 t.spec_files = FileList['spec/**/*_spec.rb']
80 desc "Print Specdoc for all plugin examples"
81 Spec::Rake::SpecTask.new(:plugin_doc) do |t|
82 t.spec_opts = ["--format", "specdoc", "--dry-run"]
83 t.spec_files = FileList['vendor/plugins/**/spec/**/*_spec.rb'].exclude('vendor/plugins/rspec/*')
86 [:models, :controllers, :views, :helpers, :lib, :integration].each do |sub|
87 desc "Run the code examples in spec/#{sub}"
88 Spec::Rake::SpecTask.new(sub => spec_prereq) do |t|
89 t.spec_opts = ['--options', "\"#{RAILS_ROOT}/spec/spec.opts\""]
90 t.spec_files = FileList["spec/#{sub}/**/*_spec.rb"]
94 desc "Run the code examples in vendor/plugins (except RSpec's own)"
95 Spec::Rake::SpecTask.new(:plugins => spec_prereq) do |t|
96 t.spec_opts = ['--options', "\"#{RAILS_ROOT}/spec/spec.opts\""]
97 t.spec_files = FileList['vendor/plugins/**/spec/**/*_spec.rb'].exclude('vendor/plugins/rspec/*').exclude("vendor/plugins/rspec-rails/*")
100 namespace :plugins do
101 desc "Runs the examples for rspec_on_rails"
102 Spec::Rake::SpecTask.new(:rspec_on_rails) do |t|
103 t.spec_opts = ['--options', "\"#{RAILS_ROOT}/spec/spec.opts\""]
104 t.spec_files = FileList['vendor/plugins/rspec-rails/spec/**/*_spec.rb']
108 # Setup specs for stats
110 require 'code_statistics'
111 ::STATS_DIRECTORIES << %w(Model\ specs spec/models) if File.exist?('spec/models')
112 ::STATS_DIRECTORIES << %w(View\ specs spec/views) if File.exist?('spec/views')
113 ::STATS_DIRECTORIES << %w(Controller\ specs spec/controllers) if File.exist?('spec/controllers')
114 ::STATS_DIRECTORIES << %w(Helper\ specs spec/helpers) if File.exist?('spec/helpers')
115 ::STATS_DIRECTORIES << %w(Library\ specs spec/lib) if File.exist?('spec/lib')
116 ::STATS_DIRECTORIES << %w(Routing\ specs spec/routing) if File.exist?('spec/routing')
117 ::STATS_DIRECTORIES << %w(Integration\ specs spec/integration) if File.exist?('spec/integration')
118 ::CodeStatistics::TEST_TYPES << "Model specs" if File.exist?('spec/models')
119 ::CodeStatistics::TEST_TYPES << "View specs" if File.exist?('spec/views')
120 ::CodeStatistics::TEST_TYPES << "Controller specs" if File.exist?('spec/controllers')
121 ::CodeStatistics::TEST_TYPES << "Helper specs" if File.exist?('spec/helpers')
122 ::CodeStatistics::TEST_TYPES << "Library specs" if File.exist?('spec/lib')
123 ::CodeStatistics::TEST_TYPES << "Routing specs" if File.exist?('spec/routing')
124 ::CodeStatistics::TEST_TYPES << "Integration specs" if File.exist?('spec/integration')
128 namespace :fixtures do
129 desc "Load fixtures (from spec/fixtures) into the current environment's database. Load specific fixtures using FIXTURES=x,y. Load from subdirectory in test/fixtures using FIXTURES_DIR=z."
130 task :load => :environment do
131 ActiveRecord::Base.establish_connection(Rails.env)
132 base_dir = File.join(Rails.root, 'spec', 'fixtures')
133 fixtures_dir = ENV['FIXTURES_DIR'] ? File.join(base_dir, ENV['FIXTURES_DIR']) : base_dir
135 require 'active_record/fixtures'
136 (ENV['FIXTURES'] ? ENV['FIXTURES'].split(/,/).map {|f| File.join(fixtures_dir, f) } : Dir.glob(File.join(fixtures_dir, '*.{yml,csv}'))).each do |fixture_file|
137 Fixtures.create_fixtures(File.dirname(fixture_file), File.basename(fixture_file, '.*'))