From 24ed0f638505fe0572c4d243f10507e0897f23bb Mon Sep 17 00:00:00 2001 From: Eric Davis Date: Tue, 20 May 2008 16:00:55 -0700 Subject: [PATCH] Fixed RSpec so only the plugin is loaded. #1135 --- Rakefile | 1 + lib/tasks/rspec.rake | 51 ++++++++++++++++++++++++++++++++++++++++++++ spec/sanity_spec.rb | 2 ++ spec/spec.opts | 7 ++++++ spec/spec_helper.rb | 39 +++++++++++++++++++++++++++++++++ 5 files changed, 100 insertions(+) create mode 100644 Rakefile create mode 100644 lib/tasks/rspec.rake create mode 100644 spec/spec.opts create mode 100644 spec/spec_helper.rb diff --git a/Rakefile b/Rakefile new file mode 100644 index 0000000..cb9d93e --- /dev/null +++ b/Rakefile @@ -0,0 +1 @@ +Dir[File.expand_path(File.dirname(__FILE__)) + "/lib/tasks/**/*.rake"].sort.each { |ext| load ext } diff --git a/lib/tasks/rspec.rake b/lib/tasks/rspec.rake new file mode 100644 index 0000000..0a05f19 --- /dev/null +++ b/lib/tasks/rspec.rake @@ -0,0 +1,51 @@ +# Modifided from the RSpec on Rails plugins +RAILS_ROOT = File.expand_path(File.dirname(__FILE__) + '/../../../') +PLUGIN_ROOT = File.expand_path(File.dirname(__FILE__) + '/../../') + + +# In rails 1.2, plugins aren't available in the path until they're loaded. +# Check to see if the rspec plugin is installed first and require +# it if it is. If not, use the gem version. +rspec_base = File.expand_path(File.dirname(__FILE__) + '/../rspec/lib') +$LOAD_PATH.unshift(rspec_base) if File.exist?(rspec_base) +require 'spec/rake/spectask' +require 'spec/translator' + +spec_prereq = File.exist?(File.join(RAILS_ROOT, 'config', 'database.yml')) ? "db:test:prepare" : :noop +task :noop do +end + +task :default => :spec +task :stats => "spec:statsetup" + +desc "Run all specs in spec directory (excluding plugin specs)" +Spec::Rake::SpecTask.new(:spec => spec_prereq) do |t| + t.spec_opts = ['--options', "\"#{PLUGIN_ROOT}/spec/spec.opts\""] + t.spec_files = FileList['spec/**/*_spec.rb'] +end + +namespace :spec do + desc "Run all specs in spec directory with RCov (excluding plugin specs)" + Spec::Rake::SpecTask.new(:rcov) do |t| + t.spec_opts = ['--options', "\"#{PLUGIN_ROOT}/spec/spec.opts\""] + t.spec_files = FileList['spec/**/*_spec.rb'] + t.rcov = true + t.rcov_opts = lambda do + IO.readlines("#{PLUGIN_ROOT}/spec/rcov.opts").map {|l| l.chomp.split " "}.flatten + end + end + + desc "Print Specdoc for all specs (excluding plugin specs)" + Spec::Rake::SpecTask.new(:doc) do |t| + t.spec_opts = ["--format", "specdoc", "--dry-run"] + t.spec_files = FileList['spec/**/*_spec.rb'] + end + + [:models, :controllers, :views, :helpers, :lib].each do |sub| + desc "Run the specs under spec/#{sub}" + Spec::Rake::SpecTask.new(sub => spec_prereq) do |t| + t.spec_opts = ['--options', "\"#{PLUGIN_ROOT}/spec/spec.opts\""] + t.spec_files = FileList["spec/#{sub}/**/*_spec.rb"] + end + end +end diff --git a/spec/sanity_spec.rb b/spec/sanity_spec.rb index 2b338e5..6de6672 100644 --- a/spec/sanity_spec.rb +++ b/spec/sanity_spec.rb @@ -1,3 +1,5 @@ +require File.dirname(__FILE__) + '/spec_helper' + describe Class do it "should be a class of Class" do Class.class.should eql(Class) diff --git a/spec/spec.opts b/spec/spec.opts new file mode 100644 index 0000000..2144705 --- /dev/null +++ b/spec/spec.opts @@ -0,0 +1,7 @@ +--colour +--format +progress +--loadby +mtime +--reverse +--backtrace \ No newline at end of file diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb new file mode 100644 index 0000000..421b198 --- /dev/null +++ b/spec/spec_helper.rb @@ -0,0 +1,39 @@ +# This file is copied to ~/spec when you run 'ruby script/generate rspec' +# from the project root directory. +ENV["RAILS_ENV"] = "test" +require File.expand_path(File.dirname(__FILE__) + "/../../../../config/environment") +require 'spec' +require 'spec/rails' + +Spec::Runner.configure do |config| + # If you're not using ActiveRecord you should remove these + # lines, delete config/database.yml and disable :active_record + # in your config/boot.rb + config.use_transactional_fixtures = true + config.use_instantiated_fixtures = false + config.fixture_path = RAILS_ROOT + '/spec/fixtures/' + + # == Fixtures + # + # You can declare fixtures for each example_group like this: + # describe "...." do + # fixtures :table_a, :table_b + # + # Alternatively, if you prefer to declare them only once, you can + # do so right here. Just uncomment the next line and replace the fixture + # names with your fixtures. + # + # config.global_fixtures = :table_a, :table_b + # + # If you declare global fixtures, be aware that they will be declared + # for all of your examples, even those that don't use them. + # + # == Mock Framework + # + # RSpec uses it's own mocking framework by default. If you prefer to + # use mocha, flexmock or RR, uncomment the appropriate line: + # + # config.mock_with :mocha + # config.mock_with :flexmock + # config.mock_with :rr +end