Skip to content

Instantly share code, notes, and snippets.

@olkeene
Created March 1, 2016 10:59
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 olkeene/5e12815e99bfc25ecc45 to your computer and use it in GitHub Desktop.
Save olkeene/5e12815e99bfc25ecc45 to your computer and use it in GitHub Desktop.
require 'spec_helper'
# Some crufty requires omitted here
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 = false
# 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
# rspec-rails 3 will no longer automatically infer an example group's spec type
# from the file location. You can explicitly opt-in to the feature using this
# config option.
config.infer_spec_type_from_file_location!
config.include ActiveSupport::Testing::TimeHelpers
config.include(EmailSpec::Helpers)
config.include(EmailSpec::Matchers)
config.include ArchivableSpecHelper, type: :model
config.include IssueSharedGroups, type: :model
config.include Devise::TestHelpers, type: :controller
config.include ControllerSharedGroups, type: :controller
config.extend AuthenticationHelper, type: :controller
config.include Helpers::CurrentUserSupport, type: :view
config.include ViewSharedGroups, type: :view
config.extend ViewMacros, type: :view
config.include FeatureHelper, type: :feature
config.extend Features::AuthenticationClassSupport, type: :feature
config.include Features::AuthenticationSupport, type: :feature
config.include Features::MembershipSelectionSupport, type: :feature
config.include Features::RailsAdminArchiveSupport, type: :feature
config.include Features::RailsAdminDeleteSupport, type: :feature
config.include Features::UserSupport, type: :feature
config.before(:suite) do
DatabaseCleaner.strategy = :transaction
DatabaseCleaner.clean_with(:truncation)
end
config.after(:each) do |example|
if example.exception && example.metadata[:js]
meta = example.metadata
filename = File.basename(meta[:file_path])
line_number = meta[:line_number]
screenshot_name = "screenshot-#{filename}-#{line_number}.png"
screenshot_path = "#{Rails.root.join("tmp")}/#{screenshot_name}"
html_name = "page-#{filename}-#{line_number}.html"
html_path = "#{Rails.root.join("tmp")}/#{html_name}"
page.save_page(html_path)
page.save_screenshot(screenshot_path)
puts meta[:full_description] + "\n HTML: #{html_path}"
puts meta[:full_description] + "\n Screenshot: #{screenshot_path}"
end
end
config.around(:each, js: true) do |ex|
DatabaseCleaner.strategy = :truncation
ex.run
DatabaseCleaner.strategy = :transaction
end
config.around(:each, truncation: true) do |ex|
DatabaseCleaner.strategy = :truncation
ex.run
DatabaseCleaner.strategy = :transaction
end
config.before(:each) do
DatabaseCleaner.start
end
config.after(:each) do |example|
DatabaseCleaner.clean
end
### START - Sidekiq configuration for tests
config.before(:each) do
# Clears out the jobs for tests using the fake testing
Sidekiq::Worker.clear_all
end
config.around(:each) do |example|
if example.metadata[:sidekiq] == :fake
Sidekiq::Testing.fake!(&example)
elsif example.metadata[:sidekiq] == :inline
Sidekiq::Testing.inline!(&example)
elsif example.metadata[:type] == :feature
Sidekiq::Testing.inline!(&example)
else
Sidekiq::Testing.fake!(&example)
end
end
### END - Sidekiq configuration for tests
# Carrierwave settings for testing
config.after(:all) do
# See initializers/carrierwave.rb
uploaded_files_path = Rails.root.join("public", "test_assets")
FileUtils.rm_r(uploaded_files_path) if File.exists?(uploaded_files_path)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment