Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 4th, 2012  |  syntax: None  |  size: 5.17 KB  |  hits: 12  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. ##spec_helper.rb
  2.  
  3. require 'rubygems'
  4. require 'spork'
  5.  
  6. Spork.prefork do
  7.   # Loading more in this block will cause your tests to run faster. However,
  8.   # if you change any configuration or code from libraries loaded here, you'll
  9.   # need to restart spork for it take effect.
  10.  
  11.   # This file is copied to ~/spec when you run 'ruby script/generate rspec'
  12.   # from the project root directory.
  13.   ENV["RAILS_ENV"] = 'test'
  14.   require File.dirname(__FILE__) + "/../config/environment"
  15.   #require 'rspec'#MXDEBUG: WHYYY
  16.   require 'rspec/rails'
  17.  
  18.   # Unfortunately this incurs a warning that requiring the 'spec' module is deprecated.
  19.   require 'rspec/rr'
  20.  
  21.   require 'factory_girl_rails'
  22.  
  23.   require 'database_cleaner'
  24.   DatabaseCleaner.orm = 'mongo_mapper'
  25.   DatabaseCleaner.strategy = :truncation
  26.  
  27.   Rspec.configure do |config|
  28.     config.mock_with :rr
  29.  
  30.     config.after do
  31.       DatabaseCleaner.clean
  32.     end
  33.   end
  34.  
  35.   Dir["#{File.dirname(__FILE__)}/shared/**/*.rb"].each {|f| require f}
  36. end
  37.  
  38. Spork.each_run do
  39.   DatabaseCleaner.clean
  40.  
  41.   #Dir["#{File.dirname(__FILE__)}/shared/**/*.rb"].each {|f| require f}
  42. end
  43.  
  44.  
  45. ## lib/tasks/rspec.rake
  46.  
  47. begin
  48.   require 'rspec/core'
  49.   require 'rspec/core/rake_task'
  50. rescue MissingSourceFile
  51.   module RSpec
  52.     module Core
  53.       class RakeTask
  54.         def initialize(name)
  55.           task name do
  56.             # if rspec-rails is a configured gem, this will output helpful material and exit ...
  57.             require File.expand_path(File.dirname(__FILE__) + "/../../config/environment")
  58.  
  59.             # ... otherwise, do this:
  60.             raise <<-MSG
  61.  
  62. #{"*" * 80}
  63. *  You are trying to run an rspec rake task defined in
  64. *  #{__FILE__},
  65. *  but rspec can not be found in vendor/gems, vendor/plugins or system gems.
  66. #{"*" * 80}
  67. MSG
  68.           end
  69.         end
  70.       end
  71.     end
  72.   end
  73. end
  74.  
  75. Rake.application.instance_variable_get('@tasks').delete('default')
  76.  
  77. spec_prereq = Rails.root.join('config', 'database.yml').exist? ? "db:test:prepare" : :noop
  78. task :noop do
  79. end
  80.  
  81. task :default => :spec
  82. task :stats => "spec:statsetup"
  83.  
  84. desc "Run all specs in spec directory (excluding plugin specs)"
  85. RSpec::Core::RakeTask.new(:spec => spec_prereq)
  86.  
  87. namespace :spec do
  88.   [:requests, :models, :controllers, :views, :helpers, :mailers, :lib].each do |sub|
  89.     desc "Run the code examples in spec/#{sub}"
  90.     RSpec::Core::RakeTask.new(sub => spec_prereq) do |t|
  91.       t.pattern = "./spec/#{sub}/**/*_spec.rb"
  92.     end
  93.   end
  94.  
  95.   task :statsetup do
  96.     require 'rails/code_statistics'
  97.     ::STATS_DIRECTORIES << %w(Model\ specs spec/models) if File.exist?('spec/models')
  98.     ::STATS_DIRECTORIES << %w(View\ specs spec/views) if File.exist?('spec/views')
  99.     ::STATS_DIRECTORIES << %w(Controller\ specs spec/controllers) if File.exist?('spec/controllers')
  100.     ::STATS_DIRECTORIES << %w(Helper\ specs spec/helpers) if File.exist?('spec/helpers')
  101.     ::STATS_DIRECTORIES << %w(Library\ specs spec/lib) if File.exist?('spec/lib')
  102.     ::STATS_DIRECTORIES << %w(Mailer\ specs spec/mailers) if File.exist?('spec/mailers')
  103.     ::STATS_DIRECTORIES << %w(Routing\ specs spec/routing) if File.exist?('spec/routing')
  104.     ::STATS_DIRECTORIES << %w(Request\ specs spec/requests) if File.exist?('spec/requests')
  105.     ::CodeStatistics::TEST_TYPES << "Model specs" if File.exist?('spec/models')
  106.     ::CodeStatistics::TEST_TYPES << "View specs" if File.exist?('spec/views')
  107.     ::CodeStatistics::TEST_TYPES << "Controller specs" if File.exist?('spec/controllers')
  108.     ::CodeStatistics::TEST_TYPES << "Helper specs" if File.exist?('spec/helpers')
  109.     ::CodeStatistics::TEST_TYPES << "Library specs" if File.exist?('spec/lib')
  110.     ::CodeStatistics::TEST_TYPES << "Mailer specs" if File.exist?('spec/mailer')
  111.     ::CodeStatistics::TEST_TYPES << "Routing specs" if File.exist?('spec/routing')
  112.     ::CodeStatistics::TEST_TYPES << "Request specs" if File.exist?('spec/requests')
  113.   end
  114. end
  115.  
  116. ##console
  117. rake spec
  118.  
  119. (in /home/michael/Scripts/CrystalCommerce/CrystalMetrics)
  120. DEPRECATION WARNING: Rake tasks in /home/michael/Scripts/CrystalCommerce/CrystalMetrics/vendor/plugins/rspec-rr/tasks/rspec_rr_tasks.rake are deprecated. Use lib/tasks instead. (called from load_deprecated_tasks at /home/michael/.rvm/gems/ruby-1.8.7-p249@global/gems/railties-3.0.0.beta4/lib/rails/plugin.rb:50)
  121. ./spec/shared/contextual_spec.rb:1: undefined method `shared_examples_for' for main:Object (NoMethodError)
  122. rake aborted!
  123. bundle exec  /home/michael/.rvm/rubies/ruby-1.8.7-p249/bin/ruby  -Ilib -Ispec "./spec/shared/contextual_spec.rb" "./spec/shared/json_controller_spec.rb" "./spec/shared/legacy_model_spec.rb" "./spec/controllers/products_controller_spec.rb" "./spec/controllers/clients_controller_spec.rb" "./spec/models/hive/client_spec.rb" "./spec/models/hive/product_spec.rb" "./spec/models/series_spec.rb" "./spec/models/client_spec.rb" "./spec/models/admin/line_item_spec.rb" "./spec/models/admin/variant_spec.rb" "./spec/models/admin/product_spec.rb" "./spec/models/admin/order_spec.rb" "./spec/models/product_spec.rb" "./spec/models/price_spec.rb" "./spec/support/stat_craft_spec.rb" "./spec/support/contextual_spec.rb" "./spec/support/mongo_decimal_spec.rb" failed
  124.  
  125. (See full trace by running task with --trace)