spring 0.0.8 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.travis.yml +3 -0
- data/CHANGELOG.md +113 -0
- data/Gemfile +1 -3
- data/README.md +129 -187
- data/bin/spring +27 -0
- data/lib/spring/application.rb +121 -20
- data/lib/spring/application_manager.rb +21 -13
- data/lib/spring/client/binstub.rb +45 -41
- data/lib/spring/client/help.rb +4 -1
- data/lib/spring/client/rails.rb +8 -3
- data/lib/spring/client/run.rb +33 -10
- data/lib/spring/client/status.rb +2 -2
- data/lib/spring/client.rb +3 -3
- data/lib/spring/commands/rails.rb +60 -0
- data/lib/spring/commands/rake.rb +34 -0
- data/lib/spring/commands.rb +12 -195
- data/lib/spring/configuration.rb +6 -2
- data/lib/spring/env.rb +27 -18
- data/lib/spring/errors.rb +1 -1
- data/lib/spring/json.rb +626 -0
- data/lib/spring/server.rb +60 -29
- data/lib/spring/version.rb +1 -1
- data/lib/spring/watcher/abstract.rb +11 -7
- data/lib/spring/watcher/listen.rb +8 -10
- data/lib/spring/watcher/polling.rb +1 -1
- data/lib/spring/watcher.rb +17 -11
- data/spring.gemspec +1 -0
- data/test/acceptance/app_test.rb +270 -73
- data/test/apps/.gitignore +3 -0
- data/test/unit/client/help_test.rb +2 -0
- data/test/unit/commands_test.rb +8 -49
- data/test/unit/watcher_test.rb +22 -2
- metadata +18 -151
- data/lib/spring/client/start.rb +0 -17
- data/test/apps/rails-3-2/.gitignore +0 -18
- data/test/apps/rails-3-2/Gemfile +0 -9
- data/test/apps/rails-3-2/README.rdoc +0 -261
- data/test/apps/rails-3-2/Rakefile +0 -7
- data/test/apps/rails-3-2/app/assets/images/rails.png +0 -0
- data/test/apps/rails-3-2/app/assets/javascripts/application.js +0 -15
- data/test/apps/rails-3-2/app/assets/javascripts/posts.js.coffee +0 -3
- data/test/apps/rails-3-2/app/assets/stylesheets/application.css +0 -13
- data/test/apps/rails-3-2/app/assets/stylesheets/posts.css.scss +0 -3
- data/test/apps/rails-3-2/app/assets/stylesheets/scaffolds.css.scss +0 -69
- data/test/apps/rails-3-2/app/controllers/application_controller.rb +0 -3
- data/test/apps/rails-3-2/app/controllers/posts_controller.rb +0 -83
- data/test/apps/rails-3-2/app/helpers/application_helper.rb +0 -2
- data/test/apps/rails-3-2/app/helpers/posts_helper.rb +0 -2
- data/test/apps/rails-3-2/app/mailers/.gitkeep +0 -0
- data/test/apps/rails-3-2/app/models/.gitkeep +0 -0
- data/test/apps/rails-3-2/app/models/post.rb +0 -3
- data/test/apps/rails-3-2/app/views/layouts/application.html.erb +0 -14
- data/test/apps/rails-3-2/app/views/posts/_form.html.erb +0 -21
- data/test/apps/rails-3-2/app/views/posts/edit.html.erb +0 -6
- data/test/apps/rails-3-2/app/views/posts/index.html.erb +0 -23
- data/test/apps/rails-3-2/app/views/posts/new.html.erb +0 -5
- data/test/apps/rails-3-2/app/views/posts/show.html.erb +0 -10
- data/test/apps/rails-3-2/config/application.rb +0 -62
- data/test/apps/rails-3-2/config/boot.rb +0 -6
- data/test/apps/rails-3-2/config/database.yml +0 -25
- data/test/apps/rails-3-2/config/environment.rb +0 -5
- data/test/apps/rails-3-2/config/environments/development.rb +0 -37
- data/test/apps/rails-3-2/config/environments/production.rb +0 -67
- data/test/apps/rails-3-2/config/environments/test.rb +0 -37
- data/test/apps/rails-3-2/config/initializers/backtrace_silencers.rb +0 -7
- data/test/apps/rails-3-2/config/initializers/inflections.rb +0 -15
- data/test/apps/rails-3-2/config/initializers/mime_types.rb +0 -5
- data/test/apps/rails-3-2/config/initializers/secret_token.rb +0 -7
- data/test/apps/rails-3-2/config/initializers/session_store.rb +0 -8
- data/test/apps/rails-3-2/config/initializers/wrap_parameters.rb +0 -14
- data/test/apps/rails-3-2/config/locales/en.yml +0 -5
- data/test/apps/rails-3-2/config/routes.rb +0 -60
- data/test/apps/rails-3-2/config/spring.rb +0 -7
- data/test/apps/rails-3-2/config.ru +0 -4
- data/test/apps/rails-3-2/db/migrate/20121109171227_create_posts.rb +0 -9
- data/test/apps/rails-3-2/db/schema.rb +0 -22
- data/test/apps/rails-3-2/db/seeds.rb +0 -7
- data/test/apps/rails-3-2/lib/assets/.gitkeep +0 -0
- data/test/apps/rails-3-2/lib/tasks/.gitkeep +0 -0
- data/test/apps/rails-3-2/log/.gitkeep +0 -0
- data/test/apps/rails-3-2/public/404.html +0 -26
- data/test/apps/rails-3-2/public/422.html +0 -26
- data/test/apps/rails-3-2/public/500.html +0 -25
- data/test/apps/rails-3-2/public/favicon.ico +0 -0
- data/test/apps/rails-3-2/public/index.html +0 -241
- data/test/apps/rails-3-2/public/robots.txt +0 -5
- data/test/apps/rails-3-2/script/rails +0 -6
- data/test/apps/rails-3-2/test/fixtures/.gitkeep +0 -0
- data/test/apps/rails-3-2/test/fixtures/posts.yml +0 -7
- data/test/apps/rails-3-2/test/functional/.gitkeep +0 -0
- data/test/apps/rails-3-2/test/functional/posts_controller_test.rb +0 -49
- data/test/apps/rails-3-2/test/integration/.gitkeep +0 -0
- data/test/apps/rails-3-2/test/performance/browsing_test.rb +0 -12
- data/test/apps/rails-3-2/test/test_helper.rb +0 -13
- data/test/apps/rails-3-2/test/unit/.gitkeep +0 -0
- data/test/apps/rails-3-2/test/unit/helpers/posts_helper_test.rb +0 -4
- data/test/apps/rails-3-2/test/unit/post_test.rb +0 -7
- data/test/apps/rails-3-2/vendor/assets/javascripts/.gitkeep +0 -0
- data/test/apps/rails-3-2/vendor/assets/stylesheets/.gitkeep +0 -0
- data/test/apps/rails-3-2/vendor/plugins/.gitkeep +0 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: ab103d29ee132ac8637c7ddca8d5c41fc567c31e
|
|
4
|
+
data.tar.gz: 88e600c6e1d59b4150625769f20f6d543958087c
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 7b4d762562b8d4c1832bcec43819b6bcc6d9168473095fac089a743c0c421d4450f77e7c0a3cf31902256ed42a3d0fa57e7767cd4a0cf9d0bd55dc24c758f460
|
|
7
|
+
data.tar.gz: 9c929b2636980dc30486f475caeacb1f3de296420c22e9f0a52c67ce732a8953e28f1b090258a18456d210ce217610e8e4df8ffeb7a1a8ebd0e2b546554235ec
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,116 @@
|
|
|
1
|
+
## 1.0.0
|
|
2
|
+
|
|
3
|
+
* Enterprise ready secret sauce added
|
|
4
|
+
|
|
5
|
+
## 0.9.2
|
|
6
|
+
|
|
7
|
+
* Bugfix: environment variables set by bundler (`BUNDLE_GEMFILE`,
|
|
8
|
+
`RUBYOPT`, etc...) were being removed from the environment.
|
|
9
|
+
* Ensure we only run the code reloader when files have actually changed.
|
|
10
|
+
This issue became more prominent with Rails 4, since Rails 4 will now
|
|
11
|
+
reload routes whenever the code is reloaded (see
|
|
12
|
+
https://github.com/rails/rails/commit/b9b06daa915fdc4d11e8cfe11a7175e5cd8f104f).
|
|
13
|
+
* Allow spring to be used in a descendant directory of the application
|
|
14
|
+
root
|
|
15
|
+
* Use the system tmpdir for our temporary files. Previously we used
|
|
16
|
+
`APP_ROOT/tmp/spring`, which caused problems on filesystems which did
|
|
17
|
+
not support sockets, and also caused problems if `APP_ROOT` was
|
|
18
|
+
sufficiently deep in the filesystem to exhaust the operating system's
|
|
19
|
+
socket name limit. Hence we had a `SPRING_TMP_PATH` environment
|
|
20
|
+
variable for configuration. We now use `/tmp/spring/[md5(APP_ROOT)]`
|
|
21
|
+
for the socket and `/tmp/spring/[md5(APP_ROOT)].pid` for the pid file.
|
|
22
|
+
Thanks @Kriechi for the suggestion. Setting `SPRING_TMP_PATH` no longer
|
|
23
|
+
has any effect.
|
|
24
|
+
|
|
25
|
+
## 0.9.1
|
|
26
|
+
|
|
27
|
+
* Environment variables which were created during application startup are no
|
|
28
|
+
longer overwritten.
|
|
29
|
+
* Support for generating multiple binstubs at once. Use --all to
|
|
30
|
+
generate all, otherwise you can pass multiple command names to the
|
|
31
|
+
binstub command.
|
|
32
|
+
* The `testunit` command has been extracted to the
|
|
33
|
+
`spring-commands-testunit` gem, because it's not necessary in Rails 4,
|
|
34
|
+
where you can just run `rake test path/to/test`.
|
|
35
|
+
* The `~/.spring.rb` config file is loaded before bundler, so it's a good
|
|
36
|
+
place to require extra commands which you want to use in all projects,
|
|
37
|
+
without having to add those commands to the Gemfile of each individual
|
|
38
|
+
project.
|
|
39
|
+
* Any gems in the bundle with names which start with "spring-commands-"
|
|
40
|
+
are now autoloaded. This makes it less faffy to add additional
|
|
41
|
+
commands.
|
|
42
|
+
|
|
43
|
+
## 0.9.0
|
|
44
|
+
|
|
45
|
+
* Display spring version in the help message
|
|
46
|
+
* Remove workaround for Rubygems performance issue. This issue is solved
|
|
47
|
+
with Rubygems 2.1, so we no longer need to generate a "spring" binstub
|
|
48
|
+
file. We warn users if they are not taking advantage of the Rubygems
|
|
49
|
+
perf fix (e.g. if they are not on 2.1, or haven't run `gem pristine
|
|
50
|
+
--all`). To upgrade, delete your `bin/spring` and re-run `spring
|
|
51
|
+
binstub` for each of your binstubs.
|
|
52
|
+
* Binstubs now fall back to non-spring execution of a command if the
|
|
53
|
+
spring gem is not present. This might be useful for production
|
|
54
|
+
environments.
|
|
55
|
+
* The ENV will be replaced on each run to match the ENV which exists
|
|
56
|
+
when the spring command is actually run (rather than the ENV which
|
|
57
|
+
exists when spring first starts).
|
|
58
|
+
* Specifying the rails env after the rake command (e.g. `rake
|
|
59
|
+
RAILS_ENV=test db:migrate`) now works as expected.
|
|
60
|
+
* Provide an explicit way to set the environment to use when running
|
|
61
|
+
`rake` on its own.
|
|
62
|
+
* The `rspec` and `cucumber` commands are no longer shipped by default.
|
|
63
|
+
They've been moved to the `spring-commands-rspec` and
|
|
64
|
+
`spring-commands-cucumber` gems.
|
|
65
|
+
|
|
66
|
+
## 0.0.11
|
|
67
|
+
|
|
68
|
+
* Added the `rails destroy` command.
|
|
69
|
+
* Global config file in `~/.spring.rb`
|
|
70
|
+
* Added logging for debugging. Specify a log file with the
|
|
71
|
+
`SPRING_LOG` environment variable.
|
|
72
|
+
* Fix hang on "Run `bundle install` to install missing gems"
|
|
73
|
+
* Added hack to make backtraces generated when running a command
|
|
74
|
+
quieter (by stripping out all of the lines relating to spring)
|
|
75
|
+
* Rails 4 is officially supported
|
|
76
|
+
|
|
77
|
+
## 0.0.10
|
|
78
|
+
|
|
79
|
+
* Added `Spring.watch_method=` configuration option to switch between
|
|
80
|
+
polling and the `listen` gem. Previously, we used the `listen` gem if
|
|
81
|
+
it was available, but this makes the option explicit. Set
|
|
82
|
+
`Spring.watch_method = :listen` to use the listen gem.
|
|
83
|
+
* Fallback when Process.fork is not available. In such cases, the user
|
|
84
|
+
will not receive the speedup that Spring provides, but won't receive
|
|
85
|
+
an error either.
|
|
86
|
+
* Don't preload `test_helper` or `spec_helper` by default. This was
|
|
87
|
+
causing people subtle problems (for example see #113) and is perhaps
|
|
88
|
+
surprising behaviour. It may be desirable but it depends on the
|
|
89
|
+
application, therefore we suggest it to people in the README but no
|
|
90
|
+
longer do it by default.
|
|
91
|
+
* Don't stay connected to database in the application processes. There's
|
|
92
|
+
no need to keep a connection open.
|
|
93
|
+
* Avoid using the database in the application processes. Previously,
|
|
94
|
+
reloading the autoloaded constants would inadvertantly cause a
|
|
95
|
+
connection to the database, which would then prevent tasks like
|
|
96
|
+
db:create from running (because at that point the database doesn't
|
|
97
|
+
exist)
|
|
98
|
+
* Removed ability to specify list of files for a command to preload. We
|
|
99
|
+
weren't using this any more internally, and this is easy to do by
|
|
100
|
+
placing requires in suitable locations in the Rails boot process
|
|
101
|
+
(which is not explained in the README).
|
|
102
|
+
* Seed the random number generator on each run.
|
|
103
|
+
|
|
104
|
+
## 0.0.9
|
|
105
|
+
|
|
106
|
+
* Added `Spring::Commands::Rake.environment_matchers` for matching
|
|
107
|
+
rake tasks to specific environments.
|
|
108
|
+
* Kill the spring server when the `Gemfile` or `Gemfile.lock` is
|
|
109
|
+
changed. This forces a new server to boot up on the next run, which
|
|
110
|
+
ensures that you get the correct gems (or the correct error message from
|
|
111
|
+
bundler if you have forgotten to `bundle install`.)
|
|
112
|
+
* Fixed error when `Spring.watch` is used in `config/spring.rb`
|
|
113
|
+
|
|
1
114
|
## 0.0.8
|
|
2
115
|
|
|
3
116
|
* Renamed `spring test` to `spring testunit`.
|
data/Gemfile
CHANGED
data/README.md
CHANGED
|
@@ -2,72 +2,45 @@
|
|
|
2
2
|
|
|
3
3
|
[](https://travis-ci.org/jonleighton/spring)
|
|
4
4
|
|
|
5
|
-
Spring is a Rails application preloader. It
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
[commands](https://github.com/rails/commands).
|
|
9
|
-
|
|
10
|
-
I made it because we are having a discussion on the rails core team
|
|
11
|
-
about shipping something to solve this problem with rails. So this is my
|
|
12
|
-
proposal, as working code.
|
|
13
|
-
|
|
14
|
-
(At least I hope it's working code, but this is alpha software at the
|
|
15
|
-
moment. Please do try it and let me know if you hit problems.)
|
|
5
|
+
Spring is a Rails application preloader. It speeds up development by
|
|
6
|
+
keeping your application running in the background so you don't need to
|
|
7
|
+
boot it every time you run a test, rake task or migration.
|
|
16
8
|
|
|
17
9
|
## Features
|
|
18
10
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
Spring tries to be totally automatic.
|
|
24
|
-
It boots up in the background the first time you run a
|
|
25
|
-
command. Then it speeds up subsequent commands. If it detects that your
|
|
26
|
-
pre-loaded environment has changed (maybe `config/application.rb` has
|
|
27
|
-
been edited) then it will reload your environment in the background,
|
|
28
|
-
ready for the next command. When you close your terminal session, Spring
|
|
29
|
-
will automatically shut down. There's no "server" to manually start and
|
|
30
|
-
stop.
|
|
31
|
-
|
|
32
|
-
Spring operates via a command line interface. Other solutions (e.g.
|
|
33
|
-
commands) take the approach of using a special console to run commands
|
|
34
|
-
from. This means we will have to re-implement shell features such as
|
|
35
|
-
history, completion, etc. Whilst it's not impossible to re-implement
|
|
36
|
-
those features, it's unnecessary work and our re-implementation
|
|
37
|
-
won't be as feature complete as a real shell. Using a real shell also
|
|
38
|
-
prevents the user having to constantly jump between a terminal with a
|
|
39
|
-
real shell and a terminal running the rails "commands console".
|
|
11
|
+
* Totally automatic; no need to explicitly start and stop the background process
|
|
12
|
+
* Reloads your application code on each run
|
|
13
|
+
* Restarts your application when configs / initializers / gem
|
|
14
|
+
dependencies are changed
|
|
40
15
|
|
|
41
16
|
## Compatibility
|
|
42
17
|
|
|
43
|
-
Ruby versions
|
|
44
|
-
|
|
45
|
-
* MRI 1.9.3
|
|
46
|
-
* MRI 2.0.0
|
|
18
|
+
* Ruby versions: MRI 1.9.3, MRI 2.0.0
|
|
19
|
+
* Rails versions: 3.2, 4.0
|
|
47
20
|
|
|
48
|
-
|
|
21
|
+
Spring makes extensive use of `Process#fork`, so won't be able to
|
|
22
|
+
provide a speed up on platforms which don't support forking (Windows, JRuby).
|
|
49
23
|
|
|
50
|
-
|
|
24
|
+
## Walkthrough
|
|
51
25
|
|
|
52
|
-
|
|
53
|
-
any platform which doesn't support that (Windows, JRuby).
|
|
26
|
+
Either `gem install spring` or add it to your Gemfile:
|
|
54
27
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
28
|
+
``` ruby
|
|
29
|
+
group :development do
|
|
30
|
+
gem "spring"
|
|
31
|
+
end
|
|
32
|
+
```
|
|
60
33
|
|
|
61
|
-
|
|
34
|
+
Spring is designed to be used *without* bundle exec, so use `spring
|
|
35
|
+
[command]` rather than `bundle exec spring [command]`.
|
|
62
36
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
```
|
|
37
|
+
For this walkthrough I've generated a new Rails application, and run
|
|
38
|
+
`rails generate scaffold posts name:string`.
|
|
66
39
|
|
|
67
|
-
|
|
40
|
+
Let's run a test:
|
|
68
41
|
|
|
69
42
|
```
|
|
70
|
-
$ time spring
|
|
43
|
+
$ time spring rake test test/functional/posts_controller_test.rb
|
|
71
44
|
Run options:
|
|
72
45
|
|
|
73
46
|
# Running tests:
|
|
@@ -78,29 +51,26 @@ Finished tests in 0.127245s, 55.0121 tests/s, 78.5887 assertions/s.
|
|
|
78
51
|
|
|
79
52
|
7 tests, 10 assertions, 0 failures, 0 errors, 0 skips
|
|
80
53
|
|
|
81
|
-
real
|
|
82
|
-
user
|
|
83
|
-
sys
|
|
54
|
+
real 0m2.165s
|
|
55
|
+
user 0m0.281s
|
|
56
|
+
sys 0m0.066s
|
|
84
57
|
```
|
|
85
58
|
|
|
86
|
-
That
|
|
59
|
+
That wasn't particularly fast because it was the first run, so spring
|
|
60
|
+
had to boot the application. It's now running:
|
|
87
61
|
|
|
88
62
|
```
|
|
89
63
|
$ spring status
|
|
90
64
|
Spring is running:
|
|
91
65
|
|
|
92
|
-
26150 spring server |
|
|
93
|
-
26155 spring app |
|
|
66
|
+
26150 spring server | spring-demo-app | started 3 secs ago
|
|
67
|
+
26155 spring app | spring-demo-app | started 3 secs ago | test mode
|
|
94
68
|
```
|
|
95
69
|
|
|
96
|
-
|
|
97
|
-
application running in the test environment. When we close the terminal,
|
|
98
|
-
the processes will be killed automatically.
|
|
99
|
-
|
|
100
|
-
Running the test is faster next time:
|
|
70
|
+
The next run is faster:
|
|
101
71
|
|
|
102
72
|
```
|
|
103
|
-
$ time spring
|
|
73
|
+
$ time spring rake test test/functional/posts_controller_test.rb
|
|
104
74
|
Run options:
|
|
105
75
|
|
|
106
76
|
# Running tests:
|
|
@@ -111,77 +81,53 @@ Finished tests in 0.176896s, 39.5714 tests/s, 56.5305 assertions/s.
|
|
|
111
81
|
|
|
112
82
|
7 tests, 10 assertions, 0 failures, 0 errors, 0 skips
|
|
113
83
|
|
|
114
|
-
real
|
|
115
|
-
user
|
|
116
|
-
sys
|
|
84
|
+
real 0m0.610s
|
|
85
|
+
user 0m0.276s
|
|
86
|
+
sys 0m0.059s
|
|
117
87
|
```
|
|
118
88
|
|
|
119
|
-
|
|
120
|
-
tedious. It also suffers from a performance issue in Rubygems ([which I
|
|
121
|
-
am actively working on](https://github.com/rubygems/rubygems/pull/435))
|
|
122
|
-
which means the `spring` command takes a while to start up. The more
|
|
123
|
-
gems you have, the longer it takes.
|
|
89
|
+
Writing `spring` before every command gets a bit tedious. Spring binstubs solve this:
|
|
124
90
|
|
|
125
|
-
Spring binstubs solve both of these problems. If you will be running the
|
|
126
|
-
`testunit` command regularly, run:
|
|
127
|
-
|
|
128
|
-
```
|
|
129
|
-
$ spring binstub testunit
|
|
130
91
|
```
|
|
131
|
-
|
|
132
|
-
This generates a `bin/spring` and a `bin/testunit`, which allows you to run
|
|
133
|
-
`spring` and `spring testunit` in a way that doesn't trigger the Rubygems
|
|
134
|
-
performance bug:
|
|
135
|
-
|
|
92
|
+
$ spring binstub rake rails
|
|
136
93
|
```
|
|
137
|
-
$ time bin/testunit test/functional/posts_controller_test.rb
|
|
138
|
-
Run options:
|
|
139
|
-
|
|
140
|
-
# Running tests:
|
|
141
|
-
|
|
142
|
-
.......
|
|
143
94
|
|
|
144
|
-
|
|
95
|
+
This will generate `bin/rake` and `bin/rails`. They
|
|
96
|
+
replace any binstubs that you might already have in your `bin/`
|
|
97
|
+
directory. Check them in to source control.
|
|
145
98
|
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
user 0m0.077s
|
|
150
|
-
sys 0m0.059s
|
|
151
|
-
```
|
|
99
|
+
If you don't want to prefix every command you type with `bin/`, you
|
|
100
|
+
can [use direnv](https://github.com/zimbatm/direnv) to automatically add
|
|
101
|
+
`./bin` to your `PATH` when you `cd` into your application.
|
|
152
102
|
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
103
|
+
If we edit any of the application files, or test files, the changes will
|
|
104
|
+
be picked up on the next run without the background process having to
|
|
105
|
+
restart. This works in exactly the same way as the code reloading
|
|
106
|
+
which allows you to refresh your browser and instantly see changes during
|
|
107
|
+
development.
|
|
156
108
|
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
109
|
+
But if we edit any of the files which were used to start the application
|
|
110
|
+
(configs, initializers, your gemfile), the application needs to be fully
|
|
111
|
+
restarted. This happens automatically.
|
|
160
112
|
|
|
161
|
-
|
|
162
|
-
automatically. Let's "edit" `config/application.rb`:
|
|
113
|
+
Let's "edit" `config/application.rb`:
|
|
163
114
|
|
|
164
115
|
```
|
|
165
116
|
$ touch config/application.rb
|
|
166
117
|
$ spring status
|
|
167
118
|
Spring is running:
|
|
168
119
|
|
|
169
|
-
26150 spring server |
|
|
170
|
-
26556 spring app |
|
|
120
|
+
26150 spring server | spring-demo-app | started 36 secs ago
|
|
121
|
+
26556 spring app | spring-demo-app | started 1 sec ago | test mode
|
|
171
122
|
```
|
|
172
123
|
|
|
173
|
-
The application
|
|
174
|
-
|
|
175
|
-
All of this happened automatically. Next time we run a
|
|
176
|
-
command we'll be running against a fresh application. We can see that
|
|
177
|
-
the start time and PID of the app process has changed.
|
|
124
|
+
The application detected that `config/application.rb` changed and
|
|
125
|
+
automatically restarted itself.
|
|
178
126
|
|
|
179
|
-
If we run a command that uses a different environment, then
|
|
180
|
-
booted up
|
|
181
|
-
environment by default:
|
|
127
|
+
If we run a command that uses a different environment, then that
|
|
128
|
+
environment gets booted up:
|
|
182
129
|
|
|
183
130
|
```
|
|
184
|
-
$ spring binstub rake
|
|
185
131
|
$ bin/rake routes
|
|
186
132
|
posts GET /posts(.:format) posts#index
|
|
187
133
|
POST /posts(.:format) posts#create
|
|
@@ -190,24 +136,21 @@ edit_post GET /posts/:id/edit(.:format) posts#edit
|
|
|
190
136
|
post GET /posts/:id(.:format) posts#show
|
|
191
137
|
PUT /posts/:id(.:format) posts#update
|
|
192
138
|
DELETE /posts/:id(.:format) posts#destroy
|
|
193
|
-
```
|
|
194
|
-
|
|
195
|
-
We now have 3 processes: the server, and application in test mode and
|
|
196
|
-
the application in development mode.
|
|
197
139
|
|
|
198
|
-
|
|
199
|
-
$ bin/spring status
|
|
140
|
+
$ spring status
|
|
200
141
|
Spring is running:
|
|
201
142
|
|
|
202
|
-
26150 spring server |
|
|
203
|
-
26556 spring app |
|
|
204
|
-
26707 spring app |
|
|
143
|
+
26150 spring server | spring-demo-app | started 1 min ago
|
|
144
|
+
26556 spring app | spring-demo-app | started 42 secs ago | test mode
|
|
145
|
+
26707 spring app | spring-demo-app | started 2 secs ago | development mode
|
|
205
146
|
```
|
|
206
147
|
|
|
207
|
-
|
|
148
|
+
There's no need to "shut down" spring. This will happen automatically
|
|
149
|
+
when you close your terminal. However if you do want to do a manual shut
|
|
150
|
+
down, use the `stop` command:
|
|
208
151
|
|
|
209
152
|
```
|
|
210
|
-
$
|
|
153
|
+
$ spring stop
|
|
211
154
|
Spring stopped.
|
|
212
155
|
```
|
|
213
156
|
|
|
@@ -215,34 +158,34 @@ Spring stopped.
|
|
|
215
158
|
|
|
216
159
|
The following commands are shipped by default.
|
|
217
160
|
|
|
218
|
-
Custom commands can be specified in
|
|
219
|
-
[`lib/spring/commands
|
|
161
|
+
Custom commands can be specified in the Spring config file. See
|
|
162
|
+
[`lib/spring/commands/`](https://github.com/jonleighton/spring/blob/master/lib/spring/commands/)
|
|
220
163
|
for examples.
|
|
221
164
|
|
|
222
|
-
|
|
223
|
-
order to make it easy for people to try spring. However in the future
|
|
224
|
-
the code to use a specific test framework should not be contained in the
|
|
225
|
-
spring repository.
|
|
226
|
-
|
|
227
|
-
### `testunit`
|
|
228
|
-
|
|
229
|
-
Runs a test (e.g. Test::Unit, MiniTest::Unit, etc.) Preloads the `test_helper` file.
|
|
165
|
+
You can add the following gems to your Gemfile for additional commands:
|
|
230
166
|
|
|
231
|
-
|
|
232
|
-
|
|
167
|
+
* [spring-commands-rspec](https://github.com/jonleighton/spring-commands-rspec)
|
|
168
|
+
* [spring-commands-cucumber](https://github.com/jonleighton/spring-commands-cucumber)
|
|
169
|
+
* [spring-commands-testunit](https://github.com/jonleighton/spring-commands-testunit) - useful for
|
|
170
|
+
running `Test::Unit` tests on Rails 3, since only Rails 4 allows you
|
|
171
|
+
to use `rake test path/to/test` to run a particular test/directory.
|
|
233
172
|
|
|
234
|
-
### `
|
|
235
|
-
|
|
236
|
-
Runs an rspec spec, exactly the same as the `rspec` executable. Preloads
|
|
237
|
-
the `spec_helper` file.
|
|
238
|
-
|
|
239
|
-
### `cucumber`
|
|
173
|
+
### `rake`
|
|
240
174
|
|
|
241
|
-
Runs a
|
|
175
|
+
Runs a rake task. Rake tasks run in the `development` environment by
|
|
176
|
+
default. You can change this on the fly by using the `RAILS_ENV`
|
|
177
|
+
environment variable. The environment is also configurable with the
|
|
178
|
+
`Spring::Commands::Rake.environment_matchers` hash. This has sensible
|
|
179
|
+
defaults, but if you need to match a specific task to a specific
|
|
180
|
+
environment, you'd do it like this:
|
|
242
181
|
|
|
243
|
-
|
|
182
|
+
``` ruby
|
|
183
|
+
Spring::Commands::Rake.environment_matchers["perf_test"] = "test"
|
|
184
|
+
Spring::Commands::Rake.environment_matchers[/^perf/] = "test"
|
|
244
185
|
|
|
245
|
-
|
|
186
|
+
# To change the environment when you run `rake` with no arguments
|
|
187
|
+
Spring::Commands::Rake.environment_matchers[:default] = "development"
|
|
188
|
+
```
|
|
246
189
|
|
|
247
190
|
### `rails console`, `rails generate`, `rails runner`
|
|
248
191
|
|
|
@@ -253,39 +196,38 @@ speed-up).
|
|
|
253
196
|
|
|
254
197
|
## Configuration
|
|
255
198
|
|
|
256
|
-
|
|
199
|
+
Spring will read `~/.spring.rb` and `config/spring.rb` for custom
|
|
200
|
+
settings. Note that `~/.spring.rb` is loaded *before* bundler, but
|
|
201
|
+
`config/spring.rb` is loaded *after* bundler. So if you have any
|
|
202
|
+
`spring-commands-*` gems installed that you want to be available in all
|
|
203
|
+
projects without having to be added to the project's Gemfile, require
|
|
204
|
+
them in your `~/.spring.rb`.
|
|
205
|
+
|
|
206
|
+
### Application root
|
|
257
207
|
|
|
258
|
-
Spring must know how to find your
|
|
208
|
+
Spring must know how to find your Rails application. If you have a
|
|
259
209
|
normal app everything works out of the box. If you are working on a
|
|
260
210
|
project with a special setup (an engine for example), you must tell
|
|
261
211
|
Spring where your app is located:
|
|
262
212
|
|
|
263
|
-
**config/spring.rb**
|
|
264
|
-
|
|
265
213
|
```ruby
|
|
266
214
|
Spring.application_root = './test/dummy'
|
|
267
215
|
```
|
|
268
216
|
|
|
269
|
-
###
|
|
270
|
-
|
|
271
|
-
Every Spring command has the ability to preload a set of files. The
|
|
272
|
-
`test` command for example preloads `test_helper` (it also adds the
|
|
273
|
-
`test/` directory to your load path). If the
|
|
274
|
-
defaults don't work for your application you can configure the
|
|
275
|
-
preloads for every command:
|
|
276
|
-
|
|
277
|
-
```ruby
|
|
278
|
-
# if your test helper is called "helper"
|
|
279
|
-
Commands::Command::TestUnit.preloads = %w(helper)
|
|
217
|
+
### Running code before forking
|
|
280
218
|
|
|
281
|
-
|
|
282
|
-
|
|
219
|
+
There is no `Spring.before_fork` callback. To run something before the
|
|
220
|
+
fork, you can place it in `~/.spring.rb` or `config/spring.rb` or in any of the files
|
|
221
|
+
which get run when your application initializers, such as
|
|
222
|
+
`config/application.rb`, `config/environments/*.rb` or
|
|
223
|
+
`config/initializers/*.rb`.
|
|
283
224
|
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
225
|
+
For example, if loading your test helper is slow, you might like to
|
|
226
|
+
preload it to speed up your test runs. To do this you could put a
|
|
227
|
+
`require Rails.root.join("test/helper")` in
|
|
228
|
+
`config/environments/test.rb`.
|
|
287
229
|
|
|
288
|
-
### after
|
|
230
|
+
### Running code after forking
|
|
289
231
|
|
|
290
232
|
You might want to run code after Spring forked off the process but
|
|
291
233
|
before the actual command is run. You might want to use an
|
|
@@ -301,35 +243,35 @@ end
|
|
|
301
243
|
If you want to register multiple callbacks you can simply call
|
|
302
244
|
`Spring.after_fork` multiple times with different blocks.
|
|
303
245
|
|
|
304
|
-
### tmp directory
|
|
305
|
-
|
|
306
|
-
Spring needs a tmp directory. This will default to `Rails.root.join('tmp', 'spring')`.
|
|
307
|
-
You can set your own configuration directory by setting the `SPRING_TMP_PATH` environment variable.
|
|
308
|
-
|
|
309
246
|
### Watching files and directories
|
|
310
247
|
|
|
311
|
-
|
|
312
|
-
boots.
|
|
313
|
-
|
|
248
|
+
Spring will automatically detect file changes to any file loaded when the server
|
|
249
|
+
boots. Changes will cause the affected environments to be restarted.
|
|
250
|
+
|
|
251
|
+
If there are additional files or directories which should trigger an
|
|
252
|
+
application restart, you can specify them with `Spring.watch`:
|
|
314
253
|
|
|
315
254
|
```ruby
|
|
316
|
-
Spring.watch "
|
|
255
|
+
Spring.watch "spec/factories"
|
|
317
256
|
```
|
|
318
257
|
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
By default Spring will check the filesystem for changes once every 0.2 seconds. This
|
|
258
|
+
By default Spring polls the filesystem for changes once every 0.2 seconds. This
|
|
322
259
|
method requires zero configuration, but if you find that it's using too
|
|
323
|
-
much CPU, then you can turn on event-based file system listening
|
|
324
|
-
adding the following to to your `Gemfile`:
|
|
260
|
+
much CPU, then you can turn on event-based file system listening:
|
|
325
261
|
|
|
326
262
|
```ruby
|
|
327
|
-
|
|
328
|
-
gem 'listen'
|
|
329
|
-
gem 'rb-inotify', :require => false # linux
|
|
330
|
-
gem 'rb-fsevent', :require => false # mac os x
|
|
331
|
-
gem 'rb-kqueue', :require => false # bsd
|
|
332
|
-
end
|
|
263
|
+
Spring.watch_method = :listen
|
|
333
264
|
```
|
|
334
265
|
|
|
335
|
-
|
|
266
|
+
You may need to add the [`listen` gem](https://github.com/guard/listen) to your `Gemfile`.
|
|
267
|
+
|
|
268
|
+
## Troubleshooting
|
|
269
|
+
|
|
270
|
+
If you want to get more information about what spring is doing, you can
|
|
271
|
+
specify a log file with the `SPRING_LOG` environment variable:
|
|
272
|
+
|
|
273
|
+
```
|
|
274
|
+
spring stop # if spring is already running
|
|
275
|
+
export SPRING_LOG=/tmp/spring.log
|
|
276
|
+
spring rake -T
|
|
277
|
+
```
|
data/bin/spring
CHANGED
|
@@ -1,4 +1,31 @@
|
|
|
1
1
|
#!/usr/bin/env ruby
|
|
2
2
|
|
|
3
|
+
if defined?(Gem)
|
|
4
|
+
if Gem::Version.new(Gem::VERSION) < Gem::Version.new("2.1.0")
|
|
5
|
+
warn "Warning: You're using Rubygems #{Gem::VERSION} with Spring. " \
|
|
6
|
+
"Upgrade to at least Rubygems 2.1.0 and run `gem pristine --all` for better " \
|
|
7
|
+
"startup performance."
|
|
8
|
+
else
|
|
9
|
+
stubs = Gem::Specification.stubs.grep(Gem::StubSpecification)
|
|
10
|
+
|
|
11
|
+
# stubbed? method added in https://github.com/rubygems/rubygems/pull/694
|
|
12
|
+
if Gem::Specification.stubs.first.respond_to?(:stubbed?)
|
|
13
|
+
unstubbed = stubs.reject(&:stubbed?)
|
|
14
|
+
else
|
|
15
|
+
unstubbed = stubs.reject { |s| s.send(:data).is_a?(Gem::StubSpecification::StubLine) }
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
# `gem pristine --all` ignores default gems. it doesn't really matter,
|
|
19
|
+
# as there are probably not many of them on the system.
|
|
20
|
+
unstubbed.reject!(&:default_gem?)
|
|
21
|
+
|
|
22
|
+
if unstubbed.any?
|
|
23
|
+
warn "Warning: Running `gem pristine --all` to regenerate your installed gemspecs " \
|
|
24
|
+
"will improve the startup performance of Spring."
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
$LOAD_PATH.unshift File.expand_path("../../lib", __FILE__)
|
|
3
30
|
require 'spring/client'
|
|
4
31
|
Spring::Client.run(ARGV)
|