Skip to content

Instantly share code, notes, and snippets.

@giljr
Created October 30, 2025 16:31
Show Gist options
  • Save giljr/6ce34004b1ea6155f06aa1b45b6da163 to your computer and use it in GitHub Desktop.
Save giljr/6ce34004b1ea6155f06aa1b45b6da163 to your computer and use it in GitHub Desktop.
Rspec cmds
Line Meaning
require 'spec_helper' Loads the basic RSpec configuration.
ENV['RAILS_ENV'] Ensures Rails runs in the test environment.
require_relative '../config/environment' Loads the Rails application environment.
abort("The Rails environment is running in production mode!") if Rails.env.production? Prevents tests from running in production.
require 'rspec/rails' Integrates RSpec with Rails features (models, controllers, etc.).
Rails.root.glob('spec/support/**/*.rb').sort_by(&:to_s).each { Loads all helper/support files in spec/support.
begin ... rescue ... end Ensures migrations are up to date before running tests; aborts if pending migrations exist.
ActiveRecord::Migration.maintain_test_schema! Applies any pending migrations to the test database.
RSpec.configure do config - Opens the main RSpec configuration block.
config.fixture_paths = [Rails.root.join('spec/fixtures')] Sets the location for test fixtures (sample data).
config.use_transactional_fixtures = true Wraps each test in a database transaction for isolation.
config.filter_rails_from_backtrace! Hides Rails internal frames from test failure backtraces.
end Closes the RSpec.configure block.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment