changelog shortlog tags changeset manifest revisions annotate raw

vendor/plugins/rspec_on_rails/tasks/rspec.rake

changeset 16: 01fd3f10ae84
author: moriq@moriq.com
date: Mon Mar 10 10:13:18 2008 +0900 (16 years ago)
permissions: -rw-r--r--
description: add plugins rspec_on_rails
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.
4rspec_base = File.expand_path(File.dirname(__FILE__) + '/../../rspec/lib')
5$LOAD_PATH.unshift(rspec_base) if File.exist?(rspec_base)
6require 'spec/rake/spectask'
7require 'spec/translator'
8
9spec_prereq = File.exist?(File.join(RAILS_ROOT, 'config', 'database.yml')) ? "db:test:prepare" : :noop
10task :noop do
11end
12
13task :default => :spec
14task :stats => "spec:statsetup"
15
16desc "Run all specs in spec directory (excluding plugin specs)"
17Spec::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']
20end
21
22namespace :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
38
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
44
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) 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
66
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
73
74 # Setup specs for stats
75 task :statsetup do
76 require 'code_statistics'
77 ::STATS_DIRECTORIES << %w(Model\ specs spec/models) if File.exist?('spec/models')
78 ::STATS_DIRECTORIES << %w(View\ specs spec/views) if File.exist?('spec/views')
79 ::STATS_DIRECTORIES << %w(Controller\ specs spec/controllers) if File.exist?('spec/controllers')
80 ::STATS_DIRECTORIES << %w(Helper\ specs spec/helpers) if File.exist?('spec/helpers')
81 ::STATS_DIRECTORIES << %w(Library\ specs spec/lib) if File.exist?('spec/lib')
82 ::CodeStatistics::TEST_TYPES << "Model specs" if File.exist?('spec/models')
83 ::CodeStatistics::TEST_TYPES << "View specs" if File.exist?('spec/views')
84 ::CodeStatistics::TEST_TYPES << "Controller specs" if File.exist?('spec/controllers')
85 ::CodeStatistics::TEST_TYPES << "Helper specs" if File.exist?('spec/helpers')
86 ::CodeStatistics::TEST_TYPES << "Library specs" if File.exist?('spec/lib')
87 ::STATS_DIRECTORIES.delete_if {|a| a[0] =~ /test/}
88 end
89
90 namespace :db do
91 namespace :fixtures do
92 desc "Load fixtures (from spec/fixtures) into the current environment's database. Load specific fixtures using FIXTURES=x,y"
93 task :load => :environment do
94 require 'active_record/fixtures'
95 ActiveRecord::Base.establish_connection(RAILS_ENV.to_sym)
96 (ENV['FIXTURES'] ? ENV['FIXTURES'].split(/,/) : Dir.glob(File.join(RAILS_ROOT, 'spec', 'fixtures', '*.{yml,csv}'))).each do |fixture_file|
97 Fixtures.create_fixtures('spec/fixtures', File.basename(fixture_file, '.*'))
98 end
99 end
100 end
101 end
102
103 namespace :server do
104 daemonized_server_pid = File.expand_path("spec_server.pid", RAILS_ROOT + "/tmp")
105
106 desc "start spec_server."
107 task :start do
108 if File.exist?(daemonized_server_pid)
109 $stderr.puts "spec_server is already running."
110 else
111 $stderr.puts "Starting up spec server."
112 system("ruby", "script/spec_server", "--daemon", "--pid", daemonized_server_pid)
113 end
114 end
115
116 desc "stop spec_server."
117 task :stop do
118 unless File.exist?(daemonized_server_pid)
119 $stderr.puts "No server running."
120 else
121 $stderr.puts "Shutting down spec_server."
122 system("kill", "-s", "TERM", File.read(daemonized_server_pid).strip) &&
123 File.delete(daemonized_server_pid)
124 end
125 end
126
127 desc "reload spec_server."
128 task :restart do
129 unless File.exist?(daemonized_server_pid)
130 $stderr.puts "No server running."
131 else
132 $stderr.puts "Reloading down spec_server."
133 system("kill", "-s", "USR2", File.read(daemonized_server_pid).strip)
134 end
135 end
136 end
137end