spring 0.0.11 → 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG.md +23 -0
- data/README.md +68 -132
- data/bin/spring +28 -6
- data/lib/spring/application.rb +5 -3
- data/lib/spring/client/binstub.rb +25 -34
- data/lib/spring/client/help.rb +2 -1
- data/lib/spring/client/run.rb +1 -1
- data/lib/spring/commands.rb +0 -2
- data/lib/spring/commands/rake.rb +9 -1
- data/lib/spring/commands/testunit.rb +4 -0
- data/lib/spring/json.rb +7 -2
- data/lib/spring/version.rb +1 -1
- data/test/acceptance/app_test.rb +45 -3
- data/test/unit/client/help_test.rb +2 -0
- data/test/unit/watcher_test.rb +3 -1
- metadata +12 -19
- data/lib/spring/commands/cucumber.rb +0 -15
- data/lib/spring/commands/rspec.rb +0 -15
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 0824c6fabd2c8830c1a610f25821f746367cee6f
|
4
|
+
data.tar.gz: 108cf6e1bd07af03dfbfe9078727315eab78b39e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c2ca57a02be596e85692d0b8e75f60bc28278f99d82bd5352e5f9ef283c49720b75cca34101061e897f692923d83e030d57da6796e90611c68c01dd3bf688813
|
7
|
+
data.tar.gz: ec4654a54e32ea00418c230ed1c159d6cc628309bb025292c109458140c5b6c41212106004c2b3c2546fc53b81027a3f70b3a58d8b1ad5d695afbad6c43c2f8b
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,26 @@
|
|
1
|
+
## 0.9.0
|
2
|
+
|
3
|
+
* Display spring version in the help message
|
4
|
+
* Remove workaround for Rubygems performance issue. This issue is solved
|
5
|
+
with Rubygems 2.1, so we no longer need to generate a "spring" binstub
|
6
|
+
file. We warn users if they are not taking advantage of the Rubygems
|
7
|
+
perf fix (e.g. if they are not on 2.1, or haven't run `gem pristine
|
8
|
+
--all`). To upgrade, delete your `bin/spring` and re-run `spring
|
9
|
+
binstub` for each of your binstubs.
|
10
|
+
* Binstubs now fall back to non-spring execution of a command if the
|
11
|
+
spring gem is not present. This might be useful for production
|
12
|
+
environments.
|
13
|
+
* The ENV will be replaced on each run to match the ENV which exists
|
14
|
+
when the spring command is actually run (rather than the ENV which
|
15
|
+
exists when spring first starts).
|
16
|
+
* Specifying the rails env after the rake command (e.g. `rake
|
17
|
+
RAILS_ENV=test db:migrate`) now works as expected.
|
18
|
+
* Provide an explicit way to set the environment to use when running
|
19
|
+
`rake` on its own.
|
20
|
+
* The `rspec` and `cucumber` commands are no longer shipped by default.
|
21
|
+
They've been moved to the `spring-commands-rspec` and
|
22
|
+
`spring-commands-cucumber` gems.
|
23
|
+
|
1
24
|
## 0.0.11
|
2
25
|
|
3
26
|
* Added the `rails destroy` command.
|
data/README.md
CHANGED
@@ -2,63 +2,42 @@
|
|
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
|
6
|
-
|
7
|
-
|
8
|
-
[commands](https://github.com/rails/commands).
|
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.
|
9
8
|
|
10
9
|
## Features
|
11
10
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
Spring tries to be totally automatic.
|
17
|
-
It boots up in the background the first time you run a
|
18
|
-
command. Then it speeds up subsequent commands. If it detects that your
|
19
|
-
pre-loaded environment has changed (maybe `config/application.rb` has
|
20
|
-
been edited) then it will reload your environment in the background,
|
21
|
-
ready for the next command. When you close your terminal session, Spring
|
22
|
-
will automatically shut down. There's no "server" to manually start and
|
23
|
-
stop.
|
24
|
-
|
25
|
-
Spring operates via a command line interface. Other solutions (e.g.
|
26
|
-
commands) take the approach of using a special console to run commands
|
27
|
-
from. This means we will have to re-implement shell features such as
|
28
|
-
history, completion, etc. Whilst it's not impossible to re-implement
|
29
|
-
those features, it's unnecessary work and our re-implementation
|
30
|
-
won't be as feature complete as a real shell. Using a real shell also
|
31
|
-
prevents the user having to constantly jump between a terminal with a
|
32
|
-
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
|
33
15
|
|
34
16
|
## Compatibility
|
35
17
|
|
36
|
-
Ruby versions
|
18
|
+
* Ruby versions: MRI 1.9.3, MRI 2.0.0
|
19
|
+
* Rails versions: 3.2, 4.0
|
37
20
|
|
38
|
-
|
39
|
-
|
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).
|
40
23
|
|
41
|
-
|
24
|
+
## Walkthrough
|
42
25
|
|
43
|
-
|
44
|
-
* 4.0
|
26
|
+
Either `gem install spring` or add it to your Gemfile:
|
45
27
|
|
46
|
-
|
47
|
-
|
28
|
+
``` ruby
|
29
|
+
group :development do
|
30
|
+
gem "spring"
|
31
|
+
end
|
32
|
+
```
|
48
33
|
|
49
|
-
|
34
|
+
Spring is designed to be used *without* bundle exec, so use `spring
|
35
|
+
[command]` rather than `bundle exec spring [command]`.
|
50
36
|
|
51
|
-
|
52
|
-
|
53
|
-
`bundle exec` or it will be extremely slow.
|
37
|
+
For this walkthrough I've generated a new Rails application, and run
|
38
|
+
`rails generate scaffold posts name:string`.
|
54
39
|
|
55
|
-
|
56
|
-
|
57
|
-
```
|
58
|
-
cd /path/to/spring/test/apps/rails-3-2
|
59
|
-
```
|
60
|
-
|
61
|
-
We can run a test:
|
40
|
+
Let's run a test:
|
62
41
|
|
63
42
|
```
|
64
43
|
$ time spring testunit test/functional/posts_controller_test.rb
|
@@ -77,21 +56,18 @@ user 0m0.281s
|
|
77
56
|
sys 0m0.066s
|
78
57
|
```
|
79
58
|
|
80
|
-
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:
|
81
61
|
|
82
62
|
```
|
83
63
|
$ spring status
|
84
64
|
Spring is running:
|
85
65
|
|
86
|
-
26150 spring server |
|
87
|
-
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
|
88
68
|
```
|
89
69
|
|
90
|
-
|
91
|
-
application running in the test environment. When we close the terminal,
|
92
|
-
the processes will be killed automatically.
|
93
|
-
|
94
|
-
Running the test is faster next time:
|
70
|
+
The next run is faster:
|
95
71
|
|
96
72
|
```
|
97
73
|
$ time spring testunit test/functional/posts_controller_test.rb
|
@@ -110,79 +86,50 @@ user 0m0.276s
|
|
110
86
|
sys 0m0.059s
|
111
87
|
```
|
112
88
|
|
113
|
-
|
114
|
-
tedious. It also suffers from a performance issue in Rubygems ([which I
|
115
|
-
am actively working on](https://github.com/rubygems/rubygems/pull/435))
|
116
|
-
which means the `spring` command takes a while to start up. The more
|
117
|
-
gems you have, the longer it takes.
|
118
|
-
|
119
|
-
Spring binstubs solve both of these problems. If you will be running the
|
120
|
-
`testunit` command regularly, run:
|
89
|
+
Writing `spring` before every command gets a bit tedious. Spring binstubs solve this:
|
121
90
|
|
122
91
|
```
|
123
92
|
$ spring binstub testunit
|
93
|
+
$ spring binstub rake
|
94
|
+
$ spring binstub rails
|
124
95
|
```
|
125
96
|
|
126
|
-
This
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
```
|
131
|
-
$ time bin/testunit test/functional/posts_controller_test.rb
|
132
|
-
Run options:
|
133
|
-
|
134
|
-
# Running tests:
|
135
|
-
|
136
|
-
.......
|
137
|
-
|
138
|
-
Finished tests in 0.166585s, 42.0207 tests/s, 60.0296 assertions/s.
|
97
|
+
This will generate `bin/testunit`, `bin/rake` and `bin/rails`. They
|
98
|
+
replace any binstubs that you might already have in your `bin/`
|
99
|
+
directory. Check them in to source control.
|
139
100
|
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
user 0m0.077s
|
144
|
-
sys 0m0.059s
|
145
|
-
```
|
146
|
-
|
147
|
-
You can add "./bin" to your `PATH` when in your application's directory
|
148
|
-
[with direnv](https://github.com/zimbatm/direnv), but you should
|
149
|
-
recognise and understand the security implications of using that.
|
101
|
+
If you don't want to prefix every command you type with `bin/`, you
|
102
|
+
can [use direnv](https://github.com/zimbatm/direnv) to automatically add
|
103
|
+
`./bin` to your `PATH` when you `cd` into your application.
|
150
104
|
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
bundler binstub; spring will run your command inside the bundle anyway.
|
105
|
+
If we edit any of the application files, or test files, the changes will
|
106
|
+
be picked up on the next run without the background process having to
|
107
|
+
restart. This works in exactly the same way as the code reloading
|
108
|
+
which allows you to refresh your browser and instantly see changes during
|
109
|
+
development.
|
157
110
|
|
158
|
-
|
159
|
-
|
160
|
-
|
111
|
+
But if we edit any of the files which were used to start the application
|
112
|
+
(configs, initializers, your gemfile), the application needs to be fully
|
113
|
+
restarted. This happens automatically.
|
161
114
|
|
162
|
-
|
163
|
-
automatically. Let's "edit" `config/application.rb`:
|
115
|
+
Let's "edit" `config/application.rb`:
|
164
116
|
|
165
117
|
```
|
166
118
|
$ touch config/application.rb
|
167
119
|
$ spring status
|
168
120
|
Spring is running:
|
169
121
|
|
170
|
-
26150 spring server |
|
171
|
-
26556 spring app |
|
122
|
+
26150 spring server | spring-demo-app | started 36 secs ago
|
123
|
+
26556 spring app | spring-demo-app | started 1 sec ago | test mode
|
172
124
|
```
|
173
125
|
|
174
|
-
The application
|
175
|
-
|
176
|
-
All of this happened automatically. Next time we run a
|
177
|
-
command we'll be running against a fresh application. We can see that
|
178
|
-
the start time and PID of the app process has changed.
|
126
|
+
The application detected that `config/application.rb` changed and
|
127
|
+
automatically restarted itself.
|
179
128
|
|
180
|
-
If we run a command that uses a different environment, then
|
181
|
-
booted up
|
182
|
-
environment by default:
|
129
|
+
If we run a command that uses a different environment, then that
|
130
|
+
environment gets booted up:
|
183
131
|
|
184
132
|
```
|
185
|
-
$ spring binstub rake
|
186
133
|
$ bin/rake routes
|
187
134
|
posts GET /posts(.:format) posts#index
|
188
135
|
POST /posts(.:format) posts#create
|
@@ -191,24 +138,21 @@ edit_post GET /posts/:id/edit(.:format) posts#edit
|
|
191
138
|
post GET /posts/:id(.:format) posts#show
|
192
139
|
PUT /posts/:id(.:format) posts#update
|
193
140
|
DELETE /posts/:id(.:format) posts#destroy
|
194
|
-
```
|
195
141
|
|
196
|
-
|
197
|
-
the application in development mode.
|
198
|
-
|
199
|
-
```
|
200
|
-
$ bin/spring status
|
142
|
+
$ spring status
|
201
143
|
Spring is running:
|
202
144
|
|
203
|
-
26150 spring server |
|
204
|
-
26556 spring app |
|
205
|
-
26707 spring app |
|
145
|
+
26150 spring server | spring-demo-app | started 1 min ago
|
146
|
+
26556 spring app | spring-demo-app | started 42 secs ago | test mode
|
147
|
+
26707 spring app | spring-demo-app | started 2 secs ago | development mode
|
206
148
|
```
|
207
149
|
|
208
|
-
|
150
|
+
There's no need to "shut down" spring. This will happen automatically
|
151
|
+
when you close your terminal. However if you do want to do a manual shut
|
152
|
+
down, use the `stop` command:
|
209
153
|
|
210
154
|
```
|
211
|
-
$
|
155
|
+
$ spring stop
|
212
156
|
Spring stopped.
|
213
157
|
```
|
214
158
|
|
@@ -217,13 +161,13 @@ Spring stopped.
|
|
217
161
|
The following commands are shipped by default.
|
218
162
|
|
219
163
|
Custom commands can be specified in the Spring config file. See
|
220
|
-
[`lib/spring/commands
|
164
|
+
[`lib/spring/commands/`](https://github.com/jonleighton/spring/blob/master/lib/spring/commands/)
|
221
165
|
for examples.
|
222
166
|
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
spring
|
167
|
+
You can also install the following gems for additional commands:
|
168
|
+
|
169
|
+
* [spring-commands-rspec](https://github.com/jonleighton/spring-commands-rspec)
|
170
|
+
* [spring-commands-cucumber](https://github.com/jonleighton/spring-commands-cucumber)
|
227
171
|
|
228
172
|
### `testunit`
|
229
173
|
|
@@ -235,17 +179,6 @@ This command can also recursively run a directory of tests. For example,
|
|
235
179
|
If your test helper file takes a while to load, consider preloading it
|
236
180
|
(see "Running code before forking" below).
|
237
181
|
|
238
|
-
### `rspec`
|
239
|
-
|
240
|
-
Runs an rspec spec, exactly the same as the `rspec` executable.
|
241
|
-
|
242
|
-
If your spec helper file takes a while to load, consider preloading it
|
243
|
-
(see "Running code before forking" below).
|
244
|
-
|
245
|
-
### `cucumber`
|
246
|
-
|
247
|
-
Runs a cucumber feature.
|
248
|
-
|
249
182
|
### `rake`
|
250
183
|
|
251
184
|
Runs a rake task. Rake tasks run in the `development` environment by
|
@@ -258,6 +191,9 @@ environment, you'd do it like this:
|
|
258
191
|
``` ruby
|
259
192
|
Spring::Commands::Rake.environment_matchers["perf_test"] = "test"
|
260
193
|
Spring::Commands::Rake.environment_matchers[/^perf/] = "test"
|
194
|
+
|
195
|
+
# To change the environment when you run `rake` with no arguments
|
196
|
+
Spring::Commands::Rake.environment_matchers[:default] = "development"
|
261
197
|
```
|
262
198
|
|
263
199
|
### `rails console`, `rails generate`, `rails runner`
|
data/bin/spring
CHANGED
@@ -1,9 +1,31 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
if
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
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
|
9
27
|
end
|
28
|
+
|
29
|
+
$LOAD_PATH.unshift File.expand_path("../../lib", __FILE__)
|
30
|
+
require 'spring/client'
|
31
|
+
Spring::Client.run(ARGV)
|
data/lib/spring/application.rb
CHANGED
@@ -98,8 +98,8 @@ module Spring
|
|
98
98
|
|
99
99
|
preload unless preloaded?
|
100
100
|
|
101
|
-
args
|
102
|
-
command
|
101
|
+
args, env = JSON.load(client.read(client.gets.to_i)).values_at("args", "env")
|
102
|
+
command = Spring.command(args.shift)
|
103
103
|
|
104
104
|
connect_database
|
105
105
|
setup command
|
@@ -112,8 +112,10 @@ module Spring
|
|
112
112
|
STDIN.reopen(streams.last)
|
113
113
|
IGNORE_SIGNALS.each { |sig| trap(sig, "DEFAULT") }
|
114
114
|
|
115
|
-
connect_database
|
116
115
|
ARGV.replace(args)
|
116
|
+
ENV.replace(env)
|
117
|
+
|
118
|
+
connect_database
|
117
119
|
srand
|
118
120
|
|
119
121
|
invoke_after_fork_callbacks
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module Spring
|
2
2
|
module Client
|
3
3
|
class Binstub < Command
|
4
|
-
attr_reader :bindir, :name
|
4
|
+
attr_reader :bindir, :name, :command
|
5
5
|
|
6
6
|
def self.description
|
7
7
|
"Generate spring based binstubs."
|
@@ -15,61 +15,52 @@ module Spring
|
|
15
15
|
def initialize(args)
|
16
16
|
super
|
17
17
|
|
18
|
-
@bindir
|
19
|
-
@name
|
18
|
+
@bindir = env.root.join("bin")
|
19
|
+
@name = args[1]
|
20
|
+
@command = Spring.commands[name]
|
20
21
|
end
|
21
22
|
|
22
23
|
def call
|
23
|
-
if
|
24
|
+
if command || name == "rails"
|
24
25
|
bindir.mkdir unless bindir.exist?
|
25
|
-
|
26
|
-
generate_command_binstub
|
26
|
+
generate_binstub
|
27
27
|
else
|
28
28
|
$stderr.puts "The '#{name}' command is not known to spring."
|
29
29
|
exit 1
|
30
30
|
end
|
31
31
|
end
|
32
32
|
|
33
|
-
def
|
34
|
-
bindir.join("spring")
|
35
|
-
end
|
36
|
-
|
37
|
-
def command_binstub
|
33
|
+
def binstub
|
38
34
|
bindir.join(name)
|
39
35
|
end
|
40
36
|
|
41
|
-
def
|
42
|
-
File.write(
|
37
|
+
def generate_binstub
|
38
|
+
File.write(binstub, <<CODE)
|
43
39
|
#!/usr/bin/env ruby
|
44
40
|
|
45
|
-
|
46
|
-
#
|
47
|
-
# https://github.com/rubygems/rubygems/pull/435
|
48
|
-
|
49
|
-
glob = "{#{Gem::Specification.dirs.join(",")}}/spring-*.gemspec"
|
50
|
-
candidates = Dir[glob].to_a.sort_by { |c| Gem::Version.new(File.basename(c).split(/[-\.]/)[1...-1].join(".")) }
|
51
|
-
|
52
|
-
spec = Gem::Specification.load(candidates.last)
|
53
|
-
|
54
|
-
if spec
|
55
|
-
spec.activate
|
56
|
-
load spec.bin_file("spring")
|
41
|
+
if !Process.respond_to?(:fork) || Gem::Specification.find_all_by_name("spring").empty?
|
42
|
+
#{fallback.strip.gsub(/^/, " ")}
|
57
43
|
else
|
58
|
-
|
59
|
-
|
44
|
+
ARGV.unshift "#{name}"
|
45
|
+
load Gem.bin_path("spring", "spring")
|
60
46
|
end
|
61
47
|
CODE
|
62
48
|
|
63
|
-
|
49
|
+
binstub.chmod 0755
|
64
50
|
end
|
65
51
|
|
66
|
-
def
|
67
|
-
|
68
|
-
|
69
|
-
|
52
|
+
def fallback
|
53
|
+
if command.respond_to?(:fallback)
|
54
|
+
command.fallback
|
55
|
+
elsif name == "rails"
|
56
|
+
<<CODE
|
57
|
+
APP_PATH = File.expand_path('../../config/application', __FILE__)
|
58
|
+
require_relative '../config/boot'
|
59
|
+
require 'rails/commands'
|
70
60
|
CODE
|
71
|
-
|
72
|
-
|
61
|
+
else
|
62
|
+
%{exec "bundle", "exec", "#{name}", *ARGV}
|
63
|
+
end
|
73
64
|
end
|
74
65
|
end
|
75
66
|
end
|
data/lib/spring/client/help.rb
CHANGED
@@ -28,7 +28,8 @@ module Spring
|
|
28
28
|
end
|
29
29
|
|
30
30
|
def formatted_help
|
31
|
-
["
|
31
|
+
["Version: #{env.version}\n",
|
32
|
+
"Usage: spring COMMAND [ARGS]\n",
|
32
33
|
*command_help("spring itself", spring_commands),
|
33
34
|
'',
|
34
35
|
*command_help("your application", application_commands)].join("\n")
|
data/lib/spring/client/run.rb
CHANGED
data/lib/spring/commands.rb
CHANGED
@@ -22,8 +22,6 @@ module Spring
|
|
22
22
|
require "spring/commands/rails"
|
23
23
|
require "spring/commands/rake"
|
24
24
|
require "spring/commands/testunit"
|
25
|
-
require "spring/commands/rspec"
|
26
|
-
require "spring/commands/cucumber"
|
27
25
|
|
28
26
|
# If the config/spring.rb contains requires for commands from other gems,
|
29
27
|
# then we need to be under bundler.
|
data/lib/spring/commands/rake.rb
CHANGED
@@ -6,13 +6,21 @@ module Spring
|
|
6
6
|
end
|
7
7
|
|
8
8
|
self.environment_matchers = {
|
9
|
+
:default => "test",
|
9
10
|
/^(test|spec|cucumber)($|:)/ => "test"
|
10
11
|
}
|
11
12
|
|
12
13
|
def env(args)
|
14
|
+
# This is an adaption of the matching that Rake itself does.
|
15
|
+
# See: https://github.com/jimweirich/rake/blob/3754a7639b3f42c2347857a0878beb3523542aee/lib/rake/application.rb#L691-L692
|
16
|
+
if env = args.grep(/^(RAILS|RACK)_ENV=(.*)$/m).last
|
17
|
+
return env.split("=").last
|
18
|
+
end
|
19
|
+
|
13
20
|
self.class.environment_matchers.each do |matcher, environment|
|
14
|
-
return environment if matcher === args.first
|
21
|
+
return environment if matcher === (args.first || :default)
|
15
22
|
end
|
23
|
+
|
16
24
|
nil
|
17
25
|
end
|
18
26
|
|
data/lib/spring/json.rb
CHANGED
@@ -53,7 +53,7 @@ require 'stringio'
|
|
53
53
|
# http://golang.org/src/pkg/utf8/utf8.go
|
54
54
|
module Spring
|
55
55
|
module OkJson
|
56
|
-
Upstream = '
|
56
|
+
Upstream = '43'
|
57
57
|
extend self
|
58
58
|
|
59
59
|
|
@@ -486,11 +486,16 @@ private
|
|
486
486
|
# In ruby >= 1.9, s[r] is a codepoint, not a byte.
|
487
487
|
if rubydoesenc?
|
488
488
|
begin
|
489
|
-
c.ord
|
489
|
+
# c.ord will raise an error if c is invalid UTF-8
|
490
|
+
if c.ord < Spc.ord
|
491
|
+
c = "\\u%04x" % [c.ord]
|
492
|
+
end
|
490
493
|
t.write(c)
|
491
494
|
rescue
|
492
495
|
t.write(Ustrerr)
|
493
496
|
end
|
497
|
+
elsif c < Spc
|
498
|
+
t.write("\\u%04x" % c)
|
494
499
|
elsif Spc <= c && c <= ?~
|
495
500
|
t.putc(c)
|
496
501
|
else
|
data/lib/spring/version.rb
CHANGED
data/test/acceptance/app_test.rb
CHANGED
@@ -179,8 +179,10 @@ class AppTest < ActiveSupport::TestCase
|
|
179
179
|
|
180
180
|
def generate_app
|
181
181
|
Bundler.with_clean_env do
|
182
|
+
# Sporadic SSL errors keep causing test failures so there are anti-SSL workarounds here
|
183
|
+
|
182
184
|
assert system("(gem list rails --installed --version '#{rails_version}' || " \
|
183
|
-
"gem install rails --version '#{rails_version}') > /dev/null")
|
185
|
+
"gem install rails --clear-sources --source http://rubygems.org --version '#{rails_version}') > /dev/null")
|
184
186
|
|
185
187
|
# Have to shell out otherwise bundler prevents us finding the gem
|
186
188
|
version = `ruby -e 'puts Gem::Specification.find_by_name("rails", "#{rails_version}").version'`.chomp
|
@@ -190,6 +192,11 @@ class AppTest < ActiveSupport::TestCase
|
|
190
192
|
FileUtils.mkdir_p(gem_home)
|
191
193
|
FileUtils.mkdir_p(user_home)
|
192
194
|
FileUtils.rm_rf("#{app_root}/test/performance/")
|
195
|
+
|
196
|
+
File.write(
|
197
|
+
"#{app_root}/Gemfile",
|
198
|
+
File.read("#{app_root}/Gemfile").sub("https://rubygems.org", "http://rubygems.org")
|
199
|
+
)
|
193
200
|
end
|
194
201
|
end
|
195
202
|
|
@@ -198,7 +205,7 @@ class AppTest < ActiveSupport::TestCase
|
|
198
205
|
|
199
206
|
assert system("gem build spring.gemspec 2>/dev/null 1>/dev/null")
|
200
207
|
|
201
|
-
assert_success "gem install ../../../spring-#{Spring::VERSION}.gem"
|
208
|
+
assert_success ["gem install ../../../spring-#{Spring::VERSION}.gem", timeout: nil]
|
202
209
|
assert_success ["(gem list bundler | grep bundler) || gem install bundler", timeout: nil]
|
203
210
|
assert_success ["bundle check || bundle update", timeout: nil]
|
204
211
|
|
@@ -367,7 +374,7 @@ class AppTest < ActiveSupport::TestCase
|
|
367
374
|
|
368
375
|
app_run "#{spring} binstub rake"
|
369
376
|
app_run "#{spring} binstub rails"
|
370
|
-
|
377
|
+
|
371
378
|
assert_success "bin/rake -T", stdout: "rake db:migrate"
|
372
379
|
assert_success "bin/rails runner 'puts %(omg)'", stdout: "omg"
|
373
380
|
assert_success "bin/rails server --help", stdout: "Usage: rails server"
|
@@ -423,6 +430,28 @@ class AppTest < ActiveSupport::TestCase
|
|
423
430
|
assert_success "#{spring} rake -p 'Rails.env'", stdout: "production"
|
424
431
|
end
|
425
432
|
|
433
|
+
test "setting env vars with rake" do
|
434
|
+
begin
|
435
|
+
File.write("#{app_root}/lib/tasks/env.rake", <<-'CODE')
|
436
|
+
task :print_rails_env => :environment do
|
437
|
+
puts Rails.env
|
438
|
+
end
|
439
|
+
|
440
|
+
task :print_env do
|
441
|
+
ENV.each { |k, v| puts "#{k}=#{v}" }
|
442
|
+
end
|
443
|
+
|
444
|
+
task(:default).clear.enhance [:print_rails_env]
|
445
|
+
CODE
|
446
|
+
|
447
|
+
assert_success "#{spring} rake RAILS_ENV=test print_rails_env", stdout: "test"
|
448
|
+
assert_success "#{spring} rake FOO=bar print_env", stdout: "FOO=bar"
|
449
|
+
assert_success "#{spring} rake", stdout: "test"
|
450
|
+
ensure
|
451
|
+
FileUtils.rm_f("#{app_root}/lib/tasks/env.rake")
|
452
|
+
end
|
453
|
+
end
|
454
|
+
|
426
455
|
test "changing the Gemfile restarts the server" do
|
427
456
|
begin
|
428
457
|
gemfile = app_root.join("Gemfile")
|
@@ -440,4 +469,17 @@ class AppTest < ActiveSupport::TestCase
|
|
440
469
|
assert_success "bundle check"
|
441
470
|
end
|
442
471
|
end
|
472
|
+
|
473
|
+
test "changing the environment between runs" do
|
474
|
+
env["OMG"] = "1"
|
475
|
+
env["FOO"] = "1"
|
476
|
+
|
477
|
+
assert_success %(#{spring} rails runner 'p ENV["OMG"]'), stdout: "1"
|
478
|
+
|
479
|
+
env["OMG"] = "2"
|
480
|
+
env.delete "FOO"
|
481
|
+
|
482
|
+
assert_success %(#{spring} rails runner 'p ENV["OMG"]'), stdout: "2"
|
483
|
+
assert_success %(#{spring} rails runner 'p ENV.key?("FOO")'), stdout: "false"
|
484
|
+
end
|
443
485
|
end
|
data/test/unit/watcher_test.rb
CHANGED
@@ -127,12 +127,14 @@ module WatcherTests
|
|
127
127
|
watcher.add file
|
128
128
|
watcher.start
|
129
129
|
|
130
|
+
io = watcher.to_io
|
131
|
+
|
130
132
|
Thread.new {
|
131
133
|
sleep LATENCY * 3
|
132
134
|
touch file, Time.now
|
133
135
|
}
|
134
136
|
|
135
|
-
assert IO.select([
|
137
|
+
assert IO.select([io], [], [], 1), "IO.select timed out before watcher was readable"
|
136
138
|
assert watcher.stale?
|
137
139
|
end
|
138
140
|
|
metadata
CHANGED
@@ -1,46 +1,41 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: spring
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
5
|
-
prerelease:
|
4
|
+
version: 0.9.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Jon Leighton
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date: 2013-10-
|
11
|
+
date: 2013-10-27 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: activesupport
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
|
-
- -
|
17
|
+
- - '>='
|
20
18
|
- !ruby/object:Gem::Version
|
21
19
|
version: '0'
|
22
20
|
type: :development
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
|
-
- -
|
24
|
+
- - '>='
|
28
25
|
- !ruby/object:Gem::Version
|
29
26
|
version: '0'
|
30
27
|
- !ruby/object:Gem::Dependency
|
31
28
|
name: rake
|
32
29
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
30
|
requirements:
|
35
|
-
- -
|
31
|
+
- - '>='
|
36
32
|
- !ruby/object:Gem::Version
|
37
33
|
version: '0'
|
38
34
|
type: :development
|
39
35
|
prerelease: false
|
40
36
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
37
|
requirements:
|
43
|
-
- -
|
38
|
+
- - '>='
|
44
39
|
- !ruby/object:Gem::Version
|
45
40
|
version: '0'
|
46
41
|
description: Rails application preloader
|
@@ -70,10 +65,8 @@ files:
|
|
70
65
|
- lib/spring/client/status.rb
|
71
66
|
- lib/spring/client/stop.rb
|
72
67
|
- lib/spring/commands.rb
|
73
|
-
- lib/spring/commands/cucumber.rb
|
74
68
|
- lib/spring/commands/rails.rb
|
75
69
|
- lib/spring/commands/rake.rb
|
76
|
-
- lib/spring/commands/rspec.rb
|
77
70
|
- lib/spring/commands/testunit.rb
|
78
71
|
- lib/spring/configuration.rb
|
79
72
|
- lib/spring/env.rb
|
@@ -97,27 +90,26 @@ files:
|
|
97
90
|
- test/unit/watcher_test.rb
|
98
91
|
homepage: http://github.com/jonleighton/spring
|
99
92
|
licenses: []
|
93
|
+
metadata: {}
|
100
94
|
post_install_message:
|
101
95
|
rdoc_options: []
|
102
96
|
require_paths:
|
103
97
|
- lib
|
104
98
|
required_ruby_version: !ruby/object:Gem::Requirement
|
105
|
-
none: false
|
106
99
|
requirements:
|
107
|
-
- -
|
100
|
+
- - '>='
|
108
101
|
- !ruby/object:Gem::Version
|
109
102
|
version: '0'
|
110
103
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
111
|
-
none: false
|
112
104
|
requirements:
|
113
|
-
- -
|
105
|
+
- - '>='
|
114
106
|
- !ruby/object:Gem::Version
|
115
107
|
version: '0'
|
116
108
|
requirements: []
|
117
109
|
rubyforge_project:
|
118
|
-
rubygems_version: 1.
|
110
|
+
rubygems_version: 2.1.9
|
119
111
|
signing_key:
|
120
|
-
specification_version:
|
112
|
+
specification_version: 4
|
121
113
|
summary: Rails application preloader
|
122
114
|
test_files:
|
123
115
|
- test/acceptance/app_test.rb
|
@@ -127,3 +119,4 @@ test_files:
|
|
127
119
|
- test/unit/commands_test.rb
|
128
120
|
- test/unit/process_title_updater_test.rb
|
129
121
|
- test/unit/watcher_test.rb
|
122
|
+
has_rdoc:
|