mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Merge pull request #10677 from mkllnk/spec-helpers
Simplify spec helpers
This commit is contained in:
@@ -57,6 +57,24 @@ RSpec.configure do |config|
|
||||
# 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.
|
||||
#
|
||||
# Setting this to true keeps the database clean by rolling back any changes.
|
||||
config.use_transactional_fixtures = true
|
||||
|
||||
# Some tests don't work within a transaction. Then we use DatabaseCleaner.
|
||||
config.before(:each, concurrency: true) do
|
||||
config.use_transactional_fixtures = false
|
||||
DatabaseCleaner.strategy = :deletion, { except: ['spree_countries', 'spree_states'] }
|
||||
DatabaseCleaner.start
|
||||
end
|
||||
config.append_after(:each, concurrency: true) do
|
||||
DatabaseCleaner.clean
|
||||
config.use_transactional_fixtures = true
|
||||
end
|
||||
|
||||
# If true, the base class of anonymous controllers will be inferred
|
||||
# automatically. This will be the default behavior in future versions of
|
||||
# rspec-rails.
|
||||
@@ -124,6 +142,7 @@ RSpec.configure do |config|
|
||||
|
||||
config.infer_spec_type_from_file_location!
|
||||
|
||||
# Helpers
|
||||
config.include FactoryBot::Syntax::Methods
|
||||
config.include JsonSpec::Helpers
|
||||
|
||||
@@ -141,6 +160,13 @@ RSpec.configure do |config|
|
||||
config.include ActiveJob::TestHelper
|
||||
config.include ReportsHelper
|
||||
|
||||
config.include ViewComponent::TestHelpers, type: :component
|
||||
|
||||
config.include ControllerRequestsHelper, type: :controller
|
||||
config.include Devise::Test::ControllerHelpers, type: :controller
|
||||
config.include OpenFoodNetwork::ApiHelper, type: :controller
|
||||
config.include OpenFoodNetwork::ControllerHelper, type: :controller
|
||||
|
||||
config.include Features::DatepickerHelper, type: :system
|
||||
config.include DownloadsHelper, type: :system
|
||||
end
|
||||
|
||||
@@ -1,22 +1,9 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'base_spec_helper'
|
||||
|
||||
require 'database_cleaner'
|
||||
require 'view_component/test_helpers'
|
||||
|
||||
RSpec.configure do |config|
|
||||
# DatabaseCleaner
|
||||
config.before(:suite) {
|
||||
DatabaseCleaner.clean_with :deletion, except: ['spree_countries', 'spree_states']
|
||||
}
|
||||
config.before(:each) { DatabaseCleaner.strategy = :transaction }
|
||||
config.before(:each, concurrency: true) {
|
||||
DatabaseCleaner.strategy = :deletion, { except: ['spree_countries', 'spree_states'] }
|
||||
}
|
||||
config.before(:each) { DatabaseCleaner.start }
|
||||
config.after(:each) { DatabaseCleaner.clean }
|
||||
|
||||
# Precompile Webpacker assets (once) when starting the suite. The default setup can result
|
||||
# in the assets getting compiled many times throughout the build, slowing it down.
|
||||
config.before :suite do
|
||||
@@ -26,20 +13,6 @@ RSpec.configure do |config|
|
||||
# Fix encoding issue in Rails 5.0; allows passing empty arrays or hashes as params.
|
||||
config.before(:each, type: :controller) { @request.env["CONTENT_TYPE"] = 'application/json' }
|
||||
|
||||
# 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
|
||||
|
||||
# You can use `rspec -n` to run only failed specs.
|
||||
config.example_status_persistence_file_path = "tmp/rspec-status.txt"
|
||||
|
||||
# Helpers
|
||||
config.include ViewComponent::TestHelpers, type: :component
|
||||
config.include ControllerRequestsHelper, type: :controller
|
||||
config.include Devise::Test::ControllerHelpers, type: :controller
|
||||
config.include OpenFoodNetwork::ApiHelper, type: :controller
|
||||
config.include OpenFoodNetwork::ControllerHelper, type: :controller
|
||||
config.include Features::DatepickerHelper, type: :feature
|
||||
config.include DownloadsHelper, type: :feature
|
||||
end
|
||||
|
||||
@@ -33,9 +33,6 @@ RSpec.configure do |config|
|
||||
|
||||
config.prepend_before(:each, type: :system) { driven_by :cuprite }
|
||||
|
||||
# System tests use transactional fixtures instead of DatabaseCleaner
|
||||
config.use_transactional_fixtures = true
|
||||
|
||||
# Make sure url helpers in mailers use the Capybara server host.
|
||||
config.around(:each, type: :system) do |example|
|
||||
original_host = Rails.application.default_url_options[:host]
|
||||
|
||||
Reference in New Issue
Block a user