Skip to content

Instantly share code, notes, and snippets.

@itsterry
Created February 11, 2014 16:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save itsterry/8938002 to your computer and use it in GitHub Desktop.
Save itsterry/8938002 to your computer and use it in GitHub Desktop.
Default spec_helper.rb
require "spork"
Spork.prefork do
ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
require 'email_spec'
require 'rspec/autorun'
require 'factory_girl'
# ---------------------------------------------------
# Webmock, to stup external REST APIs
# https://github.com/bblimke/webmock
# http://robots.thoughtbot.com/how-to-stub-external-services-in-tests
require 'webmock/rspec'
# this generally allows all network connections, so that only
# explicitly stubbed URLs will be mocked.
WebMock.allow_net_connect!
#WebMock.disable_net_connect!(allow_localhost: true)
# ---------------------------------------------------
# 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 }
include Devise::TestHelpers # see spec/support/devise.rb
include CarrierWave::Test::Matchers
include Terrys_rspec_helpers
# Checks for pending migrations before tests are run.
# If you are not using ActiveRecord, you can remove this line.
ActiveRecord::Migration.check_pending! if defined?(ActiveRecord::Migration)
unless ENV['DRB']
require "coveralls"
Coveralls.wear!('rails')
require "simplecov"
SimpleCov.coverage_dir "#{Rails.root}/coverage"
SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
SimpleCov::Formatter::HTMLFormatter,
Coveralls::SimpleCov::Formatter
]
SimpleCov.start 'rails'
end
RSpec.configure do |config|
config.include(EmailSpec::Helpers)
config.include(EmailSpec::Matchers)
config.include ValidateUserRequestHelper, :type => :request
config.include ValidateAdminRequestHelper, :type => :request
# ## Mock Framework
#
# 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
config.mock_with :rspec
# Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
config.fixture_path = "#{::Rails.root}/spec/fixtures"
# 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 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
# Run specs in random order to surface order dependencies. If you find an
# order dependency and want to debug it, you can fix the order by providing
# the seed, which is printed after each run.
# --seed 1234
#config.order = "random"
# a random order makes testing the Sanza API cache difficult
config.before(:suite) do
DatabaseCleaner.strategy = :truncation
end
config.before(:each) do
DatabaseCleaner.start
end
end
end
Spork.each_run do
if ENV['DRB']
require "simplecov"
SimpleCov.coverage_dir "#{Rails.root}/coverage"
SimpleCov.start 'rails'
end
FactoryGirl.factories.clear
FactoryGirl.define do
sequence(:slug) { |n| "slug#{n}#{rand(1000000)}" }
sequence(:title) { |n| "title#{n}" }
sequence(:email) { |n| "test#{n}@test.com" }
end
Dir[Rails.root.join("spec/factories/**/*.rb")].each{|f| load f}
Lac::Application.reload_routes!
DatabaseCleaner.clean
end
if Spork.using_spork?
ActiveSupport::Dependencies.clear
#ActiveRecord::Base.instantiate_observers
end
#see also application.rb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment