Upgraded Rails and RSpec
[monkeycharger.git] / vendor / plugins / rspec / rspec_on_rails / tasks / rspec.rake
blob6076932e73d954423f697b92cb81b823560589ef
1 # In rails 1.2, plugins aren't available in the path until they're loaded.
2 # Check to see if the rspec plugin is installed first and require
3 # it if it is.  If not, use the gem version.
4 rspec_base = File.expand_path(File.dirname(__FILE__) + '/../../rspec/lib')
5 $LOAD_PATH.unshift(rspec_base) if File.exist?(rspec_base)
6 require 'spec/rake/spectask'
7 require 'spec/translator'
9 spec_prereq = File.exist?(File.join(RAILS_ROOT, 'config', 'database.yml')) ? "db:test:prepare" : :noop
10 task :noop do
11 end
13 task :default => :spec
14 task :stats => "spec:statsetup"
16 desc "Run all specs in spec directory (excluding plugin specs)"
17 Spec::Rake::SpecTask.new(:spec => spec_prereq) do |t|
18   t.spec_opts = ['--options', "\"#{RAILS_ROOT}/spec/spec.opts\""]
19   t.spec_files = FileList['spec/**/*_spec.rb']
20 end
22 namespace :spec do
23   desc "Run all specs in spec directory with RCov (excluding plugin specs)"
24   Spec::Rake::SpecTask.new(:rcov) do |t|
25     t.spec_opts = ['--options', "\"#{RAILS_ROOT}/spec/spec.opts\""]
26     t.spec_files = FileList['spec/**/*_spec.rb']
27     t.rcov = true
28     t.rcov_opts = lambda do
29       IO.readlines("#{RAILS_ROOT}/spec/rcov.opts").map {|l| l.chomp.split " "}.flatten
30     end
31   end
32   
33   desc "Print Specdoc for all specs (excluding plugin specs)"
34   Spec::Rake::SpecTask.new(:doc) do |t|
35     t.spec_opts = ["--format", "specdoc", "--dry-run"]
36     t.spec_files = FileList['spec/**/*_spec.rb']
37   end
39   desc "Print Specdoc for all plugin specs"
40   Spec::Rake::SpecTask.new(:plugin_doc) do |t|
41     t.spec_opts = ["--format", "specdoc", "--dry-run"]
42     t.spec_files = FileList['vendor/plugins/**/spec/**/*_spec.rb'].exclude('vendor/plugins/rspec/*')
43   end
45   [:models, :controllers, :views, :helpers, :lib].each do |sub|
46     desc "Run the specs under spec/#{sub}"
47     Spec::Rake::SpecTask.new(sub => spec_prereq) do |t|
48       t.spec_opts = ['--options', "\"#{RAILS_ROOT}/spec/spec.opts\""]
49       t.spec_files = FileList["spec/#{sub}/**/*_spec.rb"]
50     end
51   end
52   
53   desc "Run the specs under vendor/plugins (except RSpec's own)"
54   Spec::Rake::SpecTask.new(:plugins => spec_prereq) do |t|
55     t.spec_opts = ['--options', "\"#{RAILS_ROOT}/spec/spec.opts\""]
56     t.spec_files = FileList['vendor/plugins/**/spec/**/*_spec.rb'].exclude('vendor/plugins/rspec/*').exclude("vendor/plugins/rspec_on_rails/*")
57   end
58   
59   namespace :plugins do
60     desc "Runs the examples for rspec_on_rails"
61     Spec::Rake::SpecTask.new(:rspec_on_rails => spec_prereq) do |t|
62       t.spec_opts = ['--options', "\"#{RAILS_ROOT}/spec/spec.opts\""]
63       t.spec_files = FileList['vendor/plugins/rspec_on_rails/spec/**/*_spec.rb']
64     end
65   end
67   desc "Translate/upgrade specs using the built-in translator"
68   task :translate do
69     translator = ::Spec::Translator.new
70     dir = RAILS_ROOT + '/spec'
71     translator.translate(dir, dir)
72   end
74   # Setup specs for stats
75   task :statsetup do
76     require 'code_statistics'
77     ::STATS_DIRECTORIES << %w(Model\ specs spec/models)
78     ::STATS_DIRECTORIES << %w(View\ specs spec/views)
79     ::STATS_DIRECTORIES << %w(Controller\ specs spec/controllers)
80     ::STATS_DIRECTORIES << %w(Helper\ specs spec/helpers)
81     ::CodeStatistics::TEST_TYPES << "Model specs"
82     ::CodeStatistics::TEST_TYPES << "View specs"
83     ::CodeStatistics::TEST_TYPES << "Controller specs"
84     ::CodeStatistics::TEST_TYPES << "Helper specs"
85     ::STATS_DIRECTORIES.delete_if {|a| a[0] =~ /test/}
86   end
88   namespace :db do
89     namespace :fixtures do
90       desc "Load fixtures (from spec/fixtures) into the current environment's database.  Load specific fixtures using FIXTURES=x,y"
91       task :load => :environment do
92         require 'active_record/fixtures'
93         ActiveRecord::Base.establish_connection(RAILS_ENV.to_sym)
94         (ENV['FIXTURES'] ? ENV['FIXTURES'].split(/,/) : Dir.glob(File.join(RAILS_ROOT, 'spec', 'fixtures', '*.{yml,csv}'))).each do |fixture_file|
95           Fixtures.create_fixtures('spec/fixtures', File.basename(fixture_file, '.*'))
96         end
97       end
98     end
99   end
101   namespace :server do
102     daemonized_server_pid = File.expand_path("spec_server.pid", RAILS_ROOT + "/tmp")
104     desc "start spec_server."
105     task :start do
106       if File.exist?(daemonized_server_pid)
107         $stderr.puts "spec_server is already running."
108       else
109         $stderr.puts "Starting up spec server."
110         system("ruby", "script/spec_server", "--daemon", "--pid", daemonized_server_pid)
111       end
112     end
114     desc "stop spec_server."
115     task :stop do
116       unless File.exist?(daemonized_server_pid)
117         $stderr.puts "No server running."
118       else
119         $stderr.puts "Shutting down spec_server."
120         system("kill", "-s", "TERM", File.read(daemonized_server_pid).strip) && 
121         File.delete(daemonized_server_pid)
122       end
123     end
125     desc "reload spec_server."
126     task :restart do
127       unless File.exist?(daemonized_server_pid)
128         $stderr.puts "No server running."
129       else
130         $stderr.puts "Reloading down spec_server."
131         system("kill", "-s", "USR2", File.read(daemonized_server_pid).strip)
132       end
133     end
134   end