Skip to content

Instantly share code, notes, and snippets.

@joxxoxo
Created May 10, 2013 06:33
Show Gist options
  • Save joxxoxo/5552738 to your computer and use it in GitHub Desktop.
Save joxxoxo/5552738 to your computer and use it in GitHub Desktop.
require 'rubygems'
ENV["RAILS_ENV"] ||= 'test'
if defined? SimpleCov
require 'simplecov'
SimpleCov.start 'rails'
end
require 'rails/application'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
require 'rspec/autorun'
require 'cancan/matchers'
require 'capybara/rspec'
require 'factory_girl_rails'
# Check pending migrations
pending_migrations = ActiveRecord::Migrator.new(:up, ActiveRecord::Migrator.migrations_paths).pending_migrations
if pending_migrations.any?
puts "You have pending migrations:\n#{pending_migrations.map(&:filename) * "\n"}"
exit 1
end
RSpec.configure do |config|
# If you're not using ActiveRecord, or you'd prefer not to run each of your
# examples within a transaction, remove the following line or assign false
# instead of true.
config.use_transactional_fixtures = true
if ENV['ZEUS_MASTER_FD']
config.before :all do
FactoryGirl.reload
end
end
# To separate specs' logs
config.before do
Rails.logger.warn("\n\n\n#{'='*30}#{example.location}#{'='*30}\n\n\n")
end
# render views in controller specs
config.render_views
config.include Devise::TestHelpers, :type => :controller
# If true, the base class of anonymous controllers will be inferred
# automatically. This will be the default behavior in future versions of
# rspec-rails.
config.infer_base_class_for_anonymous_controllers = false
config.treat_symbols_as_metadata_keys_with_true_values = true
config.filter_run :focus => true
config.run_all_when_everything_filtered = true
config.include Capybara::RSpecMatchers, :type => :helpers
config.include Capybara::RSpecMatchers, :type => :views
end
Capybara.default_wait_time = 10
Capybara.javascript_driver = :webkit
Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| load f }
#Capybara use the same connection
class ActiveRecord::Base
mattr_accessor :shared_connection
@@shared_connection = nil
def self.connection
@@shared_connection || retrieve_connection
end
end
# Forces all threads to share the same connection. This works on
# Capybara because it starts the web server in a thread.
ActiveRecord::Base.shared_connection = ActiveRecord::Base.connection
@benjaminoakes
Copy link

In case it helps someone else, the "Check pending migrations" part wasn't working for us on Rails 3.2.x. It seems to be a Rails 4.0 feature.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment