Permalink
Browse files

Use Rails config to determine whether or not we're using AR

- defined?(:ActiveRecord) is unreliable
  • Loading branch information...
1 parent d59ff2b commit bbcebcd40367fe64ca9b22dd73c29d600ff7e210 @dchelimsky dchelimsky committed Sep 5, 2010
View
@@ -1,3 +1,13 @@
+module RSpec
+ module Rails
+ class << self
+ def using_active_record?
+ ::Rails.configuration.generators.options[:rails][:orm] == :active_record
+ end
+ end
+ end
+end
+
require 'rspec/core'
require 'rspec/rails/extensions'
require 'rspec/rails/view_rendering'
@@ -1,6 +1,6 @@
-if defined?(ActiveRecord::Base)
- module RSpec
- module Rails
+module RSpec
+ module Rails
+ if using_active_record?
module Extensions
module ActiveRecord
module ClassMethods
@@ -33,12 +33,12 @@ def errors_on(attribute)
end
end
end
- end
- end
- class ActiveRecord::Base #:nodoc:
- extend RSpec::Rails::Extensions::ActiveRecord::ClassMethods
- include RSpec::Rails::Extensions::ActiveRecord::InstanceMethods
+ class ::ActiveRecord::Base #:nodoc:
+ extend RSpec::Rails::Extensions::ActiveRecord::ClassMethods
+ include RSpec::Rails::Extensions::ActiveRecord::InstanceMethods
+ end
+ end
end
end
@@ -1,31 +1,30 @@
-if defined?(ActiveRecord)
- module RSpec
- module Rails
+module RSpec
+ module Rails
+ if using_active_record?
module FixtureSupport
extend ActiveSupport::Concern
include RSpec::Rails::SetupAndTeardownAdapter
include RSpec::Rails::TestUnitAssertionAdapter
+ include ActiveRecord::TestFixtures
included do
- # TODO - figure out how to move this outside the included block
- include ActiveRecord::TestFixtures
-
self.fixture_path = RSpec.configuration.fixture_path
self.use_transactional_fixtures = RSpec.configuration.use_transactional_fixtures
self.use_instantiated_fixtures = RSpec.configuration.use_instantiated_fixtures
fixtures RSpec.configuration.global_fixtures if RSpec.configuration.global_fixtures
end
end
- end
- end
- RSpec.configure do |c|
- c.include RSpec::Rails::FixtureSupport
- c.add_setting :use_transactional_fixtures
- c.add_setting :use_transactional_examples, :alias => :use_transactional_fixtures
- c.add_setting :use_instantiated_fixtures
- c.add_setting :global_fixtures
- c.add_setting :fixture_path
+ RSpec.configure do |c|
+ c.include RSpec::Rails::FixtureSupport
+ c.add_setting :use_transactional_fixtures
+ c.add_setting :use_transactional_examples, :alias => :use_transactional_fixtures
+ c.add_setting :use_instantiated_fixtures
+ c.add_setting :global_fixtures
+ c.add_setting :fixture_path
+ end
+ end
end
end
+
@@ -1,7 +1,8 @@
require 'rspec/core'
require 'rspec/core/rake_task'
Rake.application.instance_variable_get('@tasks')['default'].prerequisites.delete('test')
-spec_prereq = Rails.root.join('config', 'database.yml').exist? ? "db:test:prepare" : :noop
+
+spec_prereq = Rails.configuration.generators.options[:rails][:orm] == :active_record ? "db:test:prepare" : :noop
task :noop do; end
task :default => :spec
@@ -0,0 +1,17 @@
+require "spec_helper"
+
+module RSpec::Rails
+ describe FixtureSupport do
+ context "with use_transactional_fixtures set to false" do
+ it "still supports fixture_path" do
+ RSpec.configuration.stub(:use_transactional_fixtures) { false }
+ group = RSpec::Core::ExampleGroup.describe do
+ include FixtureSupport
+ end
+
+ group.should respond_to(:fixture_path)
+ group.should respond_to(:fixture_path=)
+ end
+ end
+ end
+end
View
@@ -1,6 +1,10 @@
-require 'active_record'
-require 'action_controller'
-require 'action_mailer'
+require 'rails/all'
+
+module RSpecRails
+ class Application < ::Rails::Application
+ end
+end
+
require 'rspec/rails'
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}

0 comments on commit bbcebcd

Please sign in to comment.