Are Rails engines supposed to come with an environment.rb?
rails-engines, ruby-on-rails
Solution
Use the dummy app's `environment.rb` file.
To setup RSpec:
Add the below to your `spec_helper.rb` file.
ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../test/dummy/config/environment", __FILE__)
...
It's also helpful to add the engine root.
ENGINE_RAILS_ROOT = File.join(File.dirname(__FILE__), '../')
If you want access to the engine's routing helpers, add the below in the `RSpec.configure` block.
# This will include the routing helpers in the specs so that we can use
# <engine>_path, etc., to get to the routes.
config.include <RailsEngine>::Engine.routes.url_helpers
Hope that helps.
Problem
I recently created my first Rails engine. The only thing in `/config` is `routes.rb` - no `environment.rb` or `application.rb` or anything like that. When I installed the `rspec-rails` gem and tried to run my specs, I got an error saying it couldn't find `environment.rb`, which is not surprising, since `environment.rb` doesn't exist. The confusing thing to me is that the evidence I have tells me one of two things must be the case: 1) Rails engines don't come with an `environment.rb` and you're expected to create `environment.rb`, `application.rb`, etc. by hand. This seems unlikely. 2) Rails engines do come with an `environment.rb`, but my engine happens to be missing it for whatever reason. This also seems unlikely. I am confused, though, by this answer that refers to `environment.rb` in an engine: Testing Rails 3.1 mountable engine with Rspec So my question is: Are Rails engines supposed to come with an `environment.rb`, and if not, how are you supposed to create one if you want/need one?