pat / combustion

Simple, elegant testing for Rails Engines
MIT License
703 stars 51 forks source link

NameError: uninitialized constant Rails #137

Closed krisleech closed 3 days ago

krisleech commented 5 months ago

rails 7.0.8 rspec 3.12.2 combustion 1.4.0

In rails_helper.rb:

require 'spec_helper'
ENV['RAILS_ENV'] ||= 'test'

require 'bundler'
Bundler.require :default, :development
Combustion.initialize! :all

require 'rspec/rails'

when I run the specs I get:

Failure/Error: class Engine < ::Rails::Engine

NameError:
  uninitialized constant Rails

I feel like I might be missing something obvious. I removed the line which used to load the environment from the dummy app and ran combust so I get the internal directory. Any help/pointers greatly appreciated.

pat commented 5 months ago

Hi Kris - do you have Rails listed in your dependencies, and is it listed before Combustion?

The Bundler.require :default, :development line should load all dependencies, but the order does matter. You may want a `require "rails/engine" within your engine file, just to make that dependency resolution clear.

pboling commented 2 months ago

I don't really understand the load order issues, but through brute force trial and error I was able to get it to work here: https://github.com/pboling/sanitize_email/commit/a9c1d9a11732b57e1b898e74516bbff36724ff97 for my sanitize_email gem. It might be helpful to you @krisleech

pat commented 3 days ago

Hey folks - I'm going to close this issue as it's been a few months. Certainly very happy to re-open if the problem crops up again (or others are finding it troublesome)