Radio, Web and Free Software

Changeset 6b20631af609047c42513e3f1bf8907db4e0b659

Show
Ignore:
Timestamp:
07/22/10 18:32:29 (7 weeks ago)
Author:
Alban Peignier <alban@…>
Parents:
be4da1d2c37b163d56abaf020bcb43da0e05c03b
Children:
aa902da0b29edcfed29dab3c8c4bf807931412ee
git-committer:
Alban Peignier <alban@tryphon.eu> / 2010-07-22T18:32:29Z+0200
Message:

Upgrade rspec scripts

Files:
5 modified

Legend:

Unmodified
Added
Removed
  • lib/tasks/rspec.rake

    re6ecc4a r6b20631  
    1 raise "To avoid rake task loading problems: run 'rake clobber' in vendor/plugins/rspec" if File.directory?(File.join(File.dirname(__FILE__), *%w[.. .. vendor plugins rspec pkg])) 
    2 raise "To avoid rake task loading problems: run 'rake clobber' in vendor/plugins/rspec-rails" if File.directory?(File.join(File.dirname(__FILE__), *%w[.. .. vendor plugins rspec-rails pkg])) 
     1gem 'test-unit', '1.2.3' if RUBY_VERSION.to_f >= 1.9 
     2rspec_gem_dir = nil 
     3Dir["#{RAILS_ROOT}/vendor/gems/*"].each do |subdir| 
     4  rspec_gem_dir = subdir if subdir.gsub("#{RAILS_ROOT}/vendor/gems/","") =~ /^(\w+-)?rspec-(\d+)/ && File.exist?("#{subdir}/lib/spec/rake/spectask.rb") 
     5end 
     6rspec_plugin_dir = File.expand_path(File.dirname(__FILE__) + '/../../vendor/plugins/rspec') 
    37 
    4 # In rails 1.2, plugins aren't available in the path until they're loaded. 
    5 # Check to see if the rspec plugin is installed first and require 
    6 # it if it is.  If not, use the gem version. 
    7 rspec_base = File.expand_path(File.dirname(__FILE__) + '/../../vendor/plugins/rspec/lib') 
    8 $LOAD_PATH.unshift(rspec_base) if File.exist?(rspec_base) 
    9 require 'spec/rake/spectask' 
     8if rspec_gem_dir && (test ?d, rspec_plugin_dir) 
     9  raise "\n#{'*'*50}\nYou have rspec installed in both vendor/gems and vendor/plugins\nPlease pick one and dispose of the other.\n#{'*'*50}\n\n" 
     10end 
     11 
     12if rspec_gem_dir 
     13  $LOAD_PATH.unshift("#{rspec_gem_dir}/lib") 
     14elsif File.exist?(rspec_plugin_dir) 
     15  $LOAD_PATH.unshift("#{rspec_plugin_dir}/lib") 
     16end 
     17 
     18# Don't load rspec if running "rake gems:*" 
     19unless ARGV.any? {|a| a =~ /^gems/} 
     20 
     21begin 
     22  require 'spec/rake/spectask' 
     23rescue MissingSourceFile 
     24  module Spec 
     25    module Rake 
     26      class SpecTask 
     27        def initialize(name) 
     28          task name do 
     29            # if rspec-rails is a configured gem, this will output helpful material and exit ... 
     30            require File.expand_path(File.join(File.dirname(__FILE__),"..","..","config","environment")) 
     31 
     32            # ... otherwise, do this: 
     33            raise <<-MSG 
     34 
     35#{"*" * 80} 
     36*  You are trying to run an rspec rake task defined in 
     37*  #{__FILE__}, 
     38*  but rspec can not be found in vendor/gems, vendor/plugins or system gems. 
     39#{"*" * 80} 
     40MSG 
     41          end 
     42        end 
     43      end 
     44    end 
     45  end 
     46end 
     47 
     48Rake.application.instance_variable_get('@tasks').delete('default') 
    1049 
    1150spec_prereq = File.exist?(File.join(RAILS_ROOT, 'config', 'database.yml')) ? "db:test:prepare" : :noop 
     
    3271    end 
    3372  end 
    34    
     73 
    3574  desc "Print Specdoc for all specs (excluding plugin specs)" 
    3675  Spec::Rake::SpecTask.new(:doc) do |t| 
     
    3978  end 
    4079 
    41   desc "Print Specdoc for all plugin specs" 
     80  desc "Print Specdoc for all plugin examples" 
    4281  Spec::Rake::SpecTask.new(:plugin_doc) do |t| 
    4382    t.spec_opts = ["--format", "specdoc", "--dry-run"] 
     
    4584  end 
    4685 
    47   [:models, :controllers, :views, :helpers, :lib].each do |sub| 
    48     desc "Run the specs under spec/#{sub}" 
     86  [:models, :controllers, :views, :helpers, :lib, :integration].each do |sub| 
     87    desc "Run the code examples in spec/#{sub}" 
    4988    Spec::Rake::SpecTask.new(sub => spec_prereq) do |t| 
    5089      t.spec_opts = ['--options', "\"#{RAILS_ROOT}/spec/spec.opts\""] 
     
    5291    end 
    5392  end 
    54    
    55   desc "Run the specs under vendor/plugins (except RSpec's own)" 
     93 
     94  desc "Run the code examples in vendor/plugins (except RSpec's own)" 
    5695  Spec::Rake::SpecTask.new(:plugins => spec_prereq) do |t| 
    5796    t.spec_opts = ['--options', "\"#{RAILS_ROOT}/spec/spec.opts\""] 
    5897    t.spec_files = FileList['vendor/plugins/**/spec/**/*_spec.rb'].exclude('vendor/plugins/rspec/*').exclude("vendor/plugins/rspec-rails/*") 
    5998  end 
    60    
     99 
    61100  namespace :plugins do 
    62101    desc "Runs the examples for rspec_on_rails" 
     
    75114    ::STATS_DIRECTORIES << %w(Helper\ specs spec/helpers) if File.exist?('spec/helpers') 
    76115    ::STATS_DIRECTORIES << %w(Library\ specs spec/lib) if File.exist?('spec/lib') 
     116    ::STATS_DIRECTORIES << %w(Routing\ specs spec/routing) if File.exist?('spec/routing') 
     117    ::STATS_DIRECTORIES << %w(Integration\ specs spec/integration) if File.exist?('spec/integration') 
    77118    ::CodeStatistics::TEST_TYPES << "Model specs" if File.exist?('spec/models') 
    78119    ::CodeStatistics::TEST_TYPES << "View specs" if File.exist?('spec/views') 
     
    80121    ::CodeStatistics::TEST_TYPES << "Helper specs" if File.exist?('spec/helpers') 
    81122    ::CodeStatistics::TEST_TYPES << "Library specs" if File.exist?('spec/lib') 
    82     ::STATS_DIRECTORIES.delete_if {|a| a[0] =~ /test/} 
     123    ::CodeStatistics::TEST_TYPES << "Routing specs" if File.exist?('spec/routing') 
     124    ::CodeStatistics::TEST_TYPES << "Integration specs" if File.exist?('spec/integration') 
    83125  end 
    84126 
    85127  namespace :db do 
    86128    namespace :fixtures do 
    87       desc "Load fixtures (from spec/fixtures) into the current environment's database.  Load specific fixtures using FIXTURES=x,y" 
     129      desc "Load fixtures (from spec/fixtures) into the current environment's database.  Load specific fixtures using FIXTURES=x,y. Load from subdirectory in test/fixtures using FIXTURES_DIR=z." 
    88130      task :load => :environment do 
     131        ActiveRecord::Base.establish_connection(Rails.env) 
     132        base_dir = File.join(Rails.root, 'spec', 'fixtures') 
     133        fixtures_dir = ENV['FIXTURES_DIR'] ? File.join(base_dir, ENV['FIXTURES_DIR']) : base_dir 
     134 
    89135        require 'active_record/fixtures' 
    90         ActiveRecord::Base.establish_connection(RAILS_ENV.to_sym) 
    91         (ENV['FIXTURES'] ? ENV['FIXTURES'].split(/,/) : Dir.glob(File.join(RAILS_ROOT, 'spec', 'fixtures', '*.{yml,csv}'))).each do |fixture_file| 
    92           Fixtures.create_fixtures('spec/fixtures', File.basename(fixture_file, '.*')) 
     136        (ENV['FIXTURES'] ? ENV['FIXTURES'].split(/,/).map {|f| File.join(fixtures_dir, f) } : Dir.glob(File.join(fixtures_dir, '*.{yml,csv}'))).each do |fixture_file| 
     137          Fixtures.create_fixtures(File.dirname(fixture_file), File.basename(fixture_file, '.*')) 
    93138        end 
    94139      end 
    95140    end 
    96141  end 
     142end 
    97143 
    98   namespace :server do 
    99     daemonized_server_pid = File.expand_path("spec_server.pid", RAILS_ROOT + "/tmp") 
    100  
    101     desc "start spec_server." 
    102     task :start do 
    103       if File.exist?(daemonized_server_pid) 
    104         $stderr.puts "spec_server is already running." 
    105       else 
    106         $stderr.puts "Starting up spec server." 
    107         system("ruby", "script/spec_server", "--daemon", "--pid", daemonized_server_pid) 
    108       end 
    109     end 
    110  
    111     desc "stop spec_server." 
    112     task :stop do 
    113       unless File.exist?(daemonized_server_pid) 
    114         $stderr.puts "No server running." 
    115       else 
    116         $stderr.puts "Shutting down spec_server." 
    117         system("kill", "-s", "TERM", File.read(daemonized_server_pid).strip) &&  
    118         File.delete(daemonized_server_pid) 
    119       end 
    120     end 
    121  
    122     desc "reload spec_server." 
    123     task :restart do 
    124       unless File.exist?(daemonized_server_pid) 
    125         $stderr.puts "No server running." 
    126       else 
    127         $stderr.puts "Reloading down spec_server." 
    128         system("kill", "-s", "USR2", File.read(daemonized_server_pid).strip) 
    129       end 
    130     end 
    131   end 
    132144end 
  • script/autospec

    re6ecc4a r6b20631  
    11#!/usr/bin/env ruby 
    2 ENV['RSPEC'] = 'true' 
    3 system 'autotest' 
     2gem 'test-unit', '1.2.3' if RUBY_VERSION.to_f >= 1.9 
     3ENV['RSPEC'] = 'true'     # allows autotest to discover rspec 
     4ENV['AUTOTEST'] = 'true'  # allows autotest to run w/ color on linux 
     5system((RUBY_PLATFORM =~ /mswin|mingw/ ? 'autotest.bat' : 'autotest'), *ARGV) || 
     6  $stderr.puts("Unable to find autotest.  Please install ZenTest or fix your PATH") 
  • script/spec

    re6ecc4a r6b20631  
    11#!/usr/bin/env ruby 
    2 $LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__) + "/../vendor/plugins/rspec/lib")) 
    3 require 'spec' 
    4 exit ::Spec::Runner::CommandLine.run(::Spec::Runner::OptionParser.parse(ARGV, STDERR, STDOUT)) 
     2if ARGV.any? {|arg| %w[--drb -X --generate-options -G --help -h --version -v].include?(arg)} 
     3  require 'rubygems' unless ENV['NO_RUBYGEMS'] 
     4else 
     5  gem 'test-unit', '1.2.3' if RUBY_VERSION.to_f >= 1.9 
     6  ENV["RAILS_ENV"] ||= 'test' 
     7  require File.expand_path(File.dirname(__FILE__) + "/../config/environment") unless defined?(RAILS_ROOT) 
     8end 
     9require 'spec/autorun' 
     10exit ::Spec::Runner::CommandLine.run 
  • spec/rcov.opts

    re6ecc4a r6b20631  
    1 --exclude "spec/*,gems/*"  
     1--exclude "spec/*,gems/*" 
    22--rails 
  • spec/spec_helper.rb

    r5a6a44c r6b20631  
    11# This file is copied to ~/spec when you run 'ruby script/generate rspec' 
    22# from the project root directory. 
    3 ENV["RAILS_ENV"] = "test" 
    4 require File.expand_path(File.dirname(__FILE__) + "/../config/environment") 
    5 require 'spec' 
     3ENV["RAILS_ENV"] ||= 'test' 
     4require File.expand_path(File.join(File.dirname(__FILE__),'..','config','environment')) 
     5require 'spec/autorun' 
    66require 'spec/rails' 
    77 
    8 require 'factory_girl' 
    9 include AuthenticatedTestHelper 
     8# Uncomment the next line to use webrat's matchers 
     9#require 'webrat/integrations/rspec-rails' 
    1010 
    11 require File.expand_path(File.dirname(__FILE__) + "/template_example_group") 
     11# Requires supporting files with custom matchers and macros, etc, 
     12# in ./support/ and its subdirectories. 
     13Dir[File.expand_path(File.join(File.dirname(__FILE__),'support','**','*.rb'))].each {|f| require f} 
    1214 
    1315Spec::Runner.configure do |config| 
     
    3739  # 
    3840  # config.fixture_path = RAILS_ROOT + '/spec/fixtures/' 
    39  
    4041  # 
    4142  # == Mock Framework 
    4243  # 
    43   # RSpec uses it's own mocking framework by default. If you prefer to 
     44  # RSpec uses its own mocking framework by default. If you prefer to 
    4445  # use mocha, flexmock or RR, uncomment the appropriate line: 
    4546  # 
     
    4950  # 
    5051  # == Notes 
    51   #  
    52   # For more information take a look at Spec::Example::Configuration and Spec::Runner 
     52  # 
     53  # For more information take a look at Spec::Runner::Configuration and Spec::Runner 
    5354end