Guest User

Untitled

a guest
May 26th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.68 KB | None | 0 0
  1. begin
  2. require 'rspec/core'
  3. require 'rspec/core/rake_task'
  4. rescue MissingSourceFile
  5. module Rspec
  6. module Core
  7. class RakeTask
  8. def initialize(name)
  9. task name do
  10. # if rspec-rails is a configured gem, this will output helpful material and exit ...
  11. require File.expand_path(File.dirname(__FILE__) + "/../../config/environment")
  12.  
  13. # ... otherwise, do this:
  14. raise <<-MSG
  15.  
  16. #{"*" * 80}
  17. * You are trying to run an rspec rake task defined in
  18. * #{__FILE__},
  19. * but rspec can not be found in vendor/gems, vendor/plugins or system gems.
  20. #{"*" * 80}
  21. MSG
  22. end
  23. end
  24. end
  25. end
  26. end
  27. end
  28.  
  29. Rake.application.instance_variable_get('@tasks').delete('default')
  30.  
  31. spec_prereq = File.exist?(File.join(Rails.root, 'config', 'database.yml')) ? "db:test:prepare" : :noop
  32. task :noop do
  33. end
  34.  
  35. task :default => :spec
  36. task :stats => "spec:statsetup"
  37.  
  38. desc "Run all specs in spec directory (excluding plugin specs)"
  39. Rspec::Core::RakeTask.new(:spec => spec_prereq)
  40.  
  41. namespace :spec do
  42. [:requests, :models, :controllers, :views, :helpers, :mailers, :lib].each do |sub|
  43. desc "Run the code examples in spec/#{sub}"
  44. Rspec::Core::RakeTask.new(sub => spec_prereq) do |t|
  45. t.pattern = "./spec/#{sub}/**/*_spec.rb"
  46. end
  47. end
  48.  
  49. task :statsetup do
  50. require 'rails/code_statistics'
  51. ::STATS_DIRECTORIES << %w(Model\ specs spec/models) if File.exist?('spec/models')
  52. ::STATS_DIRECTORIES << %w(View\ specs spec/views) if File.exist?('spec/views')
  53. ::STATS_DIRECTORIES << %w(Controller\ specs spec/controllers) if File.exist?('spec/controllers')
  54. ::STATS_DIRECTORIES << %w(Helper\ specs spec/helpers) if File.exist?('spec/helpers')
  55. ::STATS_DIRECTORIES << %w(Library\ specs spec/lib) if File.exist?('spec/lib')
  56. ::STATS_DIRECTORIES << %w(Mailer\ specs spec/mailers) if File.exist?('spec/mailers')
  57. ::STATS_DIRECTORIES << %w(Routing\ specs spec/routing) if File.exist?('spec/routing')
  58. ::STATS_DIRECTORIES << %w(Request\ specs spec/requests) if File.exist?('spec/requests')
  59. ::CodeStatistics::TEST_TYPES << "Model specs" if File.exist?('spec/models')
  60. ::CodeStatistics::TEST_TYPES << "View specs" if File.exist?('spec/views')
  61. ::CodeStatistics::TEST_TYPES << "Controller specs" if File.exist?('spec/controllers')
  62. ::CodeStatistics::TEST_TYPES << "Helper specs" if File.exist?('spec/helpers')
  63. ::CodeStatistics::TEST_TYPES << "Library specs" if File.exist?('spec/lib')
  64. ::CodeStatistics::TEST_TYPES << "Mailer specs" if File.exist?('spec/mailer')
  65. ::CodeStatistics::TEST_TYPES << "Routing specs" if File.exist?('spec/routing')
  66. ::CodeStatistics::TEST_TYPES << "Request specs" if File.exist?('spec/requests')
  67. end
  68. end
Add Comment
Please, Sign In to add comment