Roman2K-rails-test-serving 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/Manifest +6 -0
- data/README.rdoc +33 -5
- data/Rakefile +1 -1
- data/lib/rails_test_serving.rb +60 -4
- data/rails-test-serving.gemspec +28 -64
- data/test/rails_test_serving_test.rb +82 -0
- metadata +5 -4
data/Manifest
ADDED
data/README.rdoc
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
Tired of waiting 10 seconds before your tests run? RailsTestServing can make them run almost instantly.
|
1
|
+
Tired of waiting 10 seconds before your tests run? RailsTestServing can make them run almost instantly.
|
2
2
|
|
3
|
-
==
|
3
|
+
== Usage
|
4
4
|
|
5
5
|
1. Install the gem:
|
6
6
|
gem install Roman2K-rails-test-serving -v '>= 0.1.1' -s http://gems.github.com
|
@@ -10,8 +10,12 @@ Tired of waiting 10 seconds before your tests run? RailsTestServing can make the
|
|
10
10
|
require 'rails_test_serving'
|
11
11
|
RailsTestServing.boot
|
12
12
|
|
13
|
-
3. Append the following line to <tt>~/.
|
14
|
-
export RUBYLIB="test:$RUBYLIB"
|
13
|
+
3. Append the following line to <tt>~/.bash_profile</tt>:
|
14
|
+
export RUBYLIB=".:test:$RUBYLIB"
|
15
|
+
|
16
|
+
If you get loading errors during the next steps:
|
17
|
+
* Move the +RUBYLIB+ line from <tt>~/.bash_profile</tt> to <tt>~/.bash_login</tt> instead.
|
18
|
+
* If you are using TextMate, you may try to apply {this (hopefully temporary) fix}[http://roman.flucti.com/textmate-fix-for-relative-require-test_helper].
|
15
19
|
|
16
20
|
4. Start the server:
|
17
21
|
cd <project-dir>
|
@@ -22,8 +26,24 @@ Tired of waiting 10 seconds before your tests run? RailsTestServing can make the
|
|
22
26
|
ruby test/unit/account_test.rb -n /balance/
|
23
27
|
As a consequence, they work in RubyMate too (⌘R in TextMate).
|
24
28
|
|
29
|
+
6. Details in the {introduction article}[http://roman.flucti.com/a-test-server-for-rails-applications].
|
30
|
+
|
25
31
|
<b>Note:</b> if the server is not started, tests fall back to running the usual way.
|
26
32
|
|
33
|
+
== Options
|
34
|
+
|
35
|
+
An option hash can be specified for RailsTestServing to use, by defining <tt>$test_server_options</tt> right before <tt>require 'rails_test_serving'</tt>. It must be a hash with symbol keys. Currently available options are:
|
36
|
+
+reload+:: An array of regular expressions (or any object responding to <tt>#===</tt>) matching the name of the files that should be forced to reload right after the regular constant cleanup. Note that the constants these files have defined are not removed before the new +require+.
|
37
|
+
|
38
|
+
Example <tt>test_helper.rb</tt> head:
|
39
|
+
require 'rubygems'
|
40
|
+
|
41
|
+
$test_server_options = { :reload => [/blueprint/] }
|
42
|
+
require 'rails_test_serving'
|
43
|
+
RailsTestServing.boot
|
44
|
+
|
45
|
+
# ...remainder here...
|
46
|
+
|
27
47
|
== Caveats
|
28
48
|
|
29
49
|
* Tested working with Rails 2.1.2 up to 2.2.0 RC2. Compatibility with versions of Rails out of that range is guaranteed.
|
@@ -32,4 +52,12 @@ Tired of waiting 10 seconds before your tests run? RailsTestServing can make the
|
|
32
52
|
|
33
53
|
== Credits
|
34
54
|
|
35
|
-
|
55
|
+
Code:
|
56
|
+
* {Roman Le Négrate}[http://roman.flucti.com], a.k.a. Roman2K ({contact}[mailto:roman.lenegrate@gmail.com])
|
57
|
+
* {Jack Chen}[http://github.com/chendo], a.k.a. chendo
|
58
|
+
|
59
|
+
Feedback:
|
60
|
+
* Justin Ko
|
61
|
+
* {Dr Nic Williams}[http://drnicwilliams.com]
|
62
|
+
|
63
|
+
Released under the MIT license: see the +LICENSE+ file.
|
data/Rakefile
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'echoe'
|
2
2
|
|
3
|
-
Echoe.new('rails-test-serving', '0.1.
|
3
|
+
Echoe.new('rails-test-serving', '0.1.2') do |p|
|
4
4
|
p.description = "Makes unit tests of a Rails application run instantly"
|
5
5
|
p.url = "https://github.com/Roman2K/rails-test-serving"
|
6
6
|
p.author = "Roman Le Négrate"
|
data/lib/rails_test_serving.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'pathname'
|
1
2
|
require 'thread'
|
2
3
|
require 'test/unit'
|
3
4
|
require 'drb/unix'
|
@@ -10,7 +11,31 @@ module RailsTestServing
|
|
10
11
|
class ServerUnavailable < StandardError
|
11
12
|
end
|
12
13
|
|
13
|
-
|
14
|
+
SOCKET_PATH = ['tmp', 'sockets', 'test_server.sock']
|
15
|
+
|
16
|
+
def self.service_uri
|
17
|
+
@service_uri ||= begin
|
18
|
+
# Determine RAILS_ROOT
|
19
|
+
root, max_depth = Pathname('.'), Pathname.pwd.expand_path.to_s.split(File::SEPARATOR).size
|
20
|
+
until root.join('config', 'boot.rb').file?
|
21
|
+
root = root.parent
|
22
|
+
if root.to_s.split(File::SEPARATOR).size >= max_depth
|
23
|
+
raise "RAILS_ROOT could not be determined"
|
24
|
+
end
|
25
|
+
end
|
26
|
+
root = root.cleanpath
|
27
|
+
|
28
|
+
# Adjust load path
|
29
|
+
$: << root << root.join('test')
|
30
|
+
|
31
|
+
# Ensure socket directory exists
|
32
|
+
path = root.join(*SOCKET_PATH)
|
33
|
+
path.dirname.mkpath
|
34
|
+
|
35
|
+
# URI
|
36
|
+
"drbunix:#{path}"
|
37
|
+
end
|
38
|
+
end
|
14
39
|
|
15
40
|
def self.boot(argv=ARGV)
|
16
41
|
if argv.delete('--serve')
|
@@ -20,6 +45,14 @@ module RailsTestServing
|
|
20
45
|
end
|
21
46
|
end
|
22
47
|
|
48
|
+
def self.options
|
49
|
+
@options ||= begin
|
50
|
+
options = $test_server_options || {}
|
51
|
+
options[:reload] ||= []
|
52
|
+
options
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
23
56
|
module ConstantManagement
|
24
57
|
extend self
|
25
58
|
|
@@ -80,7 +113,7 @@ module RailsTestServing
|
|
80
113
|
|
81
114
|
def run_tests!
|
82
115
|
handle_process_lifecycle do
|
83
|
-
server = DRbObject.new_with_uri(
|
116
|
+
server = DRbObject.new_with_uri(RailsTestServing.service_uri)
|
84
117
|
begin
|
85
118
|
puts(server.run($0, ARGV))
|
86
119
|
rescue DRb::DRbConnError
|
@@ -106,7 +139,7 @@ module RailsTestServing
|
|
106
139
|
GUARD = Mutex.new
|
107
140
|
|
108
141
|
def self.start
|
109
|
-
DRb.start_service(
|
142
|
+
DRb.start_service(RailsTestServing.service_uri, Server.new)
|
110
143
|
DRb.thread.join
|
111
144
|
end
|
112
145
|
|
@@ -115,7 +148,6 @@ module RailsTestServing
|
|
115
148
|
enable_dependency_tracking
|
116
149
|
start_cleaner
|
117
150
|
load_framework
|
118
|
-
|
119
151
|
log "** Test server started (##{$$})\n"
|
120
152
|
end
|
121
153
|
|
@@ -130,6 +162,7 @@ module RailsTestServing
|
|
130
162
|
$stdout.flush
|
131
163
|
end
|
132
164
|
|
165
|
+
# TODO clean this up, making 'path' a Pathname instead of a String
|
133
166
|
def shorten_path(path)
|
134
167
|
shortenable, base = File.expand_path(path), File.expand_path(Dir.pwd)
|
135
168
|
attempt = shortenable.sub(/^#{Regexp.escape base + File::SEPARATOR}/, '')
|
@@ -339,6 +372,12 @@ module RailsTestServing
|
|
339
372
|
|
340
373
|
def clean_up_app
|
341
374
|
ActionController::Dispatcher.new(StringIO.new).cleanup_application
|
375
|
+
|
376
|
+
# Reload files that match :reload here instead of in reload_app since the
|
377
|
+
# :reload option is intended to target files that don't change between two
|
378
|
+
# consecutive runs (an external library for example). That way, they are
|
379
|
+
# reloaded in the background instead of slowing down the next run.
|
380
|
+
reload_specified_source_files
|
342
381
|
end
|
343
382
|
|
344
383
|
def remove_tests
|
@@ -349,7 +388,24 @@ module RailsTestServing
|
|
349
388
|
end
|
350
389
|
|
351
390
|
def reload_app
|
391
|
+
reload_specified_source_files
|
352
392
|
ActionController::Dispatcher.new(StringIO.new).reload_application
|
353
393
|
end
|
394
|
+
|
395
|
+
def reload_specified_source_files
|
396
|
+
to_reload =
|
397
|
+
$".select do |path|
|
398
|
+
RailsTestServing.options[:reload].any? do |matcher|
|
399
|
+
matcher === path
|
400
|
+
end
|
401
|
+
end
|
402
|
+
|
403
|
+
# Force a reload by removing matched files from $"
|
404
|
+
$".replace($" - to_reload)
|
405
|
+
|
406
|
+
to_reload.each do |file|
|
407
|
+
require file.split('.').first # remove extension, most likely '.rb'
|
408
|
+
end
|
409
|
+
end
|
354
410
|
end
|
355
411
|
end unless defined? RailsTestServing
|
data/rails-test-serving.gemspec
CHANGED
@@ -1,68 +1,32 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
1
2
|
|
2
|
-
|
3
|
-
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = %q{rails-test-serving}
|
5
|
+
s.version = "0.1.2"
|
4
6
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
7
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
8
|
+
s.authors = ["Roman Le N\303\251grate"]
|
9
|
+
s.date = %q{2008-11-18}
|
10
|
+
s.description = %q{Makes unit tests of a Rails application run instantly}
|
11
|
+
s.email = %q{roman.lenegrate@gmail.com}
|
12
|
+
s.extra_rdoc_files = ["lib/rails_test_serving.rb", "LICENSE", "README.rdoc"]
|
13
|
+
s.files = ["lib/rails_test_serving.rb", "LICENSE", "Rakefile", "README.rdoc", "test/rails_test_serving_test.rb", "Manifest", "rails-test-serving.gemspec"]
|
14
|
+
s.has_rdoc = true
|
15
|
+
s.homepage = %q{https://github.com/Roman2K/rails-test-serving}
|
16
|
+
s.rdoc_options = ["--main", "README.rdoc", "--inline-source", "--line-numbers", "--charset", "UTF-8"]
|
17
|
+
s.require_paths = ["lib"]
|
18
|
+
s.rubyforge_project = %q{rails-test-serving}
|
19
|
+
s.rubygems_version = %q{1.3.1}
|
20
|
+
s.summary = %q{Makes unit tests of a Rails application run instantly}
|
21
|
+
s.test_files = ["test/rails_test_serving_test.rb"]
|
14
22
|
|
15
|
-
|
16
|
-
|
17
|
-
|
23
|
+
if s.respond_to? :specification_version then
|
24
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
25
|
+
s.specification_version = 2
|
18
26
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
extra_rdoc_files:
|
26
|
-
- lib/rails_test_serving.rb
|
27
|
-
- LICENSE
|
28
|
-
- README.rdoc
|
29
|
-
files:
|
30
|
-
- lib/rails_test_serving.rb
|
31
|
-
- LICENSE
|
32
|
-
- Manifest
|
33
|
-
- Rakefile
|
34
|
-
- README.rdoc
|
35
|
-
- test/rails_test_serving_test.rb
|
36
|
-
- rails-test-serving.gemspec
|
37
|
-
has_rdoc: true
|
38
|
-
homepage: https://github.com/Roman2K/rails-test-serving
|
39
|
-
post_install_message:
|
40
|
-
rdoc_options:
|
41
|
-
- --main
|
42
|
-
- README.rdoc
|
43
|
-
- --inline-source
|
44
|
-
- --line-numbers
|
45
|
-
- --charset
|
46
|
-
- UTF-8
|
47
|
-
require_paths:
|
48
|
-
- lib
|
49
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
50
|
-
requirements:
|
51
|
-
- - ">="
|
52
|
-
- !ruby/object:Gem::Version
|
53
|
-
version: "0"
|
54
|
-
version:
|
55
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
56
|
-
requirements:
|
57
|
-
- - ">="
|
58
|
-
- !ruby/object:Gem::Version
|
59
|
-
version: "1.2"
|
60
|
-
version:
|
61
|
-
requirements: []
|
62
|
-
|
63
|
-
rubyforge_project: rails-test-serving
|
64
|
-
rubygems_version: 1.3.1
|
65
|
-
specification_version: 2
|
66
|
-
summary: Makes unit tests of a Rails application run instantly
|
67
|
-
test_files:
|
68
|
-
- test/rails_test_serving_test.rb
|
27
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
28
|
+
else
|
29
|
+
end
|
30
|
+
else
|
31
|
+
end
|
32
|
+
end
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'rubygems'
|
2
|
+
|
2
3
|
require 'test/unit'
|
3
4
|
require 'mocha'
|
4
5
|
Mocha::Configuration.prevent :stubbing_non_existent_method
|
@@ -11,6 +12,34 @@ class RailsTestServingTest < Test::Unit::TestCase
|
|
11
12
|
|
12
13
|
# class
|
13
14
|
|
15
|
+
def test_service_uri
|
16
|
+
# RAILS_ROOT is the current directory
|
17
|
+
setup_service_uri_test do
|
18
|
+
FileTest.expects(:file?).with("config/boot.rb").returns true
|
19
|
+
FileUtils.expects(:mkpath).with("tmp/sockets")
|
20
|
+
assert_equal "drbunix:tmp/sockets/test_server.sock", RailsTestServing.service_uri
|
21
|
+
end
|
22
|
+
|
23
|
+
# RAILS_ROOT is in the parent directory
|
24
|
+
setup_service_uri_test do
|
25
|
+
FileTest.stubs(:file?).with("config/boot.rb").returns false
|
26
|
+
FileTest.stubs(:file?).with("../config/boot.rb").returns true
|
27
|
+
FileUtils.expects(:mkpath).with("../tmp/sockets")
|
28
|
+
assert_equal "drbunix:../tmp/sockets/test_server.sock", RailsTestServing.service_uri
|
29
|
+
end
|
30
|
+
|
31
|
+
# RAILS_ROOT cannot be determined
|
32
|
+
setup_service_uri_test do
|
33
|
+
Pathname.stubs(:pwd).returns(Pathname("/foo/bar"))
|
34
|
+
FileTest.expects(:file?).with("config/boot.rb").returns false
|
35
|
+
FileTest.expects(:file?).with("../config/boot.rb").returns false
|
36
|
+
FileTest.expects(:file?).with("../../config/boot.rb").returns false
|
37
|
+
FileTest.expects(:file?).with("../../../config/boot.rb").never
|
38
|
+
FileUtils.expects(:mkpath).never
|
39
|
+
assert_raise(RuntimeError) { RailsTestServing.service_uri }
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
14
43
|
def test_boot
|
15
44
|
argv = []
|
16
45
|
Client.expects(:run_tests)
|
@@ -26,6 +55,18 @@ class RailsTestServingTest < Test::Unit::TestCase
|
|
26
55
|
RailsTestServing.boot(argv)
|
27
56
|
assert_equal [], argv
|
28
57
|
end
|
58
|
+
|
59
|
+
private
|
60
|
+
|
61
|
+
def setup_service_uri_test(wont_mkpath=false)
|
62
|
+
old_load_path = $:.dup
|
63
|
+
begin
|
64
|
+
return yield
|
65
|
+
ensure
|
66
|
+
RailsTestServing.instance_variable_set(:@service_uri, nil)
|
67
|
+
$:.replace(old_load_path)
|
68
|
+
end
|
69
|
+
end
|
29
70
|
end
|
30
71
|
|
31
72
|
class RailsTestServing::ConstantManagementTest < Test::Unit::TestCase
|
@@ -210,3 +251,44 @@ private
|
|
210
251
|
S.new
|
211
252
|
end
|
212
253
|
end
|
254
|
+
|
255
|
+
class RailsTestServing::CleanerTest < Test::Unit::TestCase
|
256
|
+
include RailsTestServing
|
257
|
+
|
258
|
+
# private
|
259
|
+
|
260
|
+
def test_reload_specified_source_files
|
261
|
+
Cleaner.any_instance.stubs(:start_worker)
|
262
|
+
|
263
|
+
# Empty :reload option
|
264
|
+
preserve_features do
|
265
|
+
$".replace ["foo.rb"]
|
266
|
+
RailsTestServing.stubs(:options).returns({:reload => []})
|
267
|
+
|
268
|
+
Cleaner.any_instance.expects(:require).never
|
269
|
+
Cleaner.new.instance_eval { reload_specified_source_files }
|
270
|
+
assert_equal ["foo.rb"], $"
|
271
|
+
end
|
272
|
+
|
273
|
+
# :reload option contains regular expressions
|
274
|
+
preserve_features do
|
275
|
+
$".replace ["foo.rb", "bar.rb"]
|
276
|
+
RailsTestServing.stubs(:options).returns({:reload => [/foo/]})
|
277
|
+
|
278
|
+
Cleaner.any_instance.expects(:require).with("foo").once
|
279
|
+
Cleaner.new.instance_eval { reload_specified_source_files }
|
280
|
+
assert_equal ["bar.rb"], $"
|
281
|
+
end
|
282
|
+
end
|
283
|
+
|
284
|
+
private
|
285
|
+
|
286
|
+
def preserve_features
|
287
|
+
old = $".dup
|
288
|
+
begin
|
289
|
+
return yield
|
290
|
+
ensure
|
291
|
+
$".replace(old)
|
292
|
+
end
|
293
|
+
end
|
294
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: Roman2K-rails-test-serving
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- "Roman Le N\xC3\xA9grate"
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
|
-
cert_chain:
|
11
|
-
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2008-11-18 00:00:00 -08:00
|
12
13
|
default_executable:
|
13
14
|
dependencies: []
|
14
15
|
|
@@ -25,10 +26,10 @@ extra_rdoc_files:
|
|
25
26
|
files:
|
26
27
|
- lib/rails_test_serving.rb
|
27
28
|
- LICENSE
|
28
|
-
- Manifest
|
29
29
|
- Rakefile
|
30
30
|
- README.rdoc
|
31
31
|
- test/rails_test_serving_test.rb
|
32
|
+
- Manifest
|
32
33
|
- rails-test-serving.gemspec
|
33
34
|
has_rdoc: true
|
34
35
|
homepage: https://github.com/Roman2K/rails-test-serving
|