hensei-api/spec/rails_helper.rb
Justin Edmund 872b6fdb59 add crew specs and fix error handling
- add transactional fixtures to rails_helper for test isolation
- restructure crew errors to CrewErrors module for Zeitwerk
- add rescue_from for CrewErrors::CrewError in api_controller
- add model specs for Crew and CrewMembership (34 examples)
- add controller specs for crews and memberships (28 examples)
- add crew-related specs to User model (22 examples)
- add factories for crews and crew_memberships
2025-12-03 22:51:34 -08:00

93 lines
3.8 KiB
Ruby
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# frozen_string_literal: true
# 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
abort('The Rails environment is running in production mode!') if Rails.env.production?
# Load Rails and RSpec Rails Rails is not loaded until after the environment is set.
require 'rspec/rails'
# -----------------------------------------------------------------------------
# Additional Requires:
#
# Add any additional requires below this line. For example, if you need to load
# custom libraries or support files that are not automatically required.
# -----------------------------------------------------------------------------
# -----------------------------------------------------------------------------
# Require Support Files:
#
# All files in the spec/support directory and its subdirectories (except those
# ending in _spec.rb) are automatically required here. This is useful for custom
# matchers, macros, and shared contexts.
# -----------------------------------------------------------------------------
Dir[Rails.root.join('spec', 'support', '**', '*.rb')].sort.each { |f| require f }
# -----------------------------------------------------------------------------
# Check for Pending Migrations:
#
# This will check for any pending migrations before tests are run.
# -----------------------------------------------------------------------------
begin
ActiveRecord::Migration.maintain_test_schema!
rescue ActiveRecord::PendingMigrationError => e
abort e.to_s.strip
end
RSpec.configure do |config|
# -----------------------------------------------------------------------------
# Use transactional fixtures:
#
# Wrap each example in a database transaction that is rolled back after the
# example completes. This ensures test isolation without needing to truncate
# or delete data between tests.
# -----------------------------------------------------------------------------
config.use_transactional_fixtures = true
# Disable ActiveRecord logging during tests for a cleaner test output.
ActiveRecord::Base.logger = nil if Rails.env.test?
# -----------------------------------------------------------------------------
# Shoulda Matchers:
#
# If you use shoulda-matchers, you can configure them here. (Make sure you have
# the shoulda-matchers gem installed and configured in your Gemfile.)
# -----------------------------------------------------------------------------
require 'shoulda/matchers'
Shoulda::Matchers.configure do |matcher_config|
matcher_config.integrate do |with|
with.test_framework :rspec
with.library :rails
end
end
# -----------------------------------------------------------------------------
# FactoryBot Syntax Methods:
#
# This makes methods like create and build available without needing to prefix
# them with FactoryBot.
# -----------------------------------------------------------------------------
config.include FactoryBot::Syntax::Methods
# -----------------------------------------------------------------------------
# Load canonical seed data for test environment:
#
# This ensures that your canonical CSV data is loaded before your tests run.
# -----------------------------------------------------------------------------
config.before(:suite) do
load Rails.root.join('db', 'seed', 'canonical.rb')
end
# -----------------------------------------------------------------------------
# Backtrace Filtering:
#
# Filter out lines from Rails gems in backtraces for clarity.
# -----------------------------------------------------------------------------
config.filter_rails_from_backtrace!
# You can add additional filters here if needed:
# config.filter_gems_from_backtrace("gem name")
end