spring 1.3.6 → 1.4.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 53e40e388796f0694f931b786ba678246e64bb51
4
- data.tar.gz: fce7e7274cf3155517ca3f11411fb7f90d3ce1a6
3
+ metadata.gz: 6c37f7b4eddf6e88df7db145d63c44a92d7d166a
4
+ data.tar.gz: eee66fab5c0acb4c1b26a268cd544caeb01ab129
5
5
  SHA512:
6
- metadata.gz: ea9be374bc7b1dec0ada6cb6aec41990fb872e96272c0536562a1c884fdc93016bd3d3b2abed67d0bcd36af739419bd2332f2add3699d3944a5a8f6f2cb9e763
7
- data.tar.gz: f9f8ca0814f602e7ce30f05ee39e8c6d7313e38e1302c55d28ce30c10269974da5ca214709d4ec5c61df67053117aba92c066956c8c79bc92720363b61f0c1f4
6
+ metadata.gz: 0f402b076faef2f886e1b881732d1fa98e15ddb2652b72053755fa321bfe42a577a25adbf76529c5c6479ea3f098cbcb3515ecf9ae60e52dbe4c8b19f1048d4e
7
+ data.tar.gz: 2c48efd6d59b97147271a09689fef252f1ee379c5494a94faf8ef44b022761e751d02c37dc3f7acb59ec2ace1520cc64485d4ad0eb6db9f08da3028028db3113
data/README.md CHANGED
@@ -294,6 +294,9 @@ settings. Note that `~/.spring.rb` is loaded *before* bundler, but
294
294
  projects without having to be added to the project's Gemfile, require
295
295
  them in your `~/.spring.rb`.
296
296
 
297
+ `config/spring_client.rb` is also loaded before bundler and before a
298
+ server process is started, it can be used to add new top-level commands.
299
+
297
300
  ### Application root
298
301
 
299
302
  Spring must know how to find your Rails application. If you have a
data/bin/spring CHANGED
@@ -43,6 +43,7 @@ if defined?(Gem)
43
43
  end
44
44
  end
45
45
 
46
- $LOAD_PATH.unshift File.expand_path("../../lib", __FILE__)
46
+ lib = File.expand_path("../../lib", __FILE__)
47
+ $LOAD_PATH.unshift lib unless $LOAD_PATH.include?(lib) # enable local development
47
48
  require 'spring/client'
48
49
  Spring::Client.run(ARGV)
@@ -14,12 +14,14 @@ module Spring
14
14
  module Client
15
15
  COMMANDS = {
16
16
  "help" => Client::Help,
17
+ "-h" => Client::Help,
18
+ "--help" => Client::Help,
17
19
  "binstub" => Client::Binstub,
18
20
  "stop" => Client::Stop,
19
21
  "status" => Client::Status,
20
22
  "rails" => Client::Rails,
21
23
  "-v" => Client::Version,
22
- "--version" => Client::Version
24
+ "--version" => Client::Version,
23
25
  }
24
26
 
25
27
  def self.run(args)
@@ -36,3 +38,9 @@ module Spring
36
38
  end
37
39
  end
38
40
  end
41
+
42
+ # allow users to add hooks that do not run in the server
43
+ # or modify start/stop
44
+ if File.exist?("config/spring_client.rb")
45
+ require "./config/spring_client.rb"
46
+ end
@@ -36,7 +36,7 @@ unless defined?(Spring)
36
36
  require "rubygems"
37
37
  require "bundler"
38
38
 
39
- if match = Bundler.default_lockfile.read.match(/^GEM$.*?^ (?: )*spring \((.*?)\)$.*?^$/m)
39
+ if (match = Bundler.default_lockfile.read.match(/^GEM$.*?^ (?: )*spring \((.*?)\)$.*?^$/m))
40
40
  Gem.paths = { "GEM_PATH" => [Bundler.bundle_path.to_s, *Gem.path].uniq }
41
41
  gem "spring", match[1]
42
42
  require "spring/binstub"
@@ -1,9 +1,8 @@
1
- # encoding: utf-8
2
-
3
1
  require "io/wait"
4
2
  require "timeout"
5
3
  require "spring/sid"
6
4
  require "spring/client"
5
+ require "active_support/core_ext/string/strip"
7
6
 
8
7
  module Spring
9
8
  module Test
@@ -59,6 +58,14 @@ module Spring
59
58
  end
60
59
  end
61
60
 
61
+ def without_gem(name)
62
+ gem_home = app.gem_home.join('gems')
63
+ FileUtils.mv(gem_home.join(name), app.root)
64
+ yield
65
+ ensure
66
+ FileUtils.mv(app.root.join(name), gem_home)
67
+ end
68
+
62
69
  setup do
63
70
  generator.generate_if_missing
64
71
  generator.install_spring
@@ -77,6 +84,14 @@ module Spring
77
84
 
78
85
  test "help message when called without arguments" do
79
86
  assert_success "bin/spring", stdout: 'Usage: spring COMMAND [ARGS]'
87
+ assert app.spring_env.server_running?
88
+ end
89
+
90
+ test "shows help" do
91
+ assert_success "bin/spring help", stdout: 'Usage: spring COMMAND [ARGS]'
92
+ assert_success "bin/spring -h", stdout: 'Usage: spring COMMAND [ARGS]'
93
+ assert_success "bin/spring --help", stdout: 'Usage: spring COMMAND [ARGS]'
94
+ refute app.spring_env.server_running?
80
95
  end
81
96
 
82
97
  test "test changes are picked up" do
@@ -111,13 +126,13 @@ module Spring
111
126
  test "app gets reloaded when preloaded files change" do
112
127
  assert_success app.spring_test_command
113
128
 
114
- File.write(app.application_config, app.application_config.read + <<-CODE)
129
+ File.write(app.application_config, app.application_config.read + <<-RUBY.strip_heredoc)
115
130
  class Foo
116
131
  def self.omg
117
132
  raise "omg"
118
133
  end
119
134
  end
120
- CODE
135
+ RUBY
121
136
  File.write(app.test, app.test.read.sub("get :index", "Foo.omg"))
122
137
 
123
138
  app.await_reload
@@ -160,7 +175,7 @@ module Spring
160
175
  # Start spring before setting up the command, to test that it gracefully upgrades itself
161
176
  assert_success "bin/rails runner ''"
162
177
 
163
- File.write(app.spring_config, <<-CODE)
178
+ File.write(app.spring_config, <<-RUBY.strip_heredoc)
164
179
  class CustomCommand
165
180
  def call
166
181
  puts "omg"
@@ -172,7 +187,7 @@ module Spring
172
187
  end
173
188
 
174
189
  Spring.register_command "custom", CustomCommand.new
175
- CODE
190
+ RUBY
176
191
 
177
192
  assert_success "bin/spring custom", stdout: "omg"
178
193
 
@@ -194,52 +209,55 @@ module Spring
194
209
  end
195
210
 
196
211
  test "binstub when spring is uninstalled" do
197
- app.run! "gem uninstall --ignore-dependencies spring"
198
- File.write(app.gemfile, app.gemfile.read.gsub(/gem 'spring.*/, ""))
199
- assert_success "bin/rake -T", stdout: "rake db:migrate"
212
+ without_gem "spring-#{Spring::VERSION}" do
213
+ File.write(app.gemfile, app.gemfile.read.gsub(/gem 'spring.*/, ""))
214
+ assert_success "bin/rake -T", stdout: "rake db:migrate"
215
+ end
200
216
  end
201
217
 
202
218
  test "binstub upgrade" do
203
- File.write(app.path("bin/rake"), <<CODE)
204
- #!/usr/bin/env ruby
205
-
206
- if !Process.respond_to?(:fork) || Gem::Specification.find_all_by_name("spring").empty?
207
- exec "bundle", "exec", "rake", *ARGV
208
- else
209
- ARGV.unshift "rake"
210
- load Gem.bin_path("spring", "spring")
211
- end
212
- CODE
213
-
214
- File.write(app.path("bin/rails"), <<CODE)
215
- #!/usr/bin/env ruby
216
-
217
- if !Process.respond_to?(:fork) || Gem::Specification.find_all_by_name("spring").empty?
218
- APP_PATH = File.expand_path('../../config/application', __FILE__)
219
- require_relative '../config/boot'
220
- require 'rails/commands'
221
- else
222
- ARGV.unshift "rails"
223
- load Gem.bin_path("spring", "spring")
224
- end
225
- CODE
219
+ File.write(app.path("bin/rake"), <<-RUBY.strip_heredoc)
220
+ #!/usr/bin/env ruby
221
+
222
+ if !Process.respond_to?(:fork) || Gem::Specification.find_all_by_name("spring").empty?
223
+ exec "bundle", "exec", "rake", *ARGV
224
+ else
225
+ ARGV.unshift "rake"
226
+ load Gem.bin_path("spring", "spring")
227
+ end
228
+ RUBY
229
+
230
+ File.write(app.path("bin/rails"), <<-RUBY.strip_heredoc)
231
+ #!/usr/bin/env ruby
232
+
233
+ if !Process.respond_to?(:fork) || Gem::Specification.find_all_by_name("spring").empty?
234
+ APP_PATH = File.expand_path('../../config/application', __FILE__)
235
+ require_relative '../config/boot'
236
+ require 'rails/commands'
237
+ else
238
+ ARGV.unshift "rails"
239
+ load Gem.bin_path("spring", "spring")
240
+ end
241
+ RUBY
226
242
 
227
243
  assert_success "bin/spring binstub --all", stdout: "upgraded"
228
244
 
229
- assert_equal app.path("bin/rake").read, <<CODE
230
- #!/usr/bin/env ruby
231
- #{Spring::Client::Binstub::LOADER.strip}
232
- require 'bundler/setup'
233
- load Gem.bin_path('rake', 'rake')
234
- CODE
245
+ expected = <<-RUBY.gsub(/^ /, "")
246
+ #!/usr/bin/env ruby
247
+ #{Spring::Client::Binstub::LOADER.strip}
248
+ require 'bundler/setup'
249
+ load Gem.bin_path('rake', 'rake')
250
+ RUBY
251
+ assert_equal expected, app.path("bin/rake").read
235
252
 
236
- assert_equal app.path("bin/rails").read, <<CODE
237
- #!/usr/bin/env ruby
238
- #{Spring::Client::Binstub::LOADER.strip}
239
- APP_PATH = File.expand_path('../../config/application', __FILE__)
240
- require_relative '../config/boot'
241
- require 'rails/commands'
242
- CODE
253
+ expected = <<-RUBY.gsub(/^ /, "")
254
+ #!/usr/bin/env ruby
255
+ #{Spring::Client::Binstub::LOADER.strip}
256
+ APP_PATH = File.expand_path('../../config/application', __FILE__)
257
+ require_relative '../config/boot'
258
+ require 'rails/commands'
259
+ RUBY
260
+ assert_equal expected, app.path("bin/rails").read
243
261
  end
244
262
 
245
263
  test "after fork callback" do
@@ -252,6 +270,13 @@ CODE
252
270
  assert_success "bin/rails runner 'puts 2'", stdout: "!callback!\n2"
253
271
  end
254
272
 
273
+ test "can define client tasks" do
274
+ File.write("#{app.spring_config.sub('.rb', '_client.rb')}", <<-RUBY)
275
+ Spring::Client::COMMANDS["foo"] = lambda { |args| puts "bar -- \#{args.inspect}" }
276
+ RUBY
277
+ assert_success "bin/spring foo --baz", stdout: "bar -- [\"foo\", \"--baz\"]\n"
278
+ end
279
+
255
280
  test "missing config/application.rb" do
256
281
  app.application_config.delete
257
282
  assert_failure "bin/rake -T", stderr: "unable to find your config/application.rb"
@@ -278,17 +303,17 @@ CODE
278
303
  end
279
304
 
280
305
  test "setting env vars with rake" do
281
- File.write(app.path("lib/tasks/env.rake"), <<-'CODE')
306
+ File.write(app.path("lib/tasks/env.rake"), <<-RUBY.strip_heredoc)
282
307
  task :print_rails_env => :environment do
283
308
  puts Rails.env
284
309
  end
285
310
 
286
311
  task :print_env do
287
- ENV.each { |k, v| puts "#{k}=#{v}" }
312
+ ENV.each { |k, v| puts "\#{k}=\#{v}" }
288
313
  end
289
314
 
290
315
  task(:default).clear.enhance [:print_rails_env]
291
- CODE
316
+ RUBY
292
317
 
293
318
  assert_success "bin/rake RAILS_ENV=test print_rails_env", stdout: "test"
294
319
  assert_success "bin/rake FOO=bar print_env", stdout: "FOO=bar"
@@ -305,7 +330,7 @@ CODE
305
330
  end
306
331
 
307
332
  test "changing the Gemfile works when spring calls into itself" do
308
- File.write(app.path("script.rb"), <<-CODE)
333
+ File.write(app.path("script.rb"), <<-RUBY.strip_heredoc)
309
334
  gemfile = Rails.root.join("Gemfile")
310
335
  File.write(gemfile, "\#{gemfile.read}gem 'devise'\\n")
311
336
  Bundler.with_clean_env do
@@ -313,7 +338,7 @@ CODE
313
338
  end
314
339
  output = `\#{Rails.root.join('bin/rails')} runner 'require "devise"; puts "done";'`
315
340
  exit output == "done\n"
316
- CODE
341
+ RUBY
317
342
 
318
343
  assert_success [%(bin/rails runner 'load Rails.root.join("script.rb")'), timeout: 60]
319
344
  end
@@ -48,7 +48,7 @@ module Spring
48
48
  end
49
49
 
50
50
  def gem_home
51
- path "vendor/gems/#{RUBY_VERSION}"
51
+ path "../gems/#{RUBY_VERSION}"
52
52
  end
53
53
 
54
54
  def user_home
@@ -52,19 +52,32 @@ module Spring
52
52
  FileUtils.mkdir_p(application.user_home)
53
53
  FileUtils.rm_rf(application.path("test/performance"))
54
54
 
55
- File.write(application.gemfile, "#{application.gemfile.read}gem 'spring', '#{Spring::VERSION}'\n")
55
+ append_to_file(application.gemfile, "gem 'spring', '#{Spring::VERSION}'")
56
56
 
57
57
  if version.needs_testunit?
58
- File.write(application.gemfile, "#{application.gemfile.read}gem 'spring-commands-testunit'\n")
58
+ append_to_file(application.gemfile, "gem 'spring-commands-testunit'")
59
+ end
60
+
61
+ rewrite_file(application.gemfile) do |c|
62
+ c.sub!("https://rubygems.org", "http://rubygems.org")
63
+ c.gsub!(/(gem '(byebug|web-console|sdoc|jbuilder)')/, "# \\1")
64
+ c
59
65
  end
60
66
 
61
- File.write(application.gemfile, application.gemfile.read.sub("https://rubygems.org", "http://rubygems.org"))
62
67
 
63
68
  if application.path("bin").exist?
64
69
  FileUtils.cp_r(application.path("bin"), application.path("bin_original"))
65
70
  end
66
71
  end
67
72
 
73
+ def rewrite_file(file)
74
+ File.write(file, yield(file.read))
75
+ end
76
+
77
+ def append_to_file(file, add)
78
+ rewrite_file(file) { |c| c << "#{add}\n" }
79
+ end
80
+
68
81
  def generate_if_missing
69
82
  generate unless application.exists?
70
83
  end
@@ -1,3 +1,3 @@
1
1
  module Spring
2
- VERSION = "1.3.6"
2
+ VERSION = "1.4.0"
3
3
  end
@@ -25,6 +25,6 @@ module Spring
25
25
  end
26
26
 
27
27
  def self.watch(*items)
28
- watcher.add *items
28
+ watcher.add(*items)
29
29
  end
30
30
  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: 1.3.6
4
+ version: 1.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jon Leighton
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-05-08 00:00:00.000000000 Z
11
+ date: 2015-09-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -38,7 +38,22 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
- description: Rails application preloader
41
+ - !ruby/object:Gem::Dependency
42
+ name: bump
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: Preloads your application so things like console, rake and tests run
56
+ faster
42
57
  email:
43
58
  - j@jonathanleighton.com
44
59
  executables:
@@ -84,7 +99,7 @@ files:
84
99
  - lib/spring/watcher.rb
85
100
  - lib/spring/watcher/abstract.rb
86
101
  - lib/spring/watcher/polling.rb
87
- homepage: http://github.com/rails/spring
102
+ homepage: https://github.com/rails/spring
88
103
  licenses:
89
104
  - MIT
90
105
  metadata: {}
@@ -104,9 +119,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
104
119
  version: '0'
105
120
  requirements: []
106
121
  rubyforge_project:
107
- rubygems_version: 2.4.5
122
+ rubygems_version: 2.2.2
108
123
  signing_key:
109
124
  specification_version: 4
110
125
  summary: Rails application preloader
111
126
  test_files: []
112
- has_rdoc: