Changeset 6b20631af609047c42513e3f1bf8907db4e0b659
- 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:
-
Legend:
- Unmodified
- Added
- Removed
-
|
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])) |
| | 1 | gem 'test-unit', '1.2.3' if RUBY_VERSION.to_f >= 1.9 |
| | 2 | rspec_gem_dir = nil |
| | 3 | Dir["#{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") |
| | 5 | end |
| | 6 | rspec_plugin_dir = File.expand_path(File.dirname(__FILE__) + '/../../vendor/plugins/rspec') |
| 3 | 7 | |
| 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' |
| | 8 | if 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" |
| | 10 | end |
| | 11 | |
| | 12 | if rspec_gem_dir |
| | 13 | $LOAD_PATH.unshift("#{rspec_gem_dir}/lib") |
| | 14 | elsif File.exist?(rspec_plugin_dir) |
| | 15 | $LOAD_PATH.unshift("#{rspec_plugin_dir}/lib") |
| | 16 | end |
| | 17 | |
| | 18 | # Don't load rspec if running "rake gems:*" |
| | 19 | unless ARGV.any? {|a| a =~ /^gems/} |
| | 20 | |
| | 21 | begin |
| | 22 | require 'spec/rake/spectask' |
| | 23 | rescue 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} |
| | 40 | MSG |
| | 41 | end |
| | 42 | end |
| | 43 | end |
| | 44 | end |
| | 45 | end |
| | 46 | end |
| | 47 | |
| | 48 | Rake.application.instance_variable_get('@tasks').delete('default') |
| 10 | 49 | |
| 11 | 50 | spec_prereq = File.exist?(File.join(RAILS_ROOT, 'config', 'database.yml')) ? "db:test:prepare" : :noop |
| … |
… |
|
| 32 | 71 | end |
| 33 | 72 | end |
| 34 | | |
| | 73 | |
| 35 | 74 | desc "Print Specdoc for all specs (excluding plugin specs)" |
| 36 | 75 | Spec::Rake::SpecTask.new(:doc) do |t| |
| … |
… |
|
| 39 | 78 | end |
| 40 | 79 | |
| 41 | | desc "Print Specdoc for all plugin specs" |
| | 80 | desc "Print Specdoc for all plugin examples" |
| 42 | 81 | Spec::Rake::SpecTask.new(:plugin_doc) do |t| |
| 43 | 82 | t.spec_opts = ["--format", "specdoc", "--dry-run"] |
| … |
… |
|
| 45 | 84 | end |
| 46 | 85 | |
| 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}" |
| 49 | 88 | Spec::Rake::SpecTask.new(sub => spec_prereq) do |t| |
| 50 | 89 | t.spec_opts = ['--options', "\"#{RAILS_ROOT}/spec/spec.opts\""] |
| … |
… |
|
| 52 | 91 | end |
| 53 | 92 | 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)" |
| 56 | 95 | Spec::Rake::SpecTask.new(:plugins => spec_prereq) do |t| |
| 57 | 96 | t.spec_opts = ['--options', "\"#{RAILS_ROOT}/spec/spec.opts\""] |
| 58 | 97 | t.spec_files = FileList['vendor/plugins/**/spec/**/*_spec.rb'].exclude('vendor/plugins/rspec/*').exclude("vendor/plugins/rspec-rails/*") |
| 59 | 98 | end |
| 60 | | |
| | 99 | |
| 61 | 100 | namespace :plugins do |
| 62 | 101 | desc "Runs the examples for rspec_on_rails" |
| … |
… |
|
| 75 | 114 | ::STATS_DIRECTORIES << %w(Helper\ specs spec/helpers) if File.exist?('spec/helpers') |
| 76 | 115 | ::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') |
| 77 | 118 | ::CodeStatistics::TEST_TYPES << "Model specs" if File.exist?('spec/models') |
| 78 | 119 | ::CodeStatistics::TEST_TYPES << "View specs" if File.exist?('spec/views') |
| … |
… |
|
| 80 | 121 | ::CodeStatistics::TEST_TYPES << "Helper specs" if File.exist?('spec/helpers') |
| 81 | 122 | ::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') |
| 83 | 125 | end |
| 84 | 126 | |
| 85 | 127 | namespace :db do |
| 86 | 128 | 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." |
| 88 | 130 | 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 | |
| 89 | 135 | 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, '.*')) |
| 93 | 138 | end |
| 94 | 139 | end |
| 95 | 140 | end |
| 96 | 141 | end |
| | 142 | end |
| 97 | 143 | |
| 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 |
| 132 | 144 | end |
-
|
re6ecc4a
|
r6b20631
|
|
| 1 | 1 | #!/usr/bin/env ruby |
| 2 | | ENV['RSPEC'] = 'true' |
| 3 | | system 'autotest' |
| | 2 | gem 'test-unit', '1.2.3' if RUBY_VERSION.to_f >= 1.9 |
| | 3 | ENV['RSPEC'] = 'true' # allows autotest to discover rspec |
| | 4 | ENV['AUTOTEST'] = 'true' # allows autotest to run w/ color on linux |
| | 5 | system((RUBY_PLATFORM =~ /mswin|mingw/ ? 'autotest.bat' : 'autotest'), *ARGV) || |
| | 6 | $stderr.puts("Unable to find autotest. Please install ZenTest or fix your PATH") |
-
|
re6ecc4a
|
r6b20631
|
|
| 1 | 1 | #!/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)) |
| | 2 | if ARGV.any? {|arg| %w[--drb -X --generate-options -G --help -h --version -v].include?(arg)} |
| | 3 | require 'rubygems' unless ENV['NO_RUBYGEMS'] |
| | 4 | else |
| | 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) |
| | 8 | end |
| | 9 | require 'spec/autorun' |
| | 10 | exit ::Spec::Runner::CommandLine.run |
-
|
re6ecc4a
|
r6b20631
|
|
| 1 | | --exclude "spec/*,gems/*" |
| | 1 | --exclude "spec/*,gems/*" |
| 2 | 2 | --rails |
-
|
r5a6a44c
|
r6b20631
|
|
| 1 | 1 | # This file is copied to ~/spec when you run 'ruby script/generate rspec' |
| 2 | 2 | # from the project root directory. |
| 3 | | ENV["RAILS_ENV"] = "test" |
| 4 | | require File.expand_path(File.dirname(__FILE__) + "/../config/environment") |
| 5 | | require 'spec' |
| | 3 | ENV["RAILS_ENV"] ||= 'test' |
| | 4 | require File.expand_path(File.join(File.dirname(__FILE__),'..','config','environment')) |
| | 5 | require 'spec/autorun' |
| 6 | 6 | require 'spec/rails' |
| 7 | 7 | |
| 8 | | require 'factory_girl' |
| 9 | | include AuthenticatedTestHelper |
| | 8 | # Uncomment the next line to use webrat's matchers |
| | 9 | #require 'webrat/integrations/rspec-rails' |
| 10 | 10 | |
| 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. |
| | 13 | Dir[File.expand_path(File.join(File.dirname(__FILE__),'support','**','*.rb'))].each {|f| require f} |
| 12 | 14 | |
| 13 | 15 | Spec::Runner.configure do |config| |
| … |
… |
|
| 37 | 39 | # |
| 38 | 40 | # config.fixture_path = RAILS_ROOT + '/spec/fixtures/' |
| 39 | | |
| 40 | 41 | # |
| 41 | 42 | # == Mock Framework |
| 42 | 43 | # |
| 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 |
| 44 | 45 | # use mocha, flexmock or RR, uncomment the appropriate line: |
| 45 | 46 | # |
| … |
… |
|
| 49 | 50 | # |
| 50 | 51 | # == 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 |
| 53 | 54 | end |