Last active
August 29, 2015 13:57
-
-
Save justin808/9460750 to your computer and use it in GitHub Desktop.
spec_helper.rb What @railsonmaui uses for testing. See my gist of gems for testing.
This file contains 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
# IMPT: | |
# Configure ENV['LOG_LEVEL'] to be one of DEBUG, INFO, WARN, ERROR, FATAL | |
# figure out where we are being loaded from | |
if $LOADED_FEATURES.grep(/spec\/spec_helper\.rb/).any? | |
begin | |
raise "foo" | |
rescue => e | |
puts <<-MSG | |
=================================================== | |
It looks like spec_helper.rb has been loaded | |
multiple times. Normalize the require to: | |
require "spec/spec_helper" | |
Things like File.join and File.expand_path will | |
cause it to be loaded multiple times. | |
Loaded this time from: | |
#{e.backtrace.join("\n ")} | |
=================================================== | |
MSG | |
end | |
end | |
if ENV["RUBYMINE_HOME"] | |
# this is necessary to run tests in rubymine in case guard is running | |
$:.unshift(File.expand_path("rb/testing/patch/common", ENV["RUBYMINE_HOME"])) | |
$:.unshift(File.expand_path("rb/testing/patch/bdd", ENV["RUBYMINE_HOME"])) | |
end | |
# if below line is used, then warning messages from zeus | |
# But if line is not used and no ENV is set in the shell, then factory girl won't load | |
ENV["RAILS_ENV"] ||= 'test' | |
require File.expand_path("../../config/environment", __FILE__) | |
require 'rspec/rails' | |
require 'capybara-screenshot/rspec' | |
require 'resque_spec/scheduler' | |
# Requires supporting files with custom matchers and macros, etc, | |
# in ./support/ and its subdirectories. | |
Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f } | |
RSpec.configure do |config| | |
config.order = 'random' | |
config.mock_with :rspec | |
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, comment the following line or assign false | |
# instead of true. | |
# config.use_transactional_fixtures = true | |
# http://rainux.github.com/2011/07/23/configure-capybara-webkit-to-run-acceptance-specs-with-javascript-ajax/ | |
config.use_transactional_fixtures = false | |
config.include IntegrationSpecHelper, :type => :request | |
config.include Devise::TestHelpers, :type => :controller | |
config.include ControllerMacros, :type => :controller | |
config.include FactoryGirl::Syntax::Methods | |
config.include ShowMeTheCookies, :type => :feature | |
# VCR setup | |
# so we can use :vcr rather than :vcr => true; | |
# in RSpec 3 this will no longer be necessary. | |
config.treat_symbols_as_metadata_keys_with_true_values = true | |
config.include(MailerMacros) | |
config.before(:each) { reset_email } | |
# http://railscasts.com/episodes/413-fast-tests | |
config.filter_run :focus unless ENV["SKIP_RSPEC_FOCUS"].present? | |
config.run_all_when_everything_filtered = true | |
config.before(:all) { DeferredGarbageCollection.start } | |
config.after(:all) { DeferredGarbageCollection.reconsider } | |
config.mock_with :rspec do |c| | |
c.yield_receiver_to_any_instance_implementation_blocks = true | |
end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment