Created
March 14, 2012 06:23
-
-
Save pda/2034589 to your computer and use it in GitHub Desktop.
Fast RSpec with a tiered environment: SPEC=(unit|model|full) rspec …
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mode = ENV["SPEC"] || "full" | |
require_relative "spec_helper_#{mode}" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This file is copied to spec/ when you run 'rails generate rspec:install' | |
ENV["RAILS_ENV"] ||= 'test' | |
require File.expand_path("../../config/environment", __FILE__) | |
require 'rspec/rails' | |
# Requires supporting ruby files with custom matchers and macros, etc, | |
# in spec/support/ and its subdirectories. | |
Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require_relative "spec_helper_unit" | |
ENV["RAILS_ENV"] ||= "test" | |
# ActiveRecord | |
require "yaml" | |
require "active_record" | |
ActiveRecord::Base.establish_connection( | |
YAML.load(File.read(RAILS_ROOT + "config/database.yml"))["test"] | |
) | |
# factory_girl | |
require_relative "factories" | |
require_relative "support/factory_girl" | |
# DatabaseCleaner | |
require "database_cleaner" | |
RSpec.configure do |config| | |
config.before(:suite) do | |
DatabaseCleaner.strategy = :transaction | |
DatabaseCleaner.clean_with(:truncation) | |
end | |
config.before(:each) do | |
DatabaseCleaner.start | |
end | |
config.after(:each) do | |
DatabaseCleaner.clean | |
end | |
end | |
# Enter database configurations into ActiveRecord | |
ActiveRecord::Base.send(:configurations=, YAML::load(ERB.new(IO.read(RAILS_ROOT + "config/database.yml")).result)) | |
# We hates Devise :( | |
class ActiveRecord::Base | |
def self.devise *parameters; end; def self.define_index *parameters; end#; def configurations; configs; end | |
end | |
module Devise; module Models; module Recoverable; end end end | |
class User < ActiveRecord::Base; attr_writer :password; def self.has_own_preferences *parameters; end end | |
require_relative "../app/models/user" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "pathname" | |
RAILS_ROOT = Pathname.new(File.expand_path("../..", __FILE__)) | |
# ActiveSupport | |
require "active_support" | |
require "active_support/dependencies" | |
%w{ extensions forms helpers mailers models presenters scripts }.each do |dir| | |
ActiveSupport::Dependencies.autoload_paths << | |
File.expand_path("../../app/#{dir}", __FILE__) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment