if Rails.env.local?
  # create some test data for development or test environment
end

ref. Rails.env.local? in Rails 7.1 | Saeloun Blog

便利。