Fix load error when using Spring w/ custom config#246
Merged
bkeepers merged 1 commit intobkeepers:masterfrom Mar 11, 2016
Merged
Fix load error when using Spring w/ custom config#246bkeepers merged 1 commit intobkeepers:masterfrom
bkeepers merged 1 commit intobkeepers:masterfrom
Conversation
I'm currently working a project that is a [Rails engine](http://guides.rubyonrails.org/engines.html) When I add `dotenv-rails` to my `Gemfile`, and try to run a command, say: `bundle exec rspec spec`, this error occurs: ``` {gem-path}/spring-1.6.4/lib/spring/configuration.rb:31:in `application_root_path': Spring was unable to find your config/application.rb file. Your project root was detected at {project-root}, so spring looked for {project-root}/config/application.rb but it doesn't exist. You can configure the root of your application by setting Spring.application_root in config/spring.rb. (Spring::MissingApplication) from {gem-path}/spring-1.6.4/lib/spring/watcher.rb:24:in `watcher` ``` The error is saying that Spring can't find my `application_root`. This is odd, because [Spring allows for custom configuration](https://github.com/rails/spring#configuration), such as specifying where to find the root directory of your Rails application. This is especially helpful when working with a Rails Engine, and the root of the application lives [within the dummy app](https://github.com/rails/spring#configuration). In my project, Spring's `application_root` is configured via a `./config.spring.rb` file. [In `lib/dotenv/rails`](https://github.com/bkeepers/dotenv/blob/8fa4c4d8051f834f3d75eaa48cb1adb6994300c6/lib/dotenv/rails.rb#L7) Spring's `watcher` file was being included, but that watcher file doesn't trigger the loading of custom Spring configurations. Those includes take place in Spring's [`commands`](https://github.com/rails/spring/blob/2f88ab31297b79b3b5cf0059c2beb944052277f7/lib/spring/commands.rb) file. Specifically: - [Loading of `.spring.rb` files](https://github.com/rails/spring/blob/2f88ab31297b79b3b5cf0059c2beb944052277f7/lib/spring/commands.rb#L26-L29) - [Loading of `./config.spring.rb` files](https://github.com/rails/spring/blob/2f88ab31297b79b3b5cf0059c2beb944052277f7/lib/spring/commands.rb#L48-L49) Changed `lib/dotenv/rails` to instead include `spring/commands` (which in itself includes the `watcher` file). This allows for Spring to preload any configurations before `dotenv-rails` uses the `Spring.watch` command.
bkeepers
added a commit
that referenced
this pull request
Mar 11, 2016
Fix load error when using Spring w/ custom config
Owner
|
Thanks! |
Contributor
Author
|
@bkeepers welcome! Thanks for this project! |
Contributor
Author
|
Hey @bkeepers - would you be willing to push a new version of this gem now that this has been merged? |
Owner
|
Yup, 2.1.1 is now released! |
Contributor
Author
|
Thanks, @bkeepers !! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
I'm currently working a project that is a Rails engine
When I add
dotenv-railsto myGemfile, and try to run a command, say:bundle exec rspec spec, this error occurs:The error is saying that Spring can't find my
application_root. This is odd, because Spring allows for custom configuration, such as specifying where to find the root directory of your Rails application.This is especially helpful when working with a Rails Engine, and the root of the application lives within the dummy app.
In my project, Spring's
application_rootis configured via a./config.spring.rbfile.In
lib/dotenv/railsSpring'swatcherfile was being included, but that watcher file doesn't trigger the loading of custom Spring configurations.Those includes take place in Spring's
commandsfile.Specifically:
.spring.rbfiles./config.spring.rbfilesChanged
lib/dotenv/railsto instead includespring/commands(which in itself includes thewatcherfile). This allows for Spring to preload any configurations beforedotenv-railsuses theSpring.watchcommand.