So, I figured out a few things and will answer my own question, now that I got it to work.
For simplicity, I will refer to the name of my gem as "my_gem" and "MyGem":
In the engine.rb file engine.rb I added:
require 'my_gem' require 'rails'
These are fixed errors like:
my_gem/lib/my_gem/engine.rb:2: uninitialized constant MyGem::Rails (NameError)
In spec_helper.rb I added top to top:
require 'bundler/setup' require 'my_gem'
This means that the Bundler is initialized immediately, and not through the application. That way I can download MyGem here and it will be connected to the application initialization sequence. This fixes NameError exceptions for engine model classes.
This leaves the question of what to use Gemfile . The trouble is that my application has its own gemfile, while gem / engine needs its separate dependencies in its own Gemfile .
I could not find an API for the Bundler to pass two Gemfile , in fact the Bundler seems to be built around the assumption of one authoritative Gemfile . Therefore, I create one in spec_helper . I take the gemfile of the application and add gemspec , which points to the gem dependency in the GemSpec format. (By the way, in the book of Jose Valim there is no clue about gemspec ).
I do not know if there is a better way than concatenating files while running the test. If you know one, answer.
Useful resources were:
Wolfram arnold
source share