spring 0.0.8 → 0.0.9
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.
- data/CHANGELOG.md +10 -0
- data/README.md +47 -32
- data/bin/spring +1 -0
- data/lib/spring/application.rb +1 -1
- data/lib/spring/application_manager.rb +5 -4
- data/lib/spring/client/run.rb +2 -2
- data/lib/spring/commands.rb +29 -9
- data/lib/spring/env.rb +9 -6
- data/lib/spring/server.rb +23 -11
- data/lib/spring/version.rb +1 -1
- data/lib/spring/watcher/listen.rb +10 -3
- data/test/acceptance/app_test.rb +43 -5
- data/test/apps/rails-3-2/Gemfile +1 -0
- data/test/apps/rails-3-2/spec/dummy_spec.rb +5 -0
- data/test/unit/commands_test.rb +9 -14
- data/test/unit/watcher_test.rb +2 -1
- metadata +4 -4
- data/test/apps/rails-3-2/test/performance/browsing_test.rb +0 -12
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,13 @@
|
|
1
|
+
## 0.0.9
|
2
|
+
|
3
|
+
* Added `Spring::Commands::Rake.environment_matchers` for matching
|
4
|
+
rake tasks to specific environments.
|
5
|
+
* Kill the spring server when the `Gemfile` or `Gemfile.lock` is
|
6
|
+
changed. This forces a new server to boot up on the next run, which
|
7
|
+
ensures that you get the correct gems (or the correct error message from
|
8
|
+
bundler if you have forgotten to `bundle install`.)
|
9
|
+
* Fixed error when `Spring.watch` is used in `config/spring.rb`
|
10
|
+
|
1
11
|
## 0.0.8
|
2
12
|
|
3
13
|
* Renamed `spring test` to `spring testunit`.
|
data/README.md
CHANGED
@@ -78,9 +78,9 @@ Finished tests in 0.127245s, 55.0121 tests/s, 78.5887 assertions/s.
|
|
78
78
|
|
79
79
|
7 tests, 10 assertions, 0 failures, 0 errors, 0 skips
|
80
80
|
|
81
|
-
real
|
82
|
-
user
|
83
|
-
sys
|
81
|
+
real 0m2.165s
|
82
|
+
user 0m0.281s
|
83
|
+
sys 0m0.066s
|
84
84
|
```
|
85
85
|
|
86
86
|
That booted our app in the background:
|
@@ -111,9 +111,9 @@ Finished tests in 0.176896s, 39.5714 tests/s, 56.5305 assertions/s.
|
|
111
111
|
|
112
112
|
7 tests, 10 assertions, 0 failures, 0 errors, 0 skips
|
113
113
|
|
114
|
-
real
|
115
|
-
user
|
116
|
-
sys
|
114
|
+
real 0m0.610s
|
115
|
+
user 0m0.276s
|
116
|
+
sys 0m0.059s
|
117
117
|
```
|
118
118
|
|
119
119
|
Running `spring testunit`, `spring rake`, `spring rails`, etc gets a bit
|
@@ -145,15 +145,22 @@ Finished tests in 0.166585s, 42.0207 tests/s, 60.0296 assertions/s.
|
|
145
145
|
|
146
146
|
7 tests, 10 assertions, 0 failures, 0 errors, 0 skips
|
147
147
|
|
148
|
-
real
|
149
|
-
user
|
150
|
-
sys
|
148
|
+
real 0m0.407s
|
149
|
+
user 0m0.077s
|
150
|
+
sys 0m0.059s
|
151
151
|
```
|
152
152
|
|
153
153
|
You can add "./bin" to your `PATH` when in your application's directory
|
154
154
|
[with direnv](https://github.com/zimbatm/direnv), but you should
|
155
155
|
recognise and understand the security implications of using that.
|
156
156
|
|
157
|
+
Note: Don't use spring binstubs with `bundle install --binstubs`. If
|
158
|
+
you do this, spring and bundler will overwrite each other. If _you will_
|
159
|
+
not be using a command with spring, use `bundle binstub [GEM]` to
|
160
|
+
generate a bundler binstub for that specific gem. If you _will_ be
|
161
|
+
using a command with spring, generate a spring binstub _instaed of_ a
|
162
|
+
bundler binstub; spring will run your command inside the bundle anyway.
|
163
|
+
|
157
164
|
If we edit any of the application files, or test files, the change will
|
158
165
|
be picked up on the next run, without the background process
|
159
166
|
having to be restarted.
|
@@ -242,7 +249,17 @@ Runs a cucumber feature.
|
|
242
249
|
|
243
250
|
### `rake`
|
244
251
|
|
245
|
-
Runs a rake task.
|
252
|
+
Runs a rake task. Rake tasks run in the `development` environment by
|
253
|
+
default. You can change this on the fly by using the `RAILS_ENV`
|
254
|
+
environment variable. The environment is also configurable with the
|
255
|
+
`Spring::Commands::Rake.environment_matchers` hash. This has sensible
|
256
|
+
defaults, but if you need to match a specific task to a specific
|
257
|
+
environment, you'd do it like this:
|
258
|
+
|
259
|
+
``` ruby
|
260
|
+
Spring::Commands::Rake.environment_matchers["perf_test"] = "test"
|
261
|
+
Spring::Commands::Rake.environment_matchers[/^perf/] = "test"
|
262
|
+
```
|
246
263
|
|
247
264
|
### `rails console`, `rails generate`, `rails runner`
|
248
265
|
|
@@ -251,22 +268,22 @@ a different sub command (e.g. `rails server`) then spring will automatically
|
|
251
268
|
pass it through to the underlying `rails` executable (without the
|
252
269
|
speed-up).
|
253
270
|
|
254
|
-
## Configuration
|
271
|
+
## Configuration file
|
272
|
+
|
273
|
+
Spring will read `config/spring.rb` for custom settings, described below.
|
255
274
|
|
256
|
-
###
|
275
|
+
### Specifying application root
|
257
276
|
|
258
|
-
Spring must know how to find your
|
277
|
+
Spring must know how to find your Rails application. If you have a
|
259
278
|
normal app everything works out of the box. If you are working on a
|
260
279
|
project with a special setup (an engine for example), you must tell
|
261
280
|
Spring where your app is located:
|
262
281
|
|
263
|
-
**config/spring.rb**
|
264
|
-
|
265
282
|
```ruby
|
266
283
|
Spring.application_root = './test/dummy'
|
267
284
|
```
|
268
285
|
|
269
|
-
###
|
286
|
+
### Preloading files
|
270
287
|
|
271
288
|
Every Spring command has the ability to preload a set of files. The
|
272
289
|
`test` command for example preloads `test_helper` (it also adds the
|
@@ -276,16 +293,16 @@ preloads for every command:
|
|
276
293
|
|
277
294
|
```ruby
|
278
295
|
# if your test helper is called "helper"
|
279
|
-
Commands::
|
296
|
+
Spring::Commands::TestUnit.preloads = %w(helper)
|
280
297
|
|
281
298
|
# if you don't want to preload spec_helper.rb
|
282
|
-
Commands::
|
299
|
+
Spring::Commands::RSpec.preloads = []
|
283
300
|
|
284
301
|
# if you want to preload additional files for the console
|
285
|
-
Commands::
|
302
|
+
Spring::Commands::RailsConsole.preloads << 'extensions/console_helper'
|
286
303
|
```
|
287
304
|
|
288
|
-
### after
|
305
|
+
### Callbacks after forking
|
289
306
|
|
290
307
|
You might want to run code after Spring forked off the process but
|
291
308
|
before the actual command is run. You might want to use an
|
@@ -301,22 +318,23 @@ end
|
|
301
318
|
If you want to register multiple callbacks you can simply call
|
302
319
|
`Spring.after_fork` multiple times with different blocks.
|
303
320
|
|
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
321
|
### Watching files and directories
|
310
322
|
|
311
323
|
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`:
|
324
|
+
boots. If you would like to watch additional files or directories, use `watch`:
|
314
325
|
|
315
326
|
```ruby
|
316
|
-
Spring.watch "
|
327
|
+
Spring.watch "spec/factories"
|
317
328
|
```
|
318
329
|
|
319
|
-
|
330
|
+
## Other configuration
|
331
|
+
|
332
|
+
### tmp directory
|
333
|
+
|
334
|
+
Spring needs a tmp directory. This will default to `Rails.root.join('tmp', 'spring')`.
|
335
|
+
You can set your own configuration directory by setting the `SPRING_TMP_PATH` environment variable.
|
336
|
+
|
337
|
+
### Filesystem polling speed
|
320
338
|
|
321
339
|
By default Spring will check the filesystem for changes once every 0.2 seconds. This
|
322
340
|
method requires zero configuration, but if you find that it's using too
|
@@ -326,9 +344,6 @@ adding the following to to your `Gemfile`:
|
|
326
344
|
```ruby
|
327
345
|
group :development, :test do
|
328
346
|
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
347
|
end
|
333
348
|
```
|
334
349
|
|
data/bin/spring
CHANGED
data/lib/spring/application.rb
CHANGED
@@ -24,7 +24,7 @@ module Spring
|
|
24
24
|
# The test environment has config.cache_classes = true set by default.
|
25
25
|
# However, we don't want this to prevent us from performing class reloading,
|
26
26
|
# so this gets around that.
|
27
|
-
Rails::Application.initializer :initialize_dependency_mechanism, group: :all do
|
27
|
+
::Rails::Application.initializer :initialize_dependency_mechanism, group: :all do
|
28
28
|
ActiveSupport::Dependencies.mechanism = :load
|
29
29
|
end
|
30
30
|
|
@@ -4,11 +4,10 @@ require "spring/application"
|
|
4
4
|
|
5
5
|
module Spring
|
6
6
|
class ApplicationManager
|
7
|
-
attr_reader :pid, :child, :app_env, :spring_env
|
8
|
-
|
9
|
-
def initialize(app_env)
|
10
|
-
super()
|
7
|
+
attr_reader :pid, :child, :app_env, :spring_env, :server
|
11
8
|
|
9
|
+
def initialize(server, app_env)
|
10
|
+
@server = server
|
12
11
|
@app_env = app_env
|
13
12
|
@spring_env = Env.new
|
14
13
|
@mutex = Mutex.new
|
@@ -78,6 +77,8 @@ module Spring
|
|
78
77
|
private
|
79
78
|
|
80
79
|
def start_child(silence = false)
|
80
|
+
server.application_starting
|
81
|
+
|
81
82
|
@child, child_socket = UNIXSocket.pair
|
82
83
|
@pid = fork {
|
83
84
|
[STDOUT, STDERR].each { |s| s.reopen('/dev/null', 'w') } if silence
|
data/lib/spring/client/run.rb
CHANGED
@@ -29,7 +29,7 @@ module Spring
|
|
29
29
|
|
30
30
|
def boot_server
|
31
31
|
env.socket_path.unlink if env.socket_path.exist?
|
32
|
-
Process.spawn(
|
32
|
+
Process.spawn(BINFILE, "start")
|
33
33
|
sleep 0.1 until env.socket_path.exist?
|
34
34
|
end
|
35
35
|
|
@@ -48,7 +48,7 @@ ERROR
|
|
48
48
|
|
49
49
|
def connect_to_application(client)
|
50
50
|
server.send_io client
|
51
|
-
send_json server, args: args, env: ENV
|
51
|
+
send_json server, args: args, env: ENV.to_hash
|
52
52
|
server.gets or raise CommandNotFound
|
53
53
|
end
|
54
54
|
|
data/lib/spring/commands.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require "spring/watcher"
|
2
|
+
|
1
3
|
# If the config/spring.rb contains requires for commands from other gems,
|
2
4
|
# then we need to be under bundler.
|
3
5
|
require "bundler/setup"
|
@@ -71,17 +73,18 @@ MESSAGE
|
|
71
73
|
end
|
72
74
|
|
73
75
|
def call(args)
|
74
|
-
if args.
|
75
|
-
|
76
|
-
|
76
|
+
if args.empty?
|
77
|
+
args = ['test']
|
78
|
+
end
|
77
79
|
|
80
|
+
ARGV.replace args
|
81
|
+
args.each do |arg|
|
82
|
+
path = File.expand_path(arg)
|
78
83
|
if File.directory?(path)
|
79
84
|
Dir[File.join path, "**", "*_test.rb"].each { |f| require f }
|
80
85
|
else
|
81
86
|
require path
|
82
87
|
end
|
83
|
-
else
|
84
|
-
$stderr.puts "you need to specify what test to run: spring test TEST_NAME"
|
85
88
|
end
|
86
89
|
end
|
87
90
|
|
@@ -107,7 +110,7 @@ MESSAGE
|
|
107
110
|
|
108
111
|
def call(args)
|
109
112
|
$0 = "rspec"
|
110
|
-
::RSpec::Core::Runner.run(args)
|
113
|
+
Kernel.exit ::RSpec::Core::Runner.run(args)
|
111
114
|
end
|
112
115
|
|
113
116
|
def description
|
@@ -127,7 +130,9 @@ MESSAGE
|
|
127
130
|
end
|
128
131
|
|
129
132
|
def call(args)
|
130
|
-
|
133
|
+
# Cucumber's execute funtion returns `true` if any of the steps failed or
|
134
|
+
# some other error occured.
|
135
|
+
Kernel.exit(1) if ::Cucumber::Cli::Main.execute(args)
|
131
136
|
end
|
132
137
|
|
133
138
|
def description
|
@@ -137,6 +142,21 @@ MESSAGE
|
|
137
142
|
Spring.register_command "cucumber", Cucumber.new
|
138
143
|
|
139
144
|
class Rake < Command
|
145
|
+
class << self
|
146
|
+
attr_accessor :environment_matchers
|
147
|
+
end
|
148
|
+
|
149
|
+
self.environment_matchers = {
|
150
|
+
/^(test|spec|cucumber)($|:)/ => "test"
|
151
|
+
}
|
152
|
+
|
153
|
+
def env(args)
|
154
|
+
self.class.environment_matchers.each do |matcher, environment|
|
155
|
+
return environment if matcher === args.first
|
156
|
+
end
|
157
|
+
nil
|
158
|
+
end
|
159
|
+
|
140
160
|
def setup
|
141
161
|
super
|
142
162
|
require "rake"
|
@@ -154,8 +174,8 @@ MESSAGE
|
|
154
174
|
Spring.register_command "rake", Rake.new
|
155
175
|
|
156
176
|
class RailsConsole < Command
|
157
|
-
def env(
|
158
|
-
|
177
|
+
def env(args)
|
178
|
+
args.first if args.first && !args.first.index("-")
|
159
179
|
end
|
160
180
|
|
161
181
|
def setup
|
data/lib/spring/env.rb
CHANGED
@@ -6,6 +6,7 @@ require "spring/sid"
|
|
6
6
|
|
7
7
|
module Spring
|
8
8
|
IGNORE_SIGNALS = %w(INT QUIT)
|
9
|
+
BINFILE = File.expand_path("../../../bin/spring", __FILE__)
|
9
10
|
|
10
11
|
class Env
|
11
12
|
attr_reader :root
|
@@ -48,12 +49,10 @@ module Spring
|
|
48
49
|
end
|
49
50
|
|
50
51
|
def server_running?
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
false
|
56
|
-
end
|
52
|
+
pidfile = pidfile_path.open('r')
|
53
|
+
!pidfile.flock(File::LOCK_EX | File::LOCK_NB)
|
54
|
+
rescue Errno::ENOENT
|
55
|
+
false
|
57
56
|
ensure
|
58
57
|
if pidfile
|
59
58
|
pidfile.flock(File::LOCK_UN)
|
@@ -61,6 +60,10 @@ module Spring
|
|
61
60
|
end
|
62
61
|
end
|
63
62
|
|
63
|
+
def bundle_mtime
|
64
|
+
[Bundler.default_lockfile, Bundler.default_gemfile].select(&:exist?).map(&:mtime).max
|
65
|
+
end
|
66
|
+
|
64
67
|
private
|
65
68
|
|
66
69
|
def default_tmp_path
|
data/lib/spring/server.rb
CHANGED
@@ -1,8 +1,11 @@
|
|
1
1
|
require "socket"
|
2
|
+
require "thread"
|
2
3
|
|
3
4
|
require "spring/env"
|
4
5
|
require "spring/application_manager"
|
5
6
|
require "spring/process_title_updater"
|
7
|
+
|
8
|
+
# Must be last, as it requires bundler/setup
|
6
9
|
require "spring/commands"
|
7
10
|
|
8
11
|
# readline must be required before we setpgid, otherwise the require may hang,
|
@@ -19,17 +22,19 @@ module Spring
|
|
19
22
|
|
20
23
|
def initialize(env = Env.new)
|
21
24
|
@env = env
|
22
|
-
@applications = Hash.new { |h, k| h[k] = ApplicationManager.new(k) }
|
25
|
+
@applications = Hash.new { |h, k| h[k] = ApplicationManager.new(self, k) }
|
23
26
|
@pidfile = env.pidfile_path.open('a')
|
27
|
+
@mutex = Mutex.new
|
24
28
|
end
|
25
29
|
|
26
30
|
def boot
|
31
|
+
write_pidfile
|
27
32
|
set_pgid
|
28
33
|
ignore_signals
|
29
34
|
set_exit_hook
|
30
|
-
write_pidfile
|
31
35
|
redirect_output
|
32
36
|
set_process_title
|
37
|
+
watch_bundle
|
33
38
|
|
34
39
|
server = UNIXServer.open(env.socket_name)
|
35
40
|
loop { serve server.accept }
|
@@ -78,15 +83,15 @@ module Spring
|
|
78
83
|
def set_exit_hook
|
79
84
|
server_pid = Process.pid
|
80
85
|
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
86
|
+
# We don't want this hook to run in any forks of the current process
|
87
|
+
at_exit { shutdown if Process.pid == server_pid }
|
88
|
+
end
|
89
|
+
|
90
|
+
def shutdown
|
91
|
+
@applications.values.each(&:stop)
|
87
92
|
|
88
|
-
|
89
|
-
|
93
|
+
[env.socket_path, env.pidfile_path].each do |path|
|
94
|
+
path.unlink if path.exist?
|
90
95
|
end
|
91
96
|
end
|
92
97
|
|
@@ -96,7 +101,6 @@ module Spring
|
|
96
101
|
@pidfile.write("#{Process.pid}\n")
|
97
102
|
@pidfile.fsync
|
98
103
|
else
|
99
|
-
$stderr.puts "#{@pidfile.path} is locked; it looks like a server is already running"
|
100
104
|
exit 1
|
101
105
|
end
|
102
106
|
end
|
@@ -121,5 +125,13 @@ module Spring
|
|
121
125
|
"spring server | #{env.app_name} | started #{distance} ago"
|
122
126
|
}
|
123
127
|
end
|
128
|
+
|
129
|
+
def watch_bundle
|
130
|
+
@bundle_mtime = env.bundle_mtime
|
131
|
+
end
|
132
|
+
|
133
|
+
def application_starting
|
134
|
+
@mutex.synchronize { exit if env.bundle_mtime != @bundle_mtime }
|
135
|
+
end
|
124
136
|
end
|
125
137
|
end
|
data/lib/spring/version.rb
CHANGED
@@ -5,6 +5,7 @@ module Spring
|
|
5
5
|
|
6
6
|
def self.available?
|
7
7
|
require "listen"
|
8
|
+
require "listen/version"
|
8
9
|
true
|
9
10
|
rescue LoadError
|
10
11
|
false
|
@@ -12,10 +13,15 @@ module Spring
|
|
12
13
|
|
13
14
|
def start
|
14
15
|
unless @listener
|
15
|
-
@listener = ::Listen
|
16
|
+
@listener = ::Listen.to(*base_directories, relative_paths: false)
|
16
17
|
@listener.latency(latency)
|
17
18
|
@listener.change(&method(:changed))
|
18
|
-
|
19
|
+
|
20
|
+
if ::Listen::VERSION >= "1.0.0"
|
21
|
+
@listener.start
|
22
|
+
else
|
23
|
+
@listener.start(false)
|
24
|
+
end
|
19
25
|
end
|
20
26
|
end
|
21
27
|
|
@@ -45,9 +51,10 @@ module Spring
|
|
45
51
|
end
|
46
52
|
|
47
53
|
def base_directories
|
48
|
-
[root] +
|
54
|
+
([root] +
|
49
55
|
files.reject { |f| f.start_with? root }.map { |f| File.expand_path("#{f}/..") } +
|
50
56
|
directories.reject { |d| d.start_with? root }
|
57
|
+
).uniq
|
51
58
|
end
|
52
59
|
end
|
53
60
|
end
|
data/test/acceptance/app_test.rb
CHANGED
@@ -6,6 +6,8 @@ require "spring/env"
|
|
6
6
|
require "pty"
|
7
7
|
|
8
8
|
class AppTest < ActiveSupport::TestCase
|
9
|
+
DEFAULT_TIMEOUT = ENV['CI'] ? 30 : 10
|
10
|
+
|
9
11
|
def app_root
|
10
12
|
Pathname.new("#{TEST_ROOT}/apps/rails-3-2")
|
11
13
|
end
|
@@ -30,12 +32,16 @@ class AppTest < ActiveSupport::TestCase
|
|
30
32
|
@stderr ||= IO.pipe
|
31
33
|
end
|
32
34
|
|
35
|
+
def env
|
36
|
+
@env ||= {"GEM_HOME" => gem_home.to_s, "GEM_PATH" => ""}
|
37
|
+
end
|
38
|
+
|
33
39
|
def app_run(command, opts = {})
|
34
40
|
start_time = Time.now
|
35
41
|
|
36
42
|
Bundler.with_clean_env do
|
37
43
|
Process.spawn(
|
38
|
-
|
44
|
+
env,
|
39
45
|
command.to_s,
|
40
46
|
out: stdout.last,
|
41
47
|
err: stderr.last,
|
@@ -44,7 +50,7 @@ class AppTest < ActiveSupport::TestCase
|
|
44
50
|
)
|
45
51
|
end
|
46
52
|
|
47
|
-
_, status = Timeout.timeout(opts.fetch(:timeout,
|
53
|
+
_, status = Timeout.timeout(opts.fetch(:timeout, DEFAULT_TIMEOUT)) { Process.wait2 }
|
48
54
|
|
49
55
|
stdout, stderr = read_streams
|
50
56
|
puts dump_streams(command, stdout, stderr) if ENV["SPRING_DEBUG"]
|
@@ -63,7 +69,7 @@ class AppTest < ActiveSupport::TestCase
|
|
63
69
|
def read_streams
|
64
70
|
[stdout, stderr].map(&:first).map do |stream|
|
65
71
|
output = ""
|
66
|
-
output << stream.readpartial(10240) while IO.select([stream], [], [], 0.
|
72
|
+
output << stream.readpartial(10240) while IO.select([stream], [], [], 0.5)
|
67
73
|
output
|
68
74
|
end
|
69
75
|
end
|
@@ -98,13 +104,13 @@ class AppTest < ActiveSupport::TestCase
|
|
98
104
|
|
99
105
|
def assert_success(command, expected_output = nil)
|
100
106
|
artifacts = app_run(command)
|
101
|
-
assert artifacts[:status].success?, "expected successful exit status"
|
107
|
+
assert artifacts[:status].success?, "expected successful exit status\n\n#{dump_streams(command, *artifacts.values_at(:stdout, :stderr))}"
|
102
108
|
assert_output artifacts, expected_output if expected_output
|
103
109
|
end
|
104
110
|
|
105
111
|
def assert_failure(command, expected_output = nil)
|
106
112
|
artifacts = app_run(command)
|
107
|
-
assert !artifacts[:status].success?, "expected unsuccessful exit status"
|
113
|
+
assert !artifacts[:status].success?, "expected unsuccessful exit status\n\n#{dump_streams(command, *artifacts.values_at(:stdout, :stderr))}"
|
108
114
|
assert_output artifacts, expected_output if expected_output
|
109
115
|
end
|
110
116
|
|
@@ -124,6 +130,8 @@ class AppTest < ActiveSupport::TestCase
|
|
124
130
|
setup do
|
125
131
|
@test = "#{app_root}/test/functional/posts_controller_test.rb"
|
126
132
|
@test_contents = File.read(@test)
|
133
|
+
@spec = "#{app_root}/spec/dummy_spec.rb"
|
134
|
+
@spec_contents = File.read(@spec)
|
127
135
|
@controller = "#{app_root}/app/controllers/posts_controller.rb"
|
128
136
|
@controller_contents = File.read(@controller)
|
129
137
|
|
@@ -143,6 +151,7 @@ class AppTest < ActiveSupport::TestCase
|
|
143
151
|
teardown do
|
144
152
|
app_run "#{spring} stop"
|
145
153
|
File.write(@test, @test_contents)
|
154
|
+
File.write(@spec, @spec_contents)
|
146
155
|
File.write(@controller, @controller_contents)
|
147
156
|
end
|
148
157
|
|
@@ -311,4 +320,33 @@ class AppTest < ActiveSupport::TestCase
|
|
311
320
|
assert_success "#{spring} rails runner -e staging 'puts Rails.env'", stdout: "staging"
|
312
321
|
assert_success "#{spring} rails runner --environment=staging 'puts Rails.env'", stdout: "staging"
|
313
322
|
end
|
323
|
+
|
324
|
+
test "exit code for failing specs" do
|
325
|
+
assert_success "#{spring} rspec"
|
326
|
+
File.write(@spec, @spec_contents.sub("true.should be_true", "false.should be_true"))
|
327
|
+
assert_failure "#{spring} rspec"
|
328
|
+
end
|
329
|
+
|
330
|
+
test "selecting rails environment for rake" do
|
331
|
+
env['RAILS_ENV'] = 'staging'
|
332
|
+
assert_success "#{spring} rake -p 'ENV[\"RAILS_ENV\"]'", stdout: "staging"
|
333
|
+
end
|
334
|
+
|
335
|
+
test "changing the Gemfile restarts the server" do
|
336
|
+
begin
|
337
|
+
gemfile = app_root.join("Gemfile")
|
338
|
+
gemfile_contents = gemfile.read
|
339
|
+
|
340
|
+
assert_success %(#{spring} rails runner 'require "rspec"')
|
341
|
+
|
342
|
+
File.write(gemfile, gemfile_contents.sub(%{gem 'rspec'}, %{# gem 'rspec'}))
|
343
|
+
app_run "bundle check"
|
344
|
+
|
345
|
+
await_reload
|
346
|
+
assert_failure %(#{spring} rails runner 'require "rspec"'), stderr: "cannot load such file -- rspec"
|
347
|
+
ensure
|
348
|
+
File.write(gemfile, gemfile_contents)
|
349
|
+
assert_success "bundle check"
|
350
|
+
end
|
351
|
+
end
|
314
352
|
end
|
data/test/apps/rails-3-2/Gemfile
CHANGED
data/test/unit/commands_test.rb
CHANGED
@@ -2,20 +2,6 @@ require "helper"
|
|
2
2
|
require "spring/commands"
|
3
3
|
|
4
4
|
class CommandsTest < ActiveSupport::TestCase
|
5
|
-
test "test command needs a test name" do
|
6
|
-
begin
|
7
|
-
real_stderr = $stderr
|
8
|
-
$stderr = StringIO.new('')
|
9
|
-
|
10
|
-
command = Spring::Commands::TestUnit.new
|
11
|
-
command.call([])
|
12
|
-
|
13
|
-
assert_equal "you need to specify what test to run: spring test TEST_NAME\n", $stderr.string
|
14
|
-
ensure
|
15
|
-
$stderr = real_stderr
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
5
|
test 'children of Command have inheritable accessor named "preload"' do
|
20
6
|
command1, command2 = 2.times.map { Class.new(Spring::Commands::Command) }
|
21
7
|
|
@@ -75,4 +61,13 @@ class CommandsTest < ActiveSupport::TestCase
|
|
75
61
|
command = Spring::Commands::RailsRunner.new
|
76
62
|
assert_nil command.env(['puts 1+1'])
|
77
63
|
end
|
64
|
+
|
65
|
+
test "rake command has configurable environments" do
|
66
|
+
command = Spring::Commands::Rake.new
|
67
|
+
assert_nil command.env(["foo"])
|
68
|
+
assert_equal "test", command.env(["test"])
|
69
|
+
assert_equal "test", command.env(["test:models"])
|
70
|
+
assert_equal "test", command.env(["spec"])
|
71
|
+
assert_nil command.env(["test_foo"])
|
72
|
+
end
|
78
73
|
end
|
data/test/unit/watcher_test.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: spring
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.9
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-06-09 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|
@@ -137,12 +137,12 @@ files:
|
|
137
137
|
- test/apps/rails-3-2/public/index.html
|
138
138
|
- test/apps/rails-3-2/public/robots.txt
|
139
139
|
- test/apps/rails-3-2/script/rails
|
140
|
+
- test/apps/rails-3-2/spec/dummy_spec.rb
|
140
141
|
- test/apps/rails-3-2/test/fixtures/.gitkeep
|
141
142
|
- test/apps/rails-3-2/test/fixtures/posts.yml
|
142
143
|
- test/apps/rails-3-2/test/functional/.gitkeep
|
143
144
|
- test/apps/rails-3-2/test/functional/posts_controller_test.rb
|
144
145
|
- test/apps/rails-3-2/test/integration/.gitkeep
|
145
|
-
- test/apps/rails-3-2/test/performance/browsing_test.rb
|
146
146
|
- test/apps/rails-3-2/test/test_helper.rb
|
147
147
|
- test/apps/rails-3-2/test/unit/.gitkeep
|
148
148
|
- test/apps/rails-3-2/test/unit/helpers/posts_helper_test.rb
|
@@ -234,12 +234,12 @@ test_files:
|
|
234
234
|
- test/apps/rails-3-2/public/index.html
|
235
235
|
- test/apps/rails-3-2/public/robots.txt
|
236
236
|
- test/apps/rails-3-2/script/rails
|
237
|
+
- test/apps/rails-3-2/spec/dummy_spec.rb
|
237
238
|
- test/apps/rails-3-2/test/fixtures/.gitkeep
|
238
239
|
- test/apps/rails-3-2/test/fixtures/posts.yml
|
239
240
|
- test/apps/rails-3-2/test/functional/.gitkeep
|
240
241
|
- test/apps/rails-3-2/test/functional/posts_controller_test.rb
|
241
242
|
- test/apps/rails-3-2/test/integration/.gitkeep
|
242
|
-
- test/apps/rails-3-2/test/performance/browsing_test.rb
|
243
243
|
- test/apps/rails-3-2/test/test_helper.rb
|
244
244
|
- test/apps/rails-3-2/test/unit/.gitkeep
|
245
245
|
- test/apps/rails-3-2/test/unit/helpers/posts_helper_test.rb
|
@@ -1,12 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
require 'rails/performance_test_help'
|
3
|
-
|
4
|
-
class BrowsingTest < ActionDispatch::PerformanceTest
|
5
|
-
# Refer to the documentation for all available options
|
6
|
-
# self.profile_options = { :runs => 5, :metrics => [:wall_time, :memory]
|
7
|
-
# :output => 'tmp/performance', :formats => [:flat] }
|
8
|
-
|
9
|
-
def test_homepage
|
10
|
-
get '/'
|
11
|
-
end
|
12
|
-
end
|