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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0824c6fabd2c8830c1a610f25821f746367cee6f
4
- data.tar.gz: 108cf6e1bd07af03dfbfe9078727315eab78b39e
3
+ metadata.gz: 38ac640c7514d41f28205416b110496f5ddb14d2
4
+ data.tar.gz: 89b956912fee2b1b75e20c9f06986c33671a4b27
5
5
  SHA512:
6
- metadata.gz: c2ca57a02be596e85692d0b8e75f60bc28278f99d82bd5352e5f9ef283c49720b75cca34101061e897f692923d83e030d57da6796e90611c68c01dd3bf688813
7
- data.tar.gz: ec4654a54e32ea00418c230ed1c159d6cc628309bb025292c109458140c5b6c41212106004c2b3c2546fc53b81027a3f70b3a58d8b1ad5d695afbad6c43c2f8b
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 testunit test/functional/posts_controller_test.rb
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 testunit test/functional/posts_controller_test.rb
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 testunit
93
- $ spring binstub rake
94
- $ spring binstub rails
92
+ $ spring binstub rake rails
95
93
  ```
96
94
 
97
- This will generate `bin/testunit`, `bin/rake` and `bin/rails`. They
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
- ### `testunit`
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 settings, described below.
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
 
@@ -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.replace(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, :name, :command
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 = env.root.join("bin")
19
- @name = args[1]
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 call
24
- if command || name == "rails"
25
- bindir.mkdir unless bindir.exist?
26
- generate_binstub
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
- $stderr.puts "The '#{name}' command is not known to spring."
29
- exit 1
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 binstub
34
- bindir.join(name)
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(binstub, <<CODE)
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
- binstub.chmod 0755
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
@@ -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
@@ -6,8 +6,8 @@ module Spring
6
6
  end
7
7
 
8
8
  self.environment_matchers = {
9
- :default => "test",
10
- /^(test|spec|cucumber)($|:)/ => "test"
9
+ :default => "test",
10
+ /^test($|:)/ => "test"
11
11
  }
12
12
 
13
13
  def env(args)
@@ -1,3 +1,3 @@
1
1
  module Spring
2
- VERSION = "0.9.0"
2
+ VERSION = "0.9.1"
3
3
  end
@@ -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 --clear-sources --source http://rubygems.org --version '#{rails_version}') > /dev/null")
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
- File.write(
197
- "#{app_root}/Gemfile",
198
- File.read("#{app_root}/Gemfile").sub("https://rubygems.org", "http://rubygems.org")
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
- env["OMG"] = "1"
475
- env["FOO"] = "1"
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
- assert_success %(#{spring} rails runner 'p ENV["OMG"]'), stdout: "1"
486
+ env["OMG"] = "1"
487
+ env["FOO"] = "1"
478
488
 
479
- env["OMG"] = "2"
480
- env.delete "FOO"
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
- assert_success %(#{spring} rails runner 'p ENV["OMG"]'), stdout: "2"
483
- assert_success %(#{spring} rails runner 'p ENV.key?("FOO")'), stdout: "false"
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
@@ -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.0
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-10-27 00:00:00.000000000 Z
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