Last active
March 27, 2019 20:29
-
-
Save jonathanroehm/054598fef77543d2f8e8a492b579574d to your computer and use it in GitHub Desktop.
How to add `spring` to your rails plugin / engine for use with RSpec and beyond.
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
# In `your_engine/Gemfile` add the pertinent spring gems: | |
# Note, do not add spring gems as `spec.add_development_dependency`'s in your gemspec. | |
source 'https://rubygems.org' | |
git_source(:github) { |repo| "https://github.com/#{repo}.git" } | |
gemspec | |
group :development do | |
gem 'spring' | |
gem 'spring-watcher-listen' | |
end | |
# If you're using rspec: | |
group :test do | |
gem 'spring-commands-rspec' | |
end |
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
# Add `spring.rb` to your engine's config folder: | |
# `your_engine/config/spring.rb` | |
# | |
# when generating a plugin via `rails plugin new your_engine` | |
# (without customizing the dummy_app path) | |
# a dummy rails app is created. | |
# | |
# If you're using RSpec, you'll path will look like: './spec/dummy' | |
Spring.application_root = './test/dummy' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Using spring binstubs in the terminal
Remember to re-
bundle
your gem from the gem's root directory once you've made these changes. The rootGemfile
will automatically be applied to the dummy app.When using RSpec, you can spring your tests via:
Or, in entirety:
How to generate your plugin so it's ready for RSpec
You can also utilize RSpec's
spec/
folder for placement of your dummy app by adding the following flags to your generation:--skip-test
--skip-system-test
--dummy-path=spec/dummy
Example:
Then, you simply add
rspec-rails
as a development dependency, re-bundle
, then run the RSpec installation generator:Good to go!