-
-
Notifications
You must be signed in to change notification settings - Fork 1
HOWTO dev Guard_Zeus_Spring
Guard allows local "Continuous Integration", checking for file changes and re-running any related specs by matching filenames through regular expressions. When compared to Autotest, it's similar but extremely more powerful.
The Guardfile
defines which directories and files have to be watched for modifications. It rarely needs to be edited, but it can be customized to run any kind of automated tests, including RSpec, Cucumber, Rubocop or any other tool available through a series of plugins.
Check if your project has already a Guardfile
or not. If missing, a default one can be easily created and customized by copying one from the examples linked below.
Having the test suite run almost instantly by skipping the reloading of the whole environment is adamant for a good developer experience.
Zeus, like Spring, is a Rails pre-loader, needed for quick re-runs of any test or rake task when using Rails <= 5.
When working with Rails 5.1+, Spring seems to be the more stable and viable solution: it works similarly to Zeus and comes prepackaged and pre-configured with any new Rails project.
For this reason, in all current projects the bespoke configurations for the Guardfile
are more focused on Spring than on Zeus.
A preloader typically runs in a dedicated process and needs an internal server to be started (with a command like start
or server
).
Assuming the preloader is running, open a console on the project root and simply type:
$> guard
Guard will remain active and watching for all the files enlisted by the configuration inside the Guardfile
.
Hitting ENTER on the Guard console (which is basically a pry
console minus the binding context) will re-launch all the test suite.
When you need to run a specific spec file (if you don't want or aren't in need to edit it), you can type in the Guard console:
> c path/to/file_name
To display a list of available commands, type help
on the Guard prompt.
Type reset
to reset current Guard status and clear the list of failing specs.
Type exit
to quit Guard.
GogglesDB has slightly different paths for the matching Regexp due to its being a mounted, namespaced (isolated) Engine: this implies an additional layer of depth in each pathname given its module name, plus the spec/dummy
path for testing the mounted engine itself.
Assuming your project bundle is complete and installed, using Spring means that nothing else needs to be installed locally.
Spring is launched automatically by Guard, so nothing needs to be typed beside the guard
command itself.
The typical Guardfile is configured to only run rspec
commands using Spring (not Zeus; see the example Guardfile
s, linked above).
Like Zeus, Spring supports a stand-alone server, which can be run in a dedicated console with a simple:
$> spring server
Launching any command like rails
, rake
or rspec
will invoke Spring automatically -- assuming all the commands in your project bin
folder have already been stubbed for usage with Spring during project setup.
In any other case, if Spring has been installed afterwards, you can force a bin-stub of all the current commands under PROJECT_ROOT/bin
with:
$> spring binstub --all
A command that has been binstub
-ed for Spring will search for a running Spring server instance.
It'll use an existing one when found, or it'll spawn a new one when not. So, as said above, running spring server
is not actually necessary, but leaving one running in the background may save some seconds in between reruns.
(Rails < 5.1)
Zeus is a good Rails preloader for working with older branches of the project or any other pre- Rails 5 application (typical case: Rails 3 or 4; for smaller projects, it works well even with most of the Rails 5.1 features enabled).
Zeus must be installed locally (not inside the Gemfile or the gem specs) with:
$> gem install zeus
Open a console and start Zeus in the Project root with:
$> zeus start
Zeus will keep running in the console as long as the console is kept alive or CTRL-C
is pressed. (Whereas the Spring server runs mostly in background and needs an explicit stop
command.)
With Zeus running on another console, you can then run Guard on your main console simply by executing guard
in the project root.