spring 0.9.0 → 0.9.1
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 +4 -4
- data/CHANGELOG.md +18 -0
- data/README.md +12 -17
- data/lib/spring/application.rb +3 -7
- data/lib/spring/client/binstub.rb +37 -24
- data/lib/spring/commands.rb +8 -5
- data/lib/spring/commands/rake.rb +2 -2
- data/lib/spring/version.rb +1 -1
- data/test/acceptance/app_test.rb +33 -17
- data/test/unit/commands_test.rb +0 -1
- metadata +2 -3
- data/lib/spring/commands/testunit.rb +0 -36
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 38ac640c7514d41f28205416b110496f5ddb14d2
|
4
|
+
data.tar.gz: 89b956912fee2b1b75e20c9f06986c33671a4b27
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1251675f9d073842dc030e0855161594a31807b80ef64b530d2b8a759b9c6bf075a3cb6eb330e108b19483dcb8fb5d50a19a7e0be7a5c777d55326c56577e767
|
7
|
+
data.tar.gz: a96b76e7742eda3aa9a07ce69f6dc6d6f9de1d6bed809a2b7fc2f165dc49c282214015c229f21e9a157024bc14a4c3a81b2edd596377cee93f7dad70527a0cde
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,21 @@
|
|
1
|
+
## 0.9.1
|
2
|
+
|
3
|
+
* Environment variables which were created during application startup are no
|
4
|
+
longer overwritten.
|
5
|
+
* Support for generating multiple binstubs at once. Use --all to
|
6
|
+
generate all, otherwise you can pass multiple command names to the
|
7
|
+
binstub command.
|
8
|
+
* The `testunit` command has been extracted to the
|
9
|
+
`spring-commands-testunit` gem, because it's not necessary in Rails 4,
|
10
|
+
where you can just run `rake test path/to/test`.
|
11
|
+
* The `~/.spring.rb` config file is loaded before bundler, so it's a good
|
12
|
+
place to require extra commands which you want to use in all projects,
|
13
|
+
without having to add those commands to the Gemfile of each individual
|
14
|
+
project.
|
15
|
+
* Any gems in the bundle with names which start with "spring-commands-"
|
16
|
+
are now autoloaded. This makes it less faffy to add additional
|
17
|
+
commands.
|
18
|
+
|
1
19
|
## 0.9.0
|
2
20
|
|
3
21
|
* Display spring version in the help message
|
data/README.md
CHANGED
@@ -40,7 +40,7 @@ For this walkthrough I've generated a new Rails application, and run
|
|
40
40
|
Let's run a test:
|
41
41
|
|
42
42
|
```
|
43
|
-
$ time spring
|
43
|
+
$ time spring rake test test/functional/posts_controller_test.rb
|
44
44
|
Run options:
|
45
45
|
|
46
46
|
# Running tests:
|
@@ -70,7 +70,7 @@ Spring is running:
|
|
70
70
|
The next run is faster:
|
71
71
|
|
72
72
|
```
|
73
|
-
$ time spring
|
73
|
+
$ time spring rake test test/functional/posts_controller_test.rb
|
74
74
|
Run options:
|
75
75
|
|
76
76
|
# Running tests:
|
@@ -89,12 +89,10 @@ sys 0m0.059s
|
|
89
89
|
Writing `spring` before every command gets a bit tedious. Spring binstubs solve this:
|
90
90
|
|
91
91
|
```
|
92
|
-
$ spring binstub
|
93
|
-
$ spring binstub rake
|
94
|
-
$ spring binstub rails
|
92
|
+
$ spring binstub rake rails
|
95
93
|
```
|
96
94
|
|
97
|
-
This will generate `bin/
|
95
|
+
This will generate `bin/rake` and `bin/rails`. They
|
98
96
|
replace any binstubs that you might already have in your `bin/`
|
99
97
|
directory. Check them in to source control.
|
100
98
|
|
@@ -168,16 +166,9 @@ You can also install the following gems for additional commands:
|
|
168
166
|
|
169
167
|
* [spring-commands-rspec](https://github.com/jonleighton/spring-commands-rspec)
|
170
168
|
* [spring-commands-cucumber](https://github.com/jonleighton/spring-commands-cucumber)
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
Runs a test (e.g. Test::Unit, MiniTest::Unit, etc.)
|
175
|
-
|
176
|
-
This command can also recursively run a directory of tests. For example,
|
177
|
-
`spring testunit test/functional` will run `test/functional/**/*_test.rb`.
|
178
|
-
|
179
|
-
If your test helper file takes a while to load, consider preloading it
|
180
|
-
(see "Running code before forking" below).
|
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.
|
181
172
|
|
182
173
|
### `rake`
|
183
174
|
|
@@ -205,7 +196,11 @@ speed-up).
|
|
205
196
|
|
206
197
|
## Configuration
|
207
198
|
|
208
|
-
Spring will read `~/.spring.rb` and `config/spring.rb` for custom
|
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. This means that in
|
202
|
+
`~/.spring.rb` you are able to load extra commands without them having
|
203
|
+
to be in the bundle of the project you are working on.
|
209
204
|
|
210
205
|
### Application root
|
211
206
|
|
data/lib/spring/application.rb
CHANGED
@@ -15,6 +15,7 @@ module Spring
|
|
15
15
|
@mutex = Mutex.new
|
16
16
|
@waiting = 0
|
17
17
|
@exiting = false
|
18
|
+
@env_keys = ENV.keys
|
18
19
|
|
19
20
|
# Workaround for GC bug in Ruby 2 which causes segfaults if watcher.to_io
|
20
21
|
# instances get dereffed.
|
@@ -46,12 +47,6 @@ module Spring
|
|
46
47
|
ActiveSupport::Dependencies.mechanism = :load
|
47
48
|
end
|
48
49
|
|
49
|
-
# Ensure eager loading does not take place, even though it usually would do
|
50
|
-
# in test mode with config.cache_classes = true. Eager loading in this situation
|
51
|
-
# just makes the initial run take longer without much gain in subsequent runs,
|
52
|
-
# at least in my testing.
|
53
|
-
Rails::Application::Finisher.initializers.delete_if { |i| i.name == :eager_load! }
|
54
|
-
|
55
50
|
require Spring.application_root_path.join("config", "environment")
|
56
51
|
|
57
52
|
Rails.application.config.cache_classes = false
|
@@ -113,7 +108,8 @@ module Spring
|
|
113
108
|
IGNORE_SIGNALS.each { |sig| trap(sig, "DEFAULT") }
|
114
109
|
|
115
110
|
ARGV.replace(args)
|
116
|
-
ENV.
|
111
|
+
@env_keys.each { |k| ENV.delete k }
|
112
|
+
ENV.update(env)
|
117
113
|
|
118
114
|
connect_database
|
119
115
|
srand
|
@@ -1,10 +1,10 @@
|
|
1
1
|
module Spring
|
2
2
|
module Client
|
3
3
|
class Binstub < Command
|
4
|
-
attr_reader :bindir, :
|
4
|
+
attr_reader :bindir, :commands
|
5
5
|
|
6
6
|
def self.description
|
7
|
-
"Generate spring based binstubs."
|
7
|
+
"Generate spring based binstubs. Use --all to generate a binstub for all known commands."
|
8
8
|
end
|
9
9
|
|
10
10
|
def self.call(args)
|
@@ -12,52 +12,65 @@ module Spring
|
|
12
12
|
super
|
13
13
|
end
|
14
14
|
|
15
|
+
class RailsCommand
|
16
|
+
def fallback
|
17
|
+
<<CODE
|
18
|
+
APP_PATH = File.expand_path('../../config/application', __FILE__)
|
19
|
+
require_relative '../config/boot'
|
20
|
+
require 'rails/commands'
|
21
|
+
CODE
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
15
25
|
def initialize(args)
|
16
26
|
super
|
17
27
|
|
18
|
-
@bindir
|
19
|
-
@
|
20
|
-
@command = Spring.commands[name]
|
28
|
+
@bindir = env.root.join("bin")
|
29
|
+
@commands = args.drop(1).inject({}) { |mem, name| mem.merge(find_commands(name)) }
|
21
30
|
end
|
22
31
|
|
23
|
-
def
|
24
|
-
|
25
|
-
|
26
|
-
|
32
|
+
def find_commands(name)
|
33
|
+
case name
|
34
|
+
when "--all"
|
35
|
+
commands = Spring.commands
|
36
|
+
commands.delete_if { |name, _| name.start_with?("rails_") }
|
37
|
+
commands["rails"] = RailsCommand.new
|
38
|
+
commands
|
39
|
+
when "rails"
|
40
|
+
{ name => RailsCommand.new }
|
27
41
|
else
|
28
|
-
|
29
|
-
|
42
|
+
if command = Spring.commands[name]
|
43
|
+
{ name => command }
|
44
|
+
else
|
45
|
+
$stderr.puts "The '#{name}' command is not known to spring."
|
46
|
+
exit 1
|
47
|
+
end
|
30
48
|
end
|
31
49
|
end
|
32
50
|
|
33
|
-
def
|
34
|
-
bindir.
|
51
|
+
def call
|
52
|
+
bindir.mkdir unless bindir.exist?
|
53
|
+
commands.each { |name, command| generate_binstub(name, command) }
|
35
54
|
end
|
36
55
|
|
37
|
-
def generate_binstub
|
38
|
-
File.write(
|
56
|
+
def generate_binstub(name, command)
|
57
|
+
File.write(bindir.join(name), <<CODE)
|
39
58
|
#!/usr/bin/env ruby
|
40
59
|
|
41
60
|
if !Process.respond_to?(:fork) || Gem::Specification.find_all_by_name("spring").empty?
|
42
|
-
#{fallback.strip.gsub(/^/, " ")}
|
61
|
+
#{fallback(name, command).strip.gsub(/^/, " ")}
|
43
62
|
else
|
44
63
|
ARGV.unshift "#{name}"
|
45
64
|
load Gem.bin_path("spring", "spring")
|
46
65
|
end
|
47
66
|
CODE
|
48
67
|
|
49
|
-
|
68
|
+
bindir.join(name).chmod 0755
|
50
69
|
end
|
51
70
|
|
52
|
-
def fallback
|
71
|
+
def fallback(name, command)
|
53
72
|
if command.respond_to?(:fallback)
|
54
73
|
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'
|
60
|
-
CODE
|
61
74
|
else
|
62
75
|
%{exec "bundle", "exec", "#{name}", *ARGV}
|
63
76
|
end
|
data/lib/spring/commands.rb
CHANGED
@@ -21,17 +21,20 @@ module Spring
|
|
21
21
|
|
22
22
|
require "spring/commands/rails"
|
23
23
|
require "spring/commands/rake"
|
24
|
-
require "spring/commands/testunit"
|
25
|
-
|
26
|
-
# If the config/spring.rb contains requires for commands from other gems,
|
27
|
-
# then we need to be under bundler.
|
28
|
-
require "bundler/setup"
|
29
24
|
|
30
25
|
# Load custom commands, if any.
|
31
26
|
# needs to be at the end to allow modification of existing commands.
|
32
27
|
config = File.expand_path("~/.spring.rb")
|
33
28
|
require config if File.exist?(config)
|
34
29
|
|
30
|
+
# If the config/spring.rb contains requires for commands from other gems,
|
31
|
+
# then we need to be under bundler.
|
32
|
+
require "bundler/setup"
|
33
|
+
|
34
|
+
Gem::Specification.map(&:name).grep(/^spring-commands-/).each do |command|
|
35
|
+
require command
|
36
|
+
end
|
37
|
+
|
35
38
|
config = File.expand_path("./config/spring.rb")
|
36
39
|
require config if File.exist?(config)
|
37
40
|
end
|
data/lib/spring/commands/rake.rb
CHANGED
data/lib/spring/version.rb
CHANGED
data/test/acceptance/app_test.rb
CHANGED
@@ -174,15 +174,13 @@ class AppTest < ActiveSupport::TestCase
|
|
174
174
|
end
|
175
175
|
|
176
176
|
def spring_test_command
|
177
|
-
"#{spring} testunit #{@test}"
|
177
|
+
"#{spring} #{rails_3? ? 'testunit' : 'rake test'} #{@test}"
|
178
178
|
end
|
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
|
-
|
184
182
|
assert system("(gem list rails --installed --version '#{rails_version}' || " \
|
185
|
-
"gem install rails --
|
183
|
+
"gem install rails --version '#{rails_version}') > /dev/null")
|
186
184
|
|
187
185
|
# Have to shell out otherwise bundler prevents us finding the gem
|
188
186
|
version = `ruby -e 'puts Gem::Specification.find_by_name("rails", "#{rails_version}").version'`.chomp
|
@@ -193,10 +191,12 @@ class AppTest < ActiveSupport::TestCase
|
|
193
191
|
FileUtils.mkdir_p(user_home)
|
194
192
|
FileUtils.rm_rf("#{app_root}/test/performance/")
|
195
193
|
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
194
|
+
if rails_3?
|
195
|
+
File.write(
|
196
|
+
"#{app_root}/Gemfile",
|
197
|
+
File.read("#{app_root}/Gemfile") + "gem 'spring-commands-testunit'\n"
|
198
|
+
)
|
199
|
+
end
|
200
200
|
end
|
201
201
|
end
|
202
202
|
|
@@ -373,11 +373,17 @@ class AppTest < ActiveSupport::TestCase
|
|
373
373
|
FileUtils.mv "#{app_root}/bin", "#{app_root}/bin~" if File.exist?("#{app_root}/bin")
|
374
374
|
|
375
375
|
app_run "#{spring} binstub rake"
|
376
|
-
app_run "#{spring} binstub rails"
|
377
|
-
|
378
376
|
assert_success "bin/rake -T", stdout: "rake db:migrate"
|
377
|
+
|
378
|
+
app_run "#{spring} binstub rake rails"
|
379
379
|
assert_success "bin/rails runner 'puts %(omg)'", stdout: "omg"
|
380
380
|
assert_success "bin/rails server --help", stdout: "Usage: rails server"
|
381
|
+
|
382
|
+
FileUtils.rm ["#{app_root}/bin/rails", "#{app_root}/bin/rake"]
|
383
|
+
|
384
|
+
app_run "#{spring} binstub --all"
|
385
|
+
assert_success "bin/rake -T", stdout: "rake db:migrate"
|
386
|
+
assert_success "bin/rails runner 'puts %(omg)'", stdout: "omg"
|
381
387
|
ensure
|
382
388
|
if File.exist?("#{app_root}/bin~")
|
383
389
|
FileUtils.rm_rf "#{app_root}/bin"
|
@@ -471,15 +477,25 @@ class AppTest < ActiveSupport::TestCase
|
|
471
477
|
end
|
472
478
|
|
473
479
|
test "changing the environment between runs" do
|
474
|
-
|
475
|
-
|
480
|
+
begin
|
481
|
+
application = "#{app_root}/config/application.rb"
|
482
|
+
application_contents = File.read(application)
|
483
|
+
|
484
|
+
File.write(application, "#{application_contents}\nENV['BAR'] = 'bar'")
|
476
485
|
|
477
|
-
|
486
|
+
env["OMG"] = "1"
|
487
|
+
env["FOO"] = "1"
|
478
488
|
|
479
|
-
|
480
|
-
|
489
|
+
assert_success %(#{spring} rails runner 'p ENV["OMG"]'), stdout: "1"
|
490
|
+
assert_success %(#{spring} rails runner 'p ENV["BAR"]'), stdout: "bar"
|
481
491
|
|
482
|
-
|
483
|
-
|
492
|
+
env["OMG"] = "2"
|
493
|
+
env.delete "FOO"
|
494
|
+
|
495
|
+
assert_success %(#{spring} rails runner 'p ENV["OMG"]'), stdout: "2"
|
496
|
+
assert_success %(#{spring} rails runner 'p ENV.key?("FOO")'), stdout: "false"
|
497
|
+
ensure
|
498
|
+
File.write(application, application_contents)
|
499
|
+
end
|
484
500
|
end
|
485
501
|
end
|
data/test/unit/commands_test.rb
CHANGED
@@ -32,7 +32,6 @@ class CommandsTest < ActiveSupport::TestCase
|
|
32
32
|
assert_nil command.env(["foo"])
|
33
33
|
assert_equal "test", command.env(["test"])
|
34
34
|
assert_equal "test", command.env(["test:models"])
|
35
|
-
assert_equal "test", command.env(["spec"])
|
36
35
|
assert_nil command.env(["test_foo"])
|
37
36
|
end
|
38
37
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: spring
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jon Leighton
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-11-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -67,7 +67,6 @@ files:
|
|
67
67
|
- lib/spring/commands.rb
|
68
68
|
- lib/spring/commands/rails.rb
|
69
69
|
- lib/spring/commands/rake.rb
|
70
|
-
- lib/spring/commands/testunit.rb
|
71
70
|
- lib/spring/configuration.rb
|
72
71
|
- lib/spring/env.rb
|
73
72
|
- lib/spring/errors.rb
|
@@ -1,36 +0,0 @@
|
|
1
|
-
module Spring
|
2
|
-
module Commands
|
3
|
-
class TestUnit
|
4
|
-
def env(*)
|
5
|
-
"test"
|
6
|
-
end
|
7
|
-
|
8
|
-
def call
|
9
|
-
$LOAD_PATH.unshift "test"
|
10
|
-
ARGV << "test" if ARGV.empty?
|
11
|
-
ARGV.each do |arg|
|
12
|
-
break if arg.start_with?("-")
|
13
|
-
require_test(File.expand_path(arg))
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
def require_test(path)
|
18
|
-
if File.directory?(path)
|
19
|
-
Dir[File.join path, "**", "*_test.rb"].each { |f| require f }
|
20
|
-
else
|
21
|
-
require path
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
def description
|
26
|
-
"Execute a Test::Unit test."
|
27
|
-
end
|
28
|
-
|
29
|
-
def fallback
|
30
|
-
%{exec "bundle", "exec", "ruby", "-Itest", *ARGV}
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
Spring.register_command "testunit", TestUnit.new
|
35
|
-
end
|
36
|
-
end
|