Created
July 8, 2010 13:32
-
-
Save iain/468004 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Rake.application.instance_variable_get('@tasks')['default'].prerequisites.delete('test') | |
task :default => :spec | |
task :stats => "spec:statsetup" | |
desc "Run all specs in spec directory (excluding plugin specs)" | |
task :spec => :"spec:load" do | |
RSpec.run(:all) # or something similar | |
end | |
namespace :spec do | |
task :load do | |
begin | |
require 'rspec/core' | |
require 'rspec/core/rake_task' | |
if Rails.root.join('config', 'database.yml').exist? | |
Rake::Task["db:test:prepare"].invoke | |
end | |
rescue MissingSourceFile | |
# if rspec-rails is a configured gem, this will output helpful material and exit ... | |
require File.expand_path(File.dirname(__FILE__) + "/../../config/environment") | |
# ... otherwise, do this: | |
raise <<-MSG | |
#{"*" * 80} | |
* You are trying to run an rspec rake task defined in | |
* #{__FILE__}, | |
* but rspec can not be found in vendor/gems, vendor/plugins or system gems. | |
#{"*" * 80} | |
MSG | |
end | |
end | |
[:requests, :models, :controllers, :views, :helpers, :mailers, :lib, :routing].each do |sub| | |
desc "Run the code examples in spec/#{sub}" | |
task sub => :load do | |
RSpec.run(sub) do |t| # again, just guessing the code to run RSpec here... | |
t.pattern = "./spec/#{sub}/**/*_spec.rb" | |
end | |
end | |
end | |
task :statsetup do | |
require 'rails/code_statistics' | |
::STATS_DIRECTORIES << %w(Model\ specs spec/models) if File.exist?('spec/models') | |
::STATS_DIRECTORIES << %w(View\ specs spec/views) if File.exist?('spec/views') | |
::STATS_DIRECTORIES << %w(Controller\ specs spec/controllers) if File.exist?('spec/controllers') | |
::STATS_DIRECTORIES << %w(Helper\ specs spec/helpers) if File.exist?('spec/helpers') | |
::STATS_DIRECTORIES << %w(Library\ specs spec/lib) if File.exist?('spec/lib') | |
::STATS_DIRECTORIES << %w(Mailer\ specs spec/mailers) if File.exist?('spec/mailers') | |
::STATS_DIRECTORIES << %w(Routing\ specs spec/routing) if File.exist?('spec/routing') | |
::STATS_DIRECTORIES << %w(Request\ specs spec/requests) if File.exist?('spec/requests') | |
::CodeStatistics::TEST_TYPES << "Model specs" if File.exist?('spec/models') | |
::CodeStatistics::TEST_TYPES << "View specs" if File.exist?('spec/views') | |
::CodeStatistics::TEST_TYPES << "Controller specs" if File.exist?('spec/controllers') | |
::CodeStatistics::TEST_TYPES << "Helper specs" if File.exist?('spec/helpers') | |
::CodeStatistics::TEST_TYPES << "Library specs" if File.exist?('spec/lib') | |
::CodeStatistics::TEST_TYPES << "Mailer specs" if File.exist?('spec/mailer') | |
::CodeStatistics::TEST_TYPES << "Routing specs" if File.exist?('spec/routing') | |
::CodeStatistics::TEST_TYPES << "Request specs" if File.exist?('spec/requests') | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment