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.
Files changed (101) hide show
  1. checksums.yaml +7 -0
  2. data/.travis.yml +3 -0
  3. data/CHANGELOG.md +113 -0
  4. data/Gemfile +1 -3
  5. data/README.md +129 -187
  6. data/bin/spring +27 -0
  7. data/lib/spring/application.rb +121 -20
  8. data/lib/spring/application_manager.rb +21 -13
  9. data/lib/spring/client/binstub.rb +45 -41
  10. data/lib/spring/client/help.rb +4 -1
  11. data/lib/spring/client/rails.rb +8 -3
  12. data/lib/spring/client/run.rb +33 -10
  13. data/lib/spring/client/status.rb +2 -2
  14. data/lib/spring/client.rb +3 -3
  15. data/lib/spring/commands/rails.rb +60 -0
  16. data/lib/spring/commands/rake.rb +34 -0
  17. data/lib/spring/commands.rb +12 -195
  18. data/lib/spring/configuration.rb +6 -2
  19. data/lib/spring/env.rb +27 -18
  20. data/lib/spring/errors.rb +1 -1
  21. data/lib/spring/json.rb +626 -0
  22. data/lib/spring/server.rb +60 -29
  23. data/lib/spring/version.rb +1 -1
  24. data/lib/spring/watcher/abstract.rb +11 -7
  25. data/lib/spring/watcher/listen.rb +8 -10
  26. data/lib/spring/watcher/polling.rb +1 -1
  27. data/lib/spring/watcher.rb +17 -11
  28. data/spring.gemspec +1 -0
  29. data/test/acceptance/app_test.rb +270 -73
  30. data/test/apps/.gitignore +3 -0
  31. data/test/unit/client/help_test.rb +2 -0
  32. data/test/unit/commands_test.rb +8 -49
  33. data/test/unit/watcher_test.rb +22 -2
  34. metadata +18 -151
  35. data/lib/spring/client/start.rb +0 -17
  36. data/test/apps/rails-3-2/.gitignore +0 -18
  37. data/test/apps/rails-3-2/Gemfile +0 -9
  38. data/test/apps/rails-3-2/README.rdoc +0 -261
  39. data/test/apps/rails-3-2/Rakefile +0 -7
  40. data/test/apps/rails-3-2/app/assets/images/rails.png +0 -0
  41. data/test/apps/rails-3-2/app/assets/javascripts/application.js +0 -15
  42. data/test/apps/rails-3-2/app/assets/javascripts/posts.js.coffee +0 -3
  43. data/test/apps/rails-3-2/app/assets/stylesheets/application.css +0 -13
  44. data/test/apps/rails-3-2/app/assets/stylesheets/posts.css.scss +0 -3
  45. data/test/apps/rails-3-2/app/assets/stylesheets/scaffolds.css.scss +0 -69
  46. data/test/apps/rails-3-2/app/controllers/application_controller.rb +0 -3
  47. data/test/apps/rails-3-2/app/controllers/posts_controller.rb +0 -83
  48. data/test/apps/rails-3-2/app/helpers/application_helper.rb +0 -2
  49. data/test/apps/rails-3-2/app/helpers/posts_helper.rb +0 -2
  50. data/test/apps/rails-3-2/app/mailers/.gitkeep +0 -0
  51. data/test/apps/rails-3-2/app/models/.gitkeep +0 -0
  52. data/test/apps/rails-3-2/app/models/post.rb +0 -3
  53. data/test/apps/rails-3-2/app/views/layouts/application.html.erb +0 -14
  54. data/test/apps/rails-3-2/app/views/posts/_form.html.erb +0 -21
  55. data/test/apps/rails-3-2/app/views/posts/edit.html.erb +0 -6
  56. data/test/apps/rails-3-2/app/views/posts/index.html.erb +0 -23
  57. data/test/apps/rails-3-2/app/views/posts/new.html.erb +0 -5
  58. data/test/apps/rails-3-2/app/views/posts/show.html.erb +0 -10
  59. data/test/apps/rails-3-2/config/application.rb +0 -62
  60. data/test/apps/rails-3-2/config/boot.rb +0 -6
  61. data/test/apps/rails-3-2/config/database.yml +0 -25
  62. data/test/apps/rails-3-2/config/environment.rb +0 -5
  63. data/test/apps/rails-3-2/config/environments/development.rb +0 -37
  64. data/test/apps/rails-3-2/config/environments/production.rb +0 -67
  65. data/test/apps/rails-3-2/config/environments/test.rb +0 -37
  66. data/test/apps/rails-3-2/config/initializers/backtrace_silencers.rb +0 -7
  67. data/test/apps/rails-3-2/config/initializers/inflections.rb +0 -15
  68. data/test/apps/rails-3-2/config/initializers/mime_types.rb +0 -5
  69. data/test/apps/rails-3-2/config/initializers/secret_token.rb +0 -7
  70. data/test/apps/rails-3-2/config/initializers/session_store.rb +0 -8
  71. data/test/apps/rails-3-2/config/initializers/wrap_parameters.rb +0 -14
  72. data/test/apps/rails-3-2/config/locales/en.yml +0 -5
  73. data/test/apps/rails-3-2/config/routes.rb +0 -60
  74. data/test/apps/rails-3-2/config/spring.rb +0 -7
  75. data/test/apps/rails-3-2/config.ru +0 -4
  76. data/test/apps/rails-3-2/db/migrate/20121109171227_create_posts.rb +0 -9
  77. data/test/apps/rails-3-2/db/schema.rb +0 -22
  78. data/test/apps/rails-3-2/db/seeds.rb +0 -7
  79. data/test/apps/rails-3-2/lib/assets/.gitkeep +0 -0
  80. data/test/apps/rails-3-2/lib/tasks/.gitkeep +0 -0
  81. data/test/apps/rails-3-2/log/.gitkeep +0 -0
  82. data/test/apps/rails-3-2/public/404.html +0 -26
  83. data/test/apps/rails-3-2/public/422.html +0 -26
  84. data/test/apps/rails-3-2/public/500.html +0 -25
  85. data/test/apps/rails-3-2/public/favicon.ico +0 -0
  86. data/test/apps/rails-3-2/public/index.html +0 -241
  87. data/test/apps/rails-3-2/public/robots.txt +0 -5
  88. data/test/apps/rails-3-2/script/rails +0 -6
  89. data/test/apps/rails-3-2/test/fixtures/.gitkeep +0 -0
  90. data/test/apps/rails-3-2/test/fixtures/posts.yml +0 -7
  91. data/test/apps/rails-3-2/test/functional/.gitkeep +0 -0
  92. data/test/apps/rails-3-2/test/functional/posts_controller_test.rb +0 -49
  93. data/test/apps/rails-3-2/test/integration/.gitkeep +0 -0
  94. data/test/apps/rails-3-2/test/performance/browsing_test.rb +0 -12
  95. data/test/apps/rails-3-2/test/test_helper.rb +0 -13
  96. data/test/apps/rails-3-2/test/unit/.gitkeep +0 -0
  97. data/test/apps/rails-3-2/test/unit/helpers/posts_helper_test.rb +0 -4
  98. data/test/apps/rails-3-2/test/unit/post_test.rb +0 -7
  99. data/test/apps/rails-3-2/vendor/assets/javascripts/.gitkeep +0 -0
  100. data/test/apps/rails-3-2/vendor/assets/stylesheets/.gitkeep +0 -0
  101. 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
@@ -2,3 +2,6 @@ language: ruby
2
2
  rvm:
3
3
  - 1.9.3
4
4
  - 2.0.0
5
+ env:
6
+ - RAILS_VERSION="~> 3.2.0"
7
+ - RAILS_VERSION="~> 4.0.0"
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
@@ -3,6 +3,4 @@ source 'https://rubygems.org'
3
3
  # Specify your gem's dependencies in spring.gemspec
4
4
  gemspec
5
5
 
6
- gem 'listen', :require => false
7
- gem 'rb-inotify', :require => false
8
- gem 'rb-fsevent', :require => false
6
+ gem 'listen', "~> 1.0", :require => false
data/README.md CHANGED
@@ -2,72 +2,45 @@
2
2
 
3
3
  [![Build Status](https://travis-ci.org/jonleighton/spring.png?branch=master)](https://travis-ci.org/jonleighton/spring)
4
4
 
5
- Spring is a Rails application preloader. It's trying to solve the same
6
- problem as [spork](https://github.com/sporkrb/spork),
7
- [zeus](https://github.com/burke/zeus) and
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
- Spring is most similar to Zeus, but it's implemented in pure Ruby, and
20
- is more tightly integrated with Rails (it makes use of Rails' built-in
21
- code reloader).
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 supported:
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
- Rails versions supported:
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
- * 3.2
24
+ ## Walkthrough
51
25
 
52
- Spring makes extensive use of `Process#fork`, so won't be able to run on
53
- any platform which doesn't support that (Windows, JRuby).
26
+ Either `gem install spring` or add it to your Gemfile:
54
27
 
55
- ## Usage
56
-
57
- Install the `spring` gem. You can add it to your Gemfile if you like but
58
- it's optional. You now have a `spring` command. Don't use it with
59
- `bundle exec` or it will be extremely slow.
28
+ ``` ruby
29
+ group :development do
30
+ gem "spring"
31
+ end
32
+ ```
60
33
 
61
- For this walkthrough, I'm using the test app in the Spring repository:
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
- cd /path/to/spring/test/apps/rails-3-2
65
- ```
37
+ For this walkthrough I've generated a new Rails application, and run
38
+ `rails generate scaffold posts name:string`.
66
39
 
67
- We can run a test:
40
+ Let's run a test:
68
41
 
69
42
  ```
70
- $ time spring testunit test/functional/posts_controller_test.rb
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 0m2.165s
82
- user 0m0.281s
83
- sys 0m0.066s
54
+ real 0m2.165s
55
+ user 0m0.281s
56
+ sys 0m0.066s
84
57
  ```
85
58
 
86
- That booted our app in the background:
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 | rails-3-2 | started 3 secs ago
93
- 26155 spring app | rails-3-2 | started 3 secs ago | test mode
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
- We can see two processes, one is the Spring server, the other is the
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 testunit test/functional/posts_controller_test.rb
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 0m0.610s
115
- user 0m0.276s
116
- sys 0m0.059s
84
+ real 0m0.610s
85
+ user 0m0.276s
86
+ sys 0m0.059s
117
87
  ```
118
88
 
119
- Running `spring testunit`, `spring rake`, `spring rails`, etc gets a bit
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
- Finished tests in 0.166585s, 42.0207 tests/s, 60.0296 assertions/s.
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
- 7 tests, 10 assertions, 0 failures, 0 errors, 0 skips
147
-
148
- real 0m0.407s
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
- You can add "./bin" to your `PATH` when in your application's directory
154
- [with direnv](https://github.com/zimbatm/direnv), but you should
155
- recognise and understand the security implications of using that.
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
- If we edit any of the application files, or test files, the change will
158
- be picked up on the next run, without the background process
159
- having to be restarted.
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
- If we edit any of the preloaded files, the application needs to restart
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 | rails-3-2 | started 36 secs ago
170
- 26556 spring app | rails-3-2 | started 1 sec ago | test mode
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 process detected the change and exited. The server process
174
- then detected that the application process exited, so it started a new application.
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 it gets
180
- booted up. For example, the `rake` command uses the `development`
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 | rails-3-2 | started 1 min ago
203
- 26556 spring app | rails-3-2 | started 42 secs ago | test mode
204
- 26707 spring app | rails-3-2 | started 2 secs ago | development mode
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
- To stop the background processes:
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
- $ bin/spring stop
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 `config/spring.rb`. See
219
- [`lib/spring/commands.rb`](https://github.com/jonleighton/spring/blob/master/lib/spring/commands.rb)
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
- A bunch of different test frameworks are supported at the moment in
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
- This command can also recursively run a directory of tests. For example,
232
- `spring testunit test/functional` will run `test/functional/**/*_test.rb`.
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
- ### `rspec`
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 cucumber feature.
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
- ### `rake`
182
+ ``` ruby
183
+ Spring::Commands::Rake.environment_matchers["perf_test"] = "test"
184
+ Spring::Commands::Rake.environment_matchers[/^perf/] = "test"
244
185
 
245
- Runs a rake task.
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
- ### application_root
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 rails application. If you have a
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
- ### preload files
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
- # if you don't want to preload spec_helper.rb
282
- Commands::Command::RSpec.preloads = []
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
- # if you want to preload additional files for the console
285
- Commands::Command::RailsConsole.preloads << 'extenstions/console_helper'
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 fork callbacks
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
- As mentioned above, Spring will automatically detect file changes to any file loaded when the server
312
- boots. If you would like to watch additional files or directories, use
313
- `Spring.watch`:
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 "#{Rails.root}/spec/factories"
255
+ Spring.watch "spec/factories"
317
256
  ```
318
257
 
319
- ### Filesystem polling
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 by
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
- group :development, :test do
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
- Note that this make the initial application startup slightly slower.
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)