spring 0.0.9 → 0.0.10
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +27 -0
- data/Gemfile +0 -2
- data/README.md +35 -40
- data/bin/spring +7 -3
- data/lib/spring/application.rb +25 -4
- data/lib/spring/client.rb +2 -2
- data/lib/spring/client/help.rb +2 -0
- data/lib/spring/client/run.rb +10 -4
- data/lib/spring/commands.rb +8 -215
- data/lib/spring/commands/cucumber.rb +15 -0
- data/lib/spring/commands/rails.rb +53 -0
- data/lib/spring/commands/rake.rb +26 -0
- data/lib/spring/commands/rspec.rb +15 -0
- data/lib/spring/commands/testunit.rb +32 -0
- data/lib/spring/configuration.rb +5 -1
- data/lib/spring/env.rb +0 -1
- data/lib/spring/json.rb +621 -0
- data/lib/spring/server.rb +8 -6
- data/lib/spring/version.rb +1 -1
- data/lib/spring/watcher.rb +16 -11
- data/lib/spring/watcher/abstract.rb +2 -0
- data/lib/spring/watcher/listen.rb +5 -14
- data/test/acceptance/app_test.rb +18 -9
- data/test/apps/rails-3-2/Gemfile +1 -4
- data/test/apps/rails-3-2/config/spring.rb +1 -1
- data/test/unit/commands_test.rb +0 -35
- data/test/unit/watcher_test.rb +7 -2
- metadata +8 -3
- data/lib/spring/client/start.rb +0 -17
data/lib/spring/server.rb
CHANGED
@@ -4,6 +4,7 @@ require "thread"
|
|
4
4
|
require "spring/env"
|
5
5
|
require "spring/application_manager"
|
6
6
|
require "spring/process_title_updater"
|
7
|
+
require "spring/json"
|
7
8
|
|
8
9
|
# Must be last, as it requires bundler/setup
|
9
10
|
require "spring/commands"
|
@@ -43,13 +44,14 @@ module Spring
|
|
43
44
|
def serve(client)
|
44
45
|
client.puts env.version
|
45
46
|
|
46
|
-
app_client
|
47
|
-
command
|
48
|
-
|
47
|
+
app_client = client.recv_io
|
48
|
+
command = JSON.load(client.read(client.gets.to_i))
|
49
|
+
|
50
|
+
args, default_rails_env = command.values_at('args', 'default_rails_env')
|
49
51
|
|
50
52
|
if Spring.command?(args.first)
|
51
53
|
client.puts
|
52
|
-
client.puts @applications[rails_env_for(args,
|
54
|
+
client.puts @applications[rails_env_for(args, default_rails_env)].run(app_client)
|
53
55
|
else
|
54
56
|
client.close
|
55
57
|
end
|
@@ -57,14 +59,14 @@ module Spring
|
|
57
59
|
raise e unless client.eof?
|
58
60
|
end
|
59
61
|
|
60
|
-
def rails_env_for(args,
|
62
|
+
def rails_env_for(args, default_rails_env)
|
61
63
|
command = Spring.command(args.first)
|
62
64
|
|
63
65
|
if command.respond_to?(:env)
|
64
66
|
env = command.env(args.drop(1))
|
65
67
|
end
|
66
68
|
|
67
|
-
env ||
|
69
|
+
env || default_rails_env
|
68
70
|
end
|
69
71
|
|
70
72
|
# Boot the server into the process group of the current session.
|
data/lib/spring/version.rb
CHANGED
data/lib/spring/watcher.rb
CHANGED
@@ -1,25 +1,30 @@
|
|
1
1
|
require "spring/watcher/abstract"
|
2
|
-
require "spring/watcher/listen"
|
3
|
-
require "spring/watcher/polling"
|
4
2
|
|
5
3
|
module Spring
|
6
4
|
class << self
|
7
5
|
attr_accessor :watch_interval
|
8
6
|
attr_writer :watcher
|
7
|
+
attr_reader :watch_method
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.watch_method=(method)
|
11
|
+
case method
|
12
|
+
when :polling
|
13
|
+
require_relative "watcher/polling"
|
14
|
+
@watch_method = Watcher::Polling
|
15
|
+
when :listen
|
16
|
+
require_relative "watcher/listen"
|
17
|
+
@watch_method = Watcher::Listen
|
18
|
+
else
|
19
|
+
@watch_method = method
|
20
|
+
end
|
9
21
|
end
|
10
22
|
|
11
23
|
self.watch_interval = 0.2
|
24
|
+
self.watch_method = :polling
|
12
25
|
|
13
26
|
def self.watcher
|
14
|
-
@watcher ||=
|
15
|
-
end
|
16
|
-
|
17
|
-
def self.watcher_class
|
18
|
-
if Watcher::Listen.available?
|
19
|
-
Watcher::Listen
|
20
|
-
else
|
21
|
-
Watcher::Polling
|
22
|
-
end
|
27
|
+
@watcher ||= watch_method.new(Spring.application_root_path, watch_interval)
|
23
28
|
end
|
24
29
|
|
25
30
|
def self.watch(*items)
|
@@ -1,27 +1,18 @@
|
|
1
|
+
gem "listen", "~> 1.0"
|
2
|
+
require "listen"
|
3
|
+
require "listen/version"
|
4
|
+
|
1
5
|
module Spring
|
2
6
|
module Watcher
|
3
7
|
class Listen < Abstract
|
4
8
|
attr_reader :listener
|
5
9
|
|
6
|
-
def self.available?
|
7
|
-
require "listen"
|
8
|
-
require "listen/version"
|
9
|
-
true
|
10
|
-
rescue LoadError
|
11
|
-
false
|
12
|
-
end
|
13
|
-
|
14
10
|
def start
|
15
11
|
unless @listener
|
16
12
|
@listener = ::Listen.to(*base_directories, relative_paths: false)
|
17
13
|
@listener.latency(latency)
|
18
14
|
@listener.change(&method(:changed))
|
19
|
-
|
20
|
-
if ::Listen::VERSION >= "1.0.0"
|
21
|
-
@listener.start
|
22
|
-
else
|
23
|
-
@listener.start(false)
|
24
|
-
end
|
15
|
+
@listener.start
|
25
16
|
end
|
26
17
|
end
|
27
18
|
|
data/test/acceptance/app_test.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# encoding: utf-8
|
1
2
|
require 'helper'
|
2
3
|
require 'io/wait'
|
3
4
|
require "timeout"
|
@@ -6,6 +7,9 @@ require "spring/env"
|
|
6
7
|
require "pty"
|
7
8
|
|
8
9
|
class AppTest < ActiveSupport::TestCase
|
10
|
+
# Runtimes on the CI tend to be a bit more volatile, so make
|
11
|
+
# the ratio more permissive
|
12
|
+
DEFAULT_SPEEDUP = ENV['CI'] ? 0.8 : 0.6
|
9
13
|
DEFAULT_TIMEOUT = ENV['CI'] ? 30 : 10
|
10
14
|
|
11
15
|
def app_root
|
@@ -114,7 +118,7 @@ class AppTest < ActiveSupport::TestCase
|
|
114
118
|
assert_output artifacts, expected_output if expected_output
|
115
119
|
end
|
116
120
|
|
117
|
-
def assert_speedup(ratio =
|
121
|
+
def assert_speedup(ratio = DEFAULT_SPEEDUP)
|
118
122
|
@times = []
|
119
123
|
yield
|
120
124
|
assert (@times.last / @times.first) < ratio, "#{@times.last} was not less than #{ratio} of #{@times.first}"
|
@@ -233,11 +237,17 @@ class AppTest < ActiveSupport::TestCase
|
|
233
237
|
gemfile = app_root.join("Gemfile")
|
234
238
|
gemfile_contents = gemfile.read
|
235
239
|
File.write(gemfile, gemfile_contents.sub(%{# gem 'listen'}, %{gem 'listen'}))
|
240
|
+
|
241
|
+
config_path = "#{app_root}/config/spring.rb"
|
242
|
+
config_contents = File.read(config_path)
|
243
|
+
File.write(config_path,config_contents + "\nSpring.watch_method = :listen")
|
244
|
+
|
236
245
|
app_run "bundle install", timeout: nil
|
237
246
|
|
238
247
|
assert_success "#{spring} rails runner 'puts Spring.watcher.class'", stdout: "Listen"
|
239
248
|
assert_app_reloaded
|
240
249
|
ensure
|
250
|
+
File.write(config_path,config_contents)
|
241
251
|
File.write(gemfile, gemfile_contents)
|
242
252
|
assert_success "bundle check"
|
243
253
|
end
|
@@ -316,9 +326,13 @@ class AppTest < ActiveSupport::TestCase
|
|
316
326
|
end
|
317
327
|
|
318
328
|
test "runner command sets Rails environment from command-line options" do
|
319
|
-
|
320
|
-
assert_success "#{spring} rails runner
|
321
|
-
|
329
|
+
assert_success "#{spring} rails runner -e production 'puts Rails.env'", stdout: "production"
|
330
|
+
assert_success "#{spring} rails runner --environment=production 'puts Rails.env'", stdout: "production"
|
331
|
+
end
|
332
|
+
|
333
|
+
test "forcing rails env via environment variable" do
|
334
|
+
env['RAILS_ENV'] = 'production'
|
335
|
+
assert_success "#{spring} rake -p 'Rails.env'", stdout: "production"
|
322
336
|
end
|
323
337
|
|
324
338
|
test "exit code for failing specs" do
|
@@ -327,11 +341,6 @@ class AppTest < ActiveSupport::TestCase
|
|
327
341
|
assert_failure "#{spring} rspec"
|
328
342
|
end
|
329
343
|
|
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
344
|
test "changing the Gemfile restarts the server" do
|
336
345
|
begin
|
337
346
|
gemfile = app_root.join("Gemfile")
|
data/test/apps/rails-3-2/Gemfile
CHANGED
data/test/unit/commands_test.rb
CHANGED
@@ -2,41 +2,6 @@ require "helper"
|
|
2
2
|
require "spring/commands"
|
3
3
|
|
4
4
|
class CommandsTest < ActiveSupport::TestCase
|
5
|
-
test 'children of Command have inheritable accessor named "preload"' do
|
6
|
-
command1, command2 = 2.times.map { Class.new(Spring::Commands::Command) }
|
7
|
-
|
8
|
-
command1.preloads << "foo"
|
9
|
-
assert_equal ["foo"], command1.preloads
|
10
|
-
assert_equal [], command2.preloads
|
11
|
-
|
12
|
-
command2.preloads << "bar"
|
13
|
-
assert_equal ["foo"], command1.preloads
|
14
|
-
assert_equal ["bar"], command2.preloads
|
15
|
-
|
16
|
-
command1.preloads = ["omg"]
|
17
|
-
assert_equal ["omg"], command1.preloads
|
18
|
-
assert_equal ["bar"], command2.preloads
|
19
|
-
|
20
|
-
command3 = Class.new(command1)
|
21
|
-
command3.preloads << "foo"
|
22
|
-
assert_equal ["omg", "foo"], command3.preloads
|
23
|
-
assert_equal ["omg"], command1.preloads
|
24
|
-
end
|
25
|
-
|
26
|
-
test "prints error message when preloaded file does not exist" do
|
27
|
-
begin
|
28
|
-
original_stderr = $stderr
|
29
|
-
$stderr = StringIO.new('')
|
30
|
-
my_command_class = Class.new(Spring::Commands::Command)
|
31
|
-
my_command_class.preloads = %w(i_do_not_exist)
|
32
|
-
|
33
|
-
my_command_class.new.setup
|
34
|
-
assert_match /The #<Class:0x[0-9a-f]+> command tried to preload i_do_not_exist but could not find it./, $stderr.string
|
35
|
-
ensure
|
36
|
-
$stderr = original_stderr
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
5
|
test 'console command sets rails environment from command-line option' do
|
41
6
|
command = Spring::Commands::RailsConsole.new
|
42
7
|
assert_equal 'test', command.env(['test'])
|
data/test/unit/watcher_test.rb
CHANGED
@@ -3,8 +3,8 @@ require "tmpdir"
|
|
3
3
|
require "fileutils"
|
4
4
|
require "active_support/core_ext/numeric/time"
|
5
5
|
require "spring/watcher"
|
6
|
-
|
7
|
-
|
6
|
+
require "spring/watcher/polling"
|
7
|
+
require "spring/watcher/listen"
|
8
8
|
|
9
9
|
module WatcherTests
|
10
10
|
LATENCY = 0.001
|
@@ -135,6 +135,11 @@ module WatcherTests
|
|
135
135
|
watcher.add "./foo"
|
136
136
|
assert_equal ["#{dir}/foo"], watcher.files.to_a
|
137
137
|
end
|
138
|
+
|
139
|
+
def test_add_non_existant_file
|
140
|
+
watcher.add './foobar'
|
141
|
+
assert watcher.files.empty?
|
142
|
+
end
|
138
143
|
end
|
139
144
|
|
140
145
|
class ListenWatcherTest < ActiveSupport::TestCase
|
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.10
|
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-06-
|
12
|
+
date: 2013-06-21 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|
@@ -67,13 +67,18 @@ files:
|
|
67
67
|
- lib/spring/client/help.rb
|
68
68
|
- lib/spring/client/rails.rb
|
69
69
|
- lib/spring/client/run.rb
|
70
|
-
- lib/spring/client/start.rb
|
71
70
|
- lib/spring/client/status.rb
|
72
71
|
- lib/spring/client/stop.rb
|
73
72
|
- lib/spring/commands.rb
|
73
|
+
- lib/spring/commands/cucumber.rb
|
74
|
+
- lib/spring/commands/rails.rb
|
75
|
+
- lib/spring/commands/rake.rb
|
76
|
+
- lib/spring/commands/rspec.rb
|
77
|
+
- lib/spring/commands/testunit.rb
|
74
78
|
- lib/spring/configuration.rb
|
75
79
|
- lib/spring/env.rb
|
76
80
|
- lib/spring/errors.rb
|
81
|
+
- lib/spring/json.rb
|
77
82
|
- lib/spring/process_title_updater.rb
|
78
83
|
- lib/spring/server.rb
|
79
84
|
- lib/spring/sid.rb
|
data/lib/spring/client/start.rb
DELETED
@@ -1,17 +0,0 @@
|
|
1
|
-
module Spring
|
2
|
-
module Client
|
3
|
-
class Start < Command
|
4
|
-
def self.description
|
5
|
-
"Boot the spring server (this happens automatically when you run a command)"
|
6
|
-
end
|
7
|
-
|
8
|
-
def call
|
9
|
-
# Require spring/server before bundler so that it doesn't have to be in
|
10
|
-
# the bundle
|
11
|
-
require "spring/server"
|
12
|
-
require "bundler/setup"
|
13
|
-
Spring::Server.boot
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|