There once was a project that made extensive use of Pivotal's "Unbuilt Rails Dependency" pseudo-Gem architectural feature. After realising that that was far more limited in its applicable use cases than hoped, efforts were made to claw those back into namespaced classes within the main Rails app.
This was generally successful for a while. The use-case actions/service layer and one of the two core entities, User
s, worked Just Fine. When work began on the Post
entity, however, increasing forward progress was abruptly halted by a weird error.
Given the files spec/entities/post_spec.rb
and app/entities/post.rb
as below, running bundle exec rspec spec/entities/post_spec.rb
gives the following output
Coverage report generated for RSpec to /Users/jeffdickey/src/rails/meldd/new_poc/coverage. 377 / 707 LOC (53.32%) covered.
Coverage = 53.32%. Sending report to https://codeclimate.com for branch post-entities... done.
/Users/jeffdickey/src/rails/meldd/new_poc/vendor/ruby/2.2.0/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:495:in `load_missing_constant': Unable to autoload constant Post, expected /Users/jeffdickey/src/rails/meldd/new_poc/app/entities/post.rb to define it (LoadError)
from /Users/jeffdickey/src/rails/meldd/new_poc/vendor/ruby/2.2.0/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:184:in `const_missing'
from /Users/jeffdickey/src/rails/meldd/new_poc/vendor/ruby/2.2.0/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:526:in `load_missing_constant'
from /Users/jeffdickey/src/rails/meldd/new_poc/vendor/ruby/2.2.0/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:184:in `const_missing'
from /Users/jeffdickey/src/rails/meldd/new_poc/spec/entities/post_spec.rb:5:in `<module:Entity>'
from /Users/jeffdickey/src/rails/meldd/new_poc/spec/entities/post_spec.rb:4:in `<top (required)>'
from /Users/jeffdickey/src/rails/meldd/new_poc/vendor/ruby/2.2.0/gems/rspec-core-3.2.2/lib/rspec/core/configuration.rb:1226:in `load'
from /Users/jeffdickey/src/rails/meldd/new_poc/vendor/ruby/2.2.0/gems/rspec-core-3.2.2/lib/rspec/core/configuration.rb:1226:in `block in load_spec_files'
from /Users/jeffdickey/src/rails/meldd/new_poc/vendor/ruby/2.2.0/gems/rspec-core-3.2.2/lib/rspec/core/configuration.rb:1224:in `each'
from /Users/jeffdickey/src/rails/meldd/new_poc/vendor/ruby/2.2.0/gems/rspec-core-3.2.2/lib/rspec/core/configuration.rb:1224:in `load_spec_files'
from /Users/jeffdickey/src/rails/meldd/new_poc/vendor/ruby/2.2.0/gems/rspec-core-3.2.2/lib/rspec/core/runner.rb:97:in `setup'
from /Users/jeffdickey/src/rails/meldd/new_poc/vendor/ruby/2.2.0/gems/rspec-core-3.2.2/lib/rspec/core/runner.rb:85:in `run'
from /Users/jeffdickey/src/rails/meldd/new_poc/vendor/ruby/2.2.0/gems/rspec-core-3.2.2/lib/rspec/core/runner.rb:70:in `run'
from /Users/jeffdickey/src/rails/meldd/new_poc/vendor/ruby/2.2.0/gems/rspec-core-3.2.2/lib/rspec/core/runner.rb:38:in `invoke'
from /Users/jeffdickey/src/rails/meldd/new_poc/vendor/ruby/2.2.0/gems/rspec-core-3.2.2/exe/rspec:4:in `<top (required)>'
from /Users/jeffdickey/src/rails/meldd/new_poc/vendor/ruby/2.2.0/bin/rspec:23:in `load'
from /Users/jeffdickey/src/rails/meldd/new_poc/vendor/ruby/2.2.0/bin/rspec:23:in `<main>'
Bear in mind that Post
is the second entity to be given this treatment. There is a corresponding Entity::User
entity that Works Just Fine, including running its top-level RSpec specs as bundle exec rspec spec/entities/user_spec.rb
.
As i describe in a comment below. Major thanks to @bradstewart
for his patient prodding that finally "[knocked] my mental rust loose".
The following was my response to @bradstewart on the Reddit post; included here for completeness, as I want to encourage this to be the main forum for discussion.
Actually, I tried that with identical results; it made no difference whether I had
or
I still got the same error.
As to "here or the Gist", I was going to let the responders decide; I can see arguments for either forum. Given your stated confusion, though, I'm going to ask that this be continued on the Gist for future participants. Thanks.
I'm still troubled by the
require
vsrequire_relative
bit, as it implies that Rails "knows" where it should go find the file, but when you specify the path-independent name usingrequire
, all hell breaks loose.