# This file is copied to spec/ when you run 'rails generate rspec:install' require 'spec_helper' ENV['RAILS_ENV'] ||= 'test' require_relative '../config/environment' # Prevent database truncation if the environment is production if Rails.env.production? abort('The Rails environment is running in production mode!') end # Uncomment the line below in case you have `--require rails_helper` in the `.rspec` file # that will avoid rails generators crashing because migrations haven't been run yet # return unless Rails.env.test? require 'rspec/rails' # Each turbo_tests worker boots with an empty test.sqlite3, so we have to # load db/schema.rb on demand — there is no separate db:test:prepare step. ActiveRecord::Migration.maintain_test_schema! # Add additional requires below this line. Rails is not loaded until this point! # Requires supporting ruby files with custom matchers and macros, etc, in # spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` are # run as spec files by default. This means that files in spec/support that end # in _spec.rb will both be required and run as specs, causing the specs to be # run twice. It is recommended that you do not name files matching this glob to # end with _spec.rb. You can configure this pattern with the --pattern # option on the command line or in ~/.rspec, .rspec or `.rspec-local`. # # The following line is provided for convenience purposes. It has the downside # of increasing the boot-up time by auto-requiring all files in the support # directory. Alternatively, in the individual `*_spec.rb` files, manually # require only the support files necessary. # Rails.root.glob('spec/support/**/*.rb').sort_by(&:to_s).each { |f| require f } RSpec.configure do |config| # RSpec Rails uses metadata to mix in different behaviours to your tests, # for example enabling you to call `get` and `post` in request specs. e.g.: # # RSpec.describe UsersController, type: :request do # # ... # end # # The different available types are documented in the features, such as in # https://rspec.info/features/8-0/rspec-rails # # You can also this infer these behaviours automatically by location, e.g. # /spec/models would pull in the same behaviour as `type: :model` but this # behaviour is considered legacy and will be removed in a future version. # # To enable this behaviour uncomment the line below. config.infer_spec_type_from_file_location! # Filter lines from Rails gems in backtraces. config.filter_rails_from_backtrace! # arbitrary gems may also be filtered via: # config.filter_gems_from_backtrace("gem name") # Specs in spec/integration/ drive real Docker and are slow. Tag them by # location so individual files need no explicit metadata. config.define_derived_metadata(file_path: %r{/spec/integration/}) do |metadata| metadata[:integration] = true end # Skip integration specs in local runs; run them explicitly with # `--tag integration`. On CI (ENV['CI'] set) they always run. config.filter_run_excluding(:integration) unless ENV['CI'] # Every parallel worker announces the same filter ("Run options: exclude # {integration: true}") and, when its shard holds no matching file, "All # examples were filtered out". Twenty workers turn that into noise around # the progress dots. A serial `bin/rspec` still announces its filters. config.silence_filter_announcements = true if ENV['TEST_ENV_NUMBER'] # The Anonymizer keeps a per-bundle value→letter registry; reset between # specs so expectations don't depend on the order tests happen to run in. config.before { SupportBundle::Anonymizer.reset_registry! } # Specs under spec/components render a ViewComponent in isolation; the # helpers give them `render_inline` and the Capybara matchers on `page`. # Every component reads Configuration.current, so each starts on a config # of its own — examples that need the directory keep `config_yaml_dir`. config.include ViewComponent::TestHelpers, type: :component config.include Capybara::RSpecMatchers, type: :component config.before(type: :component) { with_config_yaml } # AR rows are scoped to one example via a transaction that's rolled back # at teardown, so a Backup created in one example never leaks into the next. config.use_transactional_fixtures = true end