spring 0.0.7 → 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +11 -0
- data/Gemfile +4 -0
- data/README.md +49 -24
- data/lib/spring/application.rb +30 -30
- data/lib/spring/application_manager.rb +34 -15
- data/lib/spring/client.rb +9 -7
- data/lib/spring/client/binstub.rb +8 -3
- data/lib/spring/client/help.rb +20 -32
- data/lib/spring/client/rails.rb +29 -0
- data/lib/spring/client/run.rb +55 -51
- data/lib/spring/client/start.rb +17 -0
- data/lib/spring/client/status.rb +1 -1
- data/lib/spring/client/stop.rb +1 -1
- data/lib/spring/commands.rb +36 -20
- data/lib/spring/errors.rb +3 -0
- data/lib/spring/server.rb +36 -12
- data/lib/spring/version.rb +1 -1
- data/lib/spring/watcher.rb +28 -0
- data/lib/spring/watcher/abstract.rb +83 -0
- data/lib/spring/watcher/listen.rb +54 -0
- data/lib/spring/watcher/polling.rb +59 -0
- data/test/acceptance/app_test.rb +62 -32
- data/test/apps/rails-3-2/Gemfile +5 -0
- data/test/unit/client/help_test.rb +27 -19
- data/test/unit/commands_test.rb +26 -1
- data/test/unit/watcher_test.rb +171 -0
- metadata +12 -6
- data/lib/spring/application_watcher.rb +0 -43
- data/test/unit/application_watcher_test.rb +0 -67
data/test/unit/commands_test.rb
CHANGED
@@ -7,7 +7,7 @@ class CommandsTest < ActiveSupport::TestCase
|
|
7
7
|
real_stderr = $stderr
|
8
8
|
$stderr = StringIO.new('')
|
9
9
|
|
10
|
-
command = Spring::Commands::
|
10
|
+
command = Spring::Commands::TestUnit.new
|
11
11
|
command.call([])
|
12
12
|
|
13
13
|
assert_equal "you need to specify what test to run: spring test TEST_NAME\n", $stderr.string
|
@@ -50,4 +50,29 @@ class CommandsTest < ActiveSupport::TestCase
|
|
50
50
|
$stderr = original_stderr
|
51
51
|
end
|
52
52
|
end
|
53
|
+
|
54
|
+
test 'console command sets rails environment from command-line option' do
|
55
|
+
command = Spring::Commands::RailsConsole.new
|
56
|
+
assert_equal 'test', command.env(['test'])
|
57
|
+
end
|
58
|
+
|
59
|
+
test 'console command ignores first argument if it is a flag' do
|
60
|
+
command = Spring::Commands::RailsConsole.new
|
61
|
+
assert_nil command.env(['--sandbox'])
|
62
|
+
end
|
63
|
+
|
64
|
+
test 'Runner#env sets rails environment from command-line option' do
|
65
|
+
command = Spring::Commands::RailsRunner.new
|
66
|
+
assert_equal 'test', command.env(['-e', 'test', 'puts 1+1'])
|
67
|
+
end
|
68
|
+
|
69
|
+
test 'RailsRunner#env sets rails environment from long form of command-line option' do
|
70
|
+
command = Spring::Commands::RailsRunner.new
|
71
|
+
assert_equal 'test', command.env(['--environment=test', 'puts 1+1'])
|
72
|
+
end
|
73
|
+
|
74
|
+
test 'RailsRunner#env ignores insignificant arguments' do
|
75
|
+
command = Spring::Commands::RailsRunner.new
|
76
|
+
assert_nil command.env(['puts 1+1'])
|
77
|
+
end
|
53
78
|
end
|
@@ -0,0 +1,171 @@
|
|
1
|
+
require "helper"
|
2
|
+
require "tmpdir"
|
3
|
+
require "fileutils"
|
4
|
+
require "active_support/core_ext/numeric/time"
|
5
|
+
require "spring/watcher"
|
6
|
+
require "listen"
|
7
|
+
|
8
|
+
module WatcherTests
|
9
|
+
LATENCY = 0.001
|
10
|
+
TIMEOUT = 1
|
11
|
+
|
12
|
+
attr_accessor :dir
|
13
|
+
|
14
|
+
def watcher
|
15
|
+
@watcher ||= watcher_class.new(dir, LATENCY)
|
16
|
+
end
|
17
|
+
|
18
|
+
def setup
|
19
|
+
@dir = File.realpath(Dir.mktmpdir)
|
20
|
+
end
|
21
|
+
|
22
|
+
def teardown
|
23
|
+
FileUtils.remove_entry_secure @dir
|
24
|
+
watcher.stop
|
25
|
+
end
|
26
|
+
|
27
|
+
def touch(file, mtime = nil)
|
28
|
+
options = {}
|
29
|
+
options[:mtime] = mtime if mtime
|
30
|
+
FileUtils.touch(file, options)
|
31
|
+
end
|
32
|
+
|
33
|
+
def assert_stale
|
34
|
+
timeout = Time.now + TIMEOUT
|
35
|
+
sleep LATENCY until watcher.stale? || Time.now > timeout
|
36
|
+
assert watcher.stale?
|
37
|
+
end
|
38
|
+
|
39
|
+
def assert_not_stale
|
40
|
+
sleep LATENCY * 10
|
41
|
+
assert !watcher.stale?
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_is_stale_when_a_watched_file_is_updated
|
45
|
+
file = "#{@dir}/omg"
|
46
|
+
touch file, Time.now - 2.seconds
|
47
|
+
|
48
|
+
watcher.add file
|
49
|
+
watcher.start
|
50
|
+
|
51
|
+
assert_not_stale
|
52
|
+
touch file, Time.now
|
53
|
+
assert_stale
|
54
|
+
end
|
55
|
+
|
56
|
+
def test_is_stale_when_removing_files
|
57
|
+
file = "#{@dir}/omg"
|
58
|
+
touch file, Time.now
|
59
|
+
|
60
|
+
watcher.add file
|
61
|
+
watcher.start
|
62
|
+
|
63
|
+
assert_not_stale
|
64
|
+
FileUtils.rm(file)
|
65
|
+
assert_stale
|
66
|
+
end
|
67
|
+
|
68
|
+
def test_is_stale_when_files_are_added_to_a_watched_directory
|
69
|
+
subdir = "#{@dir}/subdir"
|
70
|
+
FileUtils.mkdir(subdir)
|
71
|
+
|
72
|
+
watcher.add subdir
|
73
|
+
watcher.start
|
74
|
+
|
75
|
+
assert_not_stale
|
76
|
+
touch "#{subdir}/foo", Time.now - 1.minute
|
77
|
+
assert_stale
|
78
|
+
end
|
79
|
+
|
80
|
+
def test_is_stale_when_a_file_is_changed_in_a_watched_directory
|
81
|
+
subdir = "#{@dir}/subdir"
|
82
|
+
FileUtils.mkdir(subdir)
|
83
|
+
touch "#{subdir}/foo", Time.now - 1.minute
|
84
|
+
|
85
|
+
watcher.add subdir
|
86
|
+
watcher.start
|
87
|
+
|
88
|
+
assert_not_stale
|
89
|
+
touch "#{subdir}/foo", Time.now
|
90
|
+
assert_stale
|
91
|
+
end
|
92
|
+
|
93
|
+
def test_adding_doesnt_wipe_stale_state
|
94
|
+
file = "#{@dir}/omg"
|
95
|
+
file2 = "#{@dir}/foo"
|
96
|
+
touch file, Time.now - 2.seconds
|
97
|
+
touch file2, Time.now - 2.seconds
|
98
|
+
|
99
|
+
watcher.add file
|
100
|
+
watcher.start
|
101
|
+
|
102
|
+
assert_not_stale
|
103
|
+
|
104
|
+
touch file, Time.now
|
105
|
+
watcher.add file2
|
106
|
+
|
107
|
+
assert_stale
|
108
|
+
end
|
109
|
+
|
110
|
+
def test_can_io_select
|
111
|
+
file = "#{@dir}/omg"
|
112
|
+
touch file, Time.now - 2.seconds
|
113
|
+
|
114
|
+
watcher.add file
|
115
|
+
watcher.start
|
116
|
+
|
117
|
+
Thread.new {
|
118
|
+
sleep LATENCY * 3
|
119
|
+
touch file, Time.now
|
120
|
+
}
|
121
|
+
|
122
|
+
assert IO.select([watcher], [], [], 1), "IO.select timed out before watcher was readable"
|
123
|
+
assert watcher.stale?
|
124
|
+
end
|
125
|
+
|
126
|
+
def test_add_relative_path
|
127
|
+
File.write("#{dir}/foo", "foo")
|
128
|
+
watcher.add "foo"
|
129
|
+
assert_equal ["#{dir}/foo"], watcher.files.to_a
|
130
|
+
end
|
131
|
+
|
132
|
+
def test_add_dot_relative_path
|
133
|
+
File.write("#{dir}/foo", "foo")
|
134
|
+
watcher.add "./foo"
|
135
|
+
assert_equal ["#{dir}/foo"], watcher.files.to_a
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
class ListenWatcherTest < ActiveSupport::TestCase
|
140
|
+
include WatcherTests
|
141
|
+
|
142
|
+
def watcher_class
|
143
|
+
Spring::Watcher::Listen
|
144
|
+
end
|
145
|
+
|
146
|
+
test "root directories" do
|
147
|
+
begin
|
148
|
+
other_dir_1 = File.realpath(Dir.mktmpdir)
|
149
|
+
other_dir_2 = File.realpath(Dir.mktmpdir)
|
150
|
+
File.write("#{other_dir_1}/foo", "foo")
|
151
|
+
File.write("#{dir}/foo", "foo")
|
152
|
+
|
153
|
+
watcher.add "#{other_dir_1}/foo"
|
154
|
+
watcher.add other_dir_2
|
155
|
+
watcher.add "#{dir}/foo"
|
156
|
+
|
157
|
+
assert_equal [dir, other_dir_1, other_dir_2].sort, watcher.base_directories.sort
|
158
|
+
ensure
|
159
|
+
FileUtils.rmdir other_dir_1
|
160
|
+
FileUtils.rmdir other_dir_2
|
161
|
+
end
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
165
|
+
class PollingWatcherTest < ActiveSupport::TestCase
|
166
|
+
include WatcherTests
|
167
|
+
|
168
|
+
def watcher_class
|
169
|
+
Spring::Watcher::Polling
|
170
|
+
end
|
171
|
+
end
|
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.8
|
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-03-22 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|
@@ -53,6 +53,7 @@ extra_rdoc_files: []
|
|
53
53
|
files:
|
54
54
|
- .gitignore
|
55
55
|
- .travis.yml
|
56
|
+
- CHANGELOG.md
|
56
57
|
- Gemfile
|
57
58
|
- LICENSE.txt
|
58
59
|
- README.md
|
@@ -60,12 +61,13 @@ files:
|
|
60
61
|
- bin/spring
|
61
62
|
- lib/spring/application.rb
|
62
63
|
- lib/spring/application_manager.rb
|
63
|
-
- lib/spring/application_watcher.rb
|
64
64
|
- lib/spring/client.rb
|
65
65
|
- lib/spring/client/binstub.rb
|
66
66
|
- lib/spring/client/command.rb
|
67
67
|
- lib/spring/client/help.rb
|
68
|
+
- lib/spring/client/rails.rb
|
68
69
|
- lib/spring/client/run.rb
|
70
|
+
- lib/spring/client/start.rb
|
69
71
|
- lib/spring/client/status.rb
|
70
72
|
- lib/spring/client/stop.rb
|
71
73
|
- lib/spring/commands.rb
|
@@ -76,6 +78,10 @@ files:
|
|
76
78
|
- lib/spring/server.rb
|
77
79
|
- lib/spring/sid.rb
|
78
80
|
- lib/spring/version.rb
|
81
|
+
- lib/spring/watcher.rb
|
82
|
+
- lib/spring/watcher/abstract.rb
|
83
|
+
- lib/spring/watcher/listen.rb
|
84
|
+
- lib/spring/watcher/polling.rb
|
79
85
|
- spring.gemspec
|
80
86
|
- test/acceptance/app_test.rb
|
81
87
|
- test/apps/rails-3-2/.gitignore
|
@@ -145,10 +151,10 @@ files:
|
|
145
151
|
- test/apps/rails-3-2/vendor/assets/stylesheets/.gitkeep
|
146
152
|
- test/apps/rails-3-2/vendor/plugins/.gitkeep
|
147
153
|
- test/helper.rb
|
148
|
-
- test/unit/application_watcher_test.rb
|
149
154
|
- test/unit/client/help_test.rb
|
150
155
|
- test/unit/commands_test.rb
|
151
156
|
- test/unit/process_title_updater_test.rb
|
157
|
+
- test/unit/watcher_test.rb
|
152
158
|
homepage: http://github.com/jonleighton/spring
|
153
159
|
licenses: []
|
154
160
|
post_install_message:
|
@@ -169,7 +175,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
169
175
|
version: '0'
|
170
176
|
requirements: []
|
171
177
|
rubyforge_project:
|
172
|
-
rubygems_version: 1.8.
|
178
|
+
rubygems_version: 1.8.24
|
173
179
|
signing_key:
|
174
180
|
specification_version: 3
|
175
181
|
summary: Rails application preloader
|
@@ -242,7 +248,7 @@ test_files:
|
|
242
248
|
- test/apps/rails-3-2/vendor/assets/stylesheets/.gitkeep
|
243
249
|
- test/apps/rails-3-2/vendor/plugins/.gitkeep
|
244
250
|
- test/helper.rb
|
245
|
-
- test/unit/application_watcher_test.rb
|
246
251
|
- test/unit/client/help_test.rb
|
247
252
|
- test/unit/commands_test.rb
|
248
253
|
- test/unit/process_title_updater_test.rb
|
254
|
+
- test/unit/watcher_test.rb
|
@@ -1,43 +0,0 @@
|
|
1
|
-
module Spring
|
2
|
-
class ApplicationWatcher
|
3
|
-
attr_reader :mtime, :files, :globs
|
4
|
-
|
5
|
-
def initialize
|
6
|
-
@files = []
|
7
|
-
@globs = []
|
8
|
-
@mtime = nil
|
9
|
-
end
|
10
|
-
|
11
|
-
def add_files(new_files)
|
12
|
-
files.concat new_files.select { |f| File.exist?(f) }
|
13
|
-
files.uniq!
|
14
|
-
reset
|
15
|
-
end
|
16
|
-
|
17
|
-
def add_globs(new_globs)
|
18
|
-
globs.concat new_globs
|
19
|
-
reset
|
20
|
-
end
|
21
|
-
|
22
|
-
def reset
|
23
|
-
@mtime = compute_mtime
|
24
|
-
end
|
25
|
-
|
26
|
-
def stale?
|
27
|
-
mtime < compute_mtime
|
28
|
-
end
|
29
|
-
|
30
|
-
private
|
31
|
-
|
32
|
-
def compute_mtime
|
33
|
-
expanded_files.map { |f| File.mtime(f).to_f }.max || 0
|
34
|
-
rescue Errno::ENOENT
|
35
|
-
# if a file does no longer exist, the watcher is always stale.
|
36
|
-
Float::MAX
|
37
|
-
end
|
38
|
-
|
39
|
-
def expanded_files
|
40
|
-
files + Dir["{#{globs.join(",")}}"]
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
@@ -1,67 +0,0 @@
|
|
1
|
-
require "helper"
|
2
|
-
require "fileutils"
|
3
|
-
require "active_support/core_ext/numeric/time"
|
4
|
-
require "spring/application_watcher"
|
5
|
-
|
6
|
-
class ApplicationWatcherTest < ActiveSupport::TestCase
|
7
|
-
def setup
|
8
|
-
@dir = "/tmp/spring"
|
9
|
-
FileUtils.mkdir(@dir)
|
10
|
-
end
|
11
|
-
|
12
|
-
def teardown
|
13
|
-
FileUtils.rm_r(@dir)
|
14
|
-
end
|
15
|
-
|
16
|
-
def touch(file, mtime = nil)
|
17
|
-
options = {}
|
18
|
-
options[:mtime] = mtime if mtime
|
19
|
-
FileUtils.touch(file, options)
|
20
|
-
end
|
21
|
-
|
22
|
-
test "file mtime" do
|
23
|
-
file = "#{@dir}/omg"
|
24
|
-
touch file, Time.now - 2.seconds
|
25
|
-
|
26
|
-
watcher = Spring::ApplicationWatcher.new
|
27
|
-
watcher.add_files [file]
|
28
|
-
|
29
|
-
assert !watcher.stale?
|
30
|
-
touch file, Time.now
|
31
|
-
assert watcher.stale?
|
32
|
-
end
|
33
|
-
|
34
|
-
test "tolerates enoent" do
|
35
|
-
file = "#{@dir}/omg"
|
36
|
-
touch file
|
37
|
-
|
38
|
-
watcher = Spring::ApplicationWatcher.new
|
39
|
-
watcher.add_files [file]
|
40
|
-
|
41
|
-
assert !watcher.stale?
|
42
|
-
FileUtils.rm(file)
|
43
|
-
assert watcher.stale?
|
44
|
-
end
|
45
|
-
|
46
|
-
test "accepts glob patterns" do
|
47
|
-
FileUtils.mkdir("#{@dir}/1")
|
48
|
-
FileUtils.mkdir("#{@dir}/2")
|
49
|
-
|
50
|
-
watcher = Spring::ApplicationWatcher.new
|
51
|
-
watcher.add_globs ["#{@dir}/1/*.rb", "#{@dir}/2/*"]
|
52
|
-
|
53
|
-
assert !watcher.stale?
|
54
|
-
|
55
|
-
touch "#{@dir}/1/foo", Time.now - 1.minute
|
56
|
-
assert !watcher.stale?
|
57
|
-
|
58
|
-
touch "#{@dir}/1/foo.rb", 2.seconds
|
59
|
-
assert watcher.stale?
|
60
|
-
|
61
|
-
watcher.reset
|
62
|
-
assert !watcher.stale?
|
63
|
-
|
64
|
-
touch "#{@dir}/2/foo", Time.now
|
65
|
-
assert watcher.stale?
|
66
|
-
end
|
67
|
-
end
|