sauron 0.1.8 → 0.1.10
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.
- data/VERSION +1 -1
- data/generators/sauron/sauron_generator.rb +10 -2
- data/generators/sauron/templates/config/hydra.yml +1 -1
- data/generators/sauron/templates/config/sauron.yml +2 -0
- data/generators/sauron/templates/lib/sauron/watchr.rb +3 -86
- data/generators/sauron/templates/lib/tasks/sauron.rake +2 -1
- data/generators/sauron/templates/sauron_watchr.rb +30 -11
- data/generators/sauron/templates/{sauron → script/sauron} +0 -0
- data/lib/sauron/sauron_template.rb +146 -0
- data/lib/sauron.rb +3 -0
- data/sauron.gemspec +5 -3
- metadata +7 -5
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.10
|
@@ -2,12 +2,18 @@ class SauronGenerator < Rails::Generator::Base
|
|
2
2
|
def manifest
|
3
3
|
options[:runners] ||= 4
|
4
4
|
|
5
|
+
options[:rspec] ||= false
|
6
|
+
options[:testunit] ||= false
|
7
|
+
|
8
|
+
options[:framework] = options[:rspec] ? 'rspec' : 'testunit'
|
9
|
+
|
5
10
|
record do |m|
|
6
11
|
m.file 'sauron_watchr.rb', 'sauron_watchr.rb'
|
7
12
|
m.file 'test_helper.rb', 'test_helper.rb'
|
8
|
-
m.file 'sauron', 'sauron', :chmod => 0755
|
13
|
+
m.file 'script/sauron', 'script/sauron', :chmod => 0755
|
9
14
|
|
10
|
-
m.
|
15
|
+
m.file 'config/hydra.yml', 'config/hydra.yml'
|
16
|
+
m.template 'config/sauron.yml', 'config/sauron.yml'
|
11
17
|
|
12
18
|
m.directory 'lib/sauron'
|
13
19
|
m.file 'lib/sauron/watchr.rb', 'lib/sauron/watchr.rb'
|
@@ -21,5 +27,7 @@ class SauronGenerator < Rails::Generator::Base
|
|
21
27
|
|
22
28
|
def add_options!(opt)
|
23
29
|
opt.on('--runners='){|v| options[:runners] = v}
|
30
|
+
opt.on('--rspec'){|v| options[:rspec] = v}
|
31
|
+
opt.on('--testunit'){|v| options[:testunit] = v}
|
24
32
|
end
|
25
33
|
end
|
@@ -1,91 +1,8 @@
|
|
1
|
-
require '
|
2
|
-
|
3
|
-
def set_hydra
|
4
|
-
$hydra = !!(`rake -T` =~ /rake hydra:sauron\s+/)
|
5
|
-
end
|
6
|
-
|
7
|
-
def run_routing_tests
|
8
|
-
message "running routing tests"
|
9
|
-
run_multiple_tests routing_tests
|
10
|
-
end
|
11
|
-
|
12
|
-
def run_single_test file
|
13
|
-
message "running #{file}"
|
14
|
-
system "time ruby -I.:lib:test -rubygems -e \"require '#{file}'\""
|
15
|
-
end
|
16
|
-
|
17
|
-
def run_multiple_tests *files
|
18
|
-
joined_files = files.join(',')
|
19
|
-
|
20
|
-
message "running #{files.first.size} tests: #{joined_files}"
|
21
|
-
|
22
|
-
if $hydra
|
23
|
-
system "time rake hydra:sauron RAILS_ENV=test FILE_LIST=#{joined_files}"
|
24
|
-
else
|
25
|
-
system "time ruby -I.:lib:test -rubygems -e \"%w[#{files.join(' ')}].each {|f| require f}\""
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
def run_all_tests
|
30
|
-
message "running all tests"
|
31
|
-
run_multiple_tests all_tests
|
32
|
-
end
|
33
|
-
|
34
|
-
def unit_tests
|
35
|
-
Dir.glob('test/unit/*_test.rb')
|
36
|
-
end
|
37
|
-
|
38
|
-
def helper_tests
|
39
|
-
Dir.glob('test/unit/helpers/*_test.rb')
|
40
|
-
end
|
41
|
-
|
42
|
-
def functional_tests
|
43
|
-
Dir.glob('test/functional/*_test.rb')
|
44
|
-
end
|
45
|
-
|
46
|
-
def routing_tests
|
47
|
-
Dir.glob('test/unit/rout{es,ing}_test.rb')
|
48
|
-
end
|
49
|
-
|
50
|
-
def all_tests
|
51
|
-
Dir.glob('test/**/*_test.rb')
|
52
|
-
end
|
53
|
-
|
54
|
-
def message body
|
55
|
-
system 'clear'
|
56
|
-
puts body
|
57
|
-
end
|
58
|
-
|
59
|
-
def setup_databases
|
60
|
-
# Find the number of runners #
|
61
|
-
runners = 0
|
62
|
-
hydra_yaml = YAML.load_file('config/hydra.yml')
|
63
|
-
hydra_yaml['workers'].each do |worker|
|
64
|
-
runners = worker['runners'] if worker['runners'] > runners && worker['type'] == 'local'
|
65
|
-
end
|
66
|
-
|
67
|
-
print "setting up #{runners} databases (you can change in config/hydra.yml)"
|
68
|
-
STDOUT.flush
|
69
|
-
|
70
|
-
# setup each database #
|
71
|
-
runners.times do |i|
|
72
|
-
print '.'
|
73
|
-
STDOUT.flush
|
74
|
-
|
75
|
-
i = '' if i == 0
|
76
|
-
`rake db:reset RAILS_ENV=test TEST_ENV_NUMBER=#{i}`
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
def startup
|
81
|
-
set_hydra
|
82
|
-
setup_databases
|
83
|
-
run_all_tests
|
84
|
-
end
|
1
|
+
require 'sauron'
|
85
2
|
|
86
3
|
Signal.trap('QUIT') do
|
87
|
-
run_all_tests
|
4
|
+
Sauron.run_all_tests
|
88
5
|
end
|
89
6
|
|
90
7
|
# Startup #
|
91
|
-
startup
|
8
|
+
Sauron.startup
|
@@ -1,10 +1,11 @@
|
|
1
1
|
require 'hydra'
|
2
2
|
require 'hydra/tasks'
|
3
|
+
require 'sauron'
|
3
4
|
|
4
5
|
Hydra::TestTask.new('hydra:sauron') do |t|
|
5
6
|
if ENV.has_key?('FILE_LIST')
|
6
7
|
ENV['FILE_LIST'].split(/,/).each {|file| t.add_files file}
|
7
8
|
else
|
8
|
-
|
9
|
+
Sauron.all_tests
|
9
10
|
end
|
10
11
|
end
|
@@ -1,16 +1,35 @@
|
|
1
1
|
require 'lib/sauron/watchr'
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
3
|
+
case Sauron.framework
|
4
|
+
when 'testunit'
|
5
|
+
# Unit tests #
|
6
|
+
watch('test/unit/.*_test\.rb'){|f| Sauron.run_single_test f[0]}
|
7
|
+
watch('app/models/(.*)\.rb'){|f| Sauron.run_single_test "test/unit/#{f[1]}_test.rb"}
|
6
8
|
|
7
|
-
# Functional tests #
|
8
|
-
watch('test/functional/.*_test\.rb'){|f| run_single_test f[0]}
|
9
|
-
watch('app/controllers/(.*)\.rb'){|f| run_single_test "test/functional/#{f[1]}_test.rb"}
|
10
|
-
watch('app/views/(.*)/.*\.html.erb'){|f| run_single_test "test/functional/#{f[1]}_controller_test.rb"}
|
9
|
+
# Functional tests #
|
10
|
+
watch('test/functional/.*_test\.rb'){|f| Sauron.run_single_test f[0]}
|
11
|
+
watch('app/controllers/(.*)\.rb'){|f| Sauron.run_single_test "test/functional/#{f[1]}_test.rb"}
|
12
|
+
watch('app/views/(.*)/.*\.html.erb'){|f| Sauron.run_single_test "test/functional/#{f[1]}_controller_test.rb"}
|
11
13
|
|
12
|
-
# Routing tests #
|
13
|
-
watch('config/routes.rb'){|f| run_routing_tests }
|
14
|
+
# Routing tests #
|
15
|
+
watch('config/routes.rb'){|f| Sauron.run_routing_tests }
|
14
16
|
|
15
|
-
# Multiple tests #
|
16
|
-
watch('test/test_helper.rb'){|f| run_all_tests }
|
17
|
+
# Multiple tests #
|
18
|
+
watch('test/test_helper.rb'){|f| Sauron.run_all_tests }
|
19
|
+
|
20
|
+
when 'rspec'
|
21
|
+
# Model tests #
|
22
|
+
watch('spec/models/.*_spec\.rb'){|f| Sauron.run_single_test f[0]}
|
23
|
+
watch('app/models/(.*)\.rb'){|f| Sauron.run_single_test "spec_models/#{f[1]}_spec.rb"}
|
24
|
+
|
25
|
+
# Controller/View tests #
|
26
|
+
watch('spec/controllers/.*_spec\.rb'){|f| Sauron.run_single_test f[0]}
|
27
|
+
watch('app/controllers/(.*)\.rb'){|f| Sauron.run_multiple_tests ["spec/controllers/#{f[1]}_spec.rb"] + view_tests(f[1])}
|
28
|
+
watch('app/views/(.*)/(.*)'){|f| Sauron.run_multiple_tests "spec/controllers/#{f[1]}_controller_spec.rb", "spec/views/#{f[1]}/#{f[2]}_spec.rb"}
|
29
|
+
|
30
|
+
# Routing tests #
|
31
|
+
watch('config/routes.rb'){|f| Sauron.run_routing_tests }
|
32
|
+
|
33
|
+
# Multiple tests #
|
34
|
+
watch('spec/spec_helper.rb'){|f| Sauron.run_all_tests }
|
35
|
+
end
|
File without changes
|
@@ -0,0 +1,146 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
require 'erb'
|
3
|
+
|
4
|
+
class SauronTemplate
|
5
|
+
attr_accessor :framework, :workers, :hydra
|
6
|
+
|
7
|
+
def initialize
|
8
|
+
config = YAML::load(ERB.new(IO.read(config_file)).result)
|
9
|
+
|
10
|
+
framework = config[:framework]
|
11
|
+
workers = config[:workers]
|
12
|
+
end
|
13
|
+
|
14
|
+
def config_file
|
15
|
+
'config/sauron.yml'
|
16
|
+
end
|
17
|
+
|
18
|
+
def set_hydra
|
19
|
+
if hydra = !!(`rake -T hydra:sauron` =~ /hydra:sauron/)
|
20
|
+
message "Using hydra to run multiple tests in parallel"
|
21
|
+
else
|
22
|
+
message "You don't have hydra properly setup. All tests will be run in single-threaded mode."
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def run_routing_tests
|
27
|
+
message "running routing tests"
|
28
|
+
run_multiple_tests routing_tests
|
29
|
+
end
|
30
|
+
|
31
|
+
def run_single_test file
|
32
|
+
message "running #{file}"
|
33
|
+
|
34
|
+
case framework
|
35
|
+
when 'testunit'
|
36
|
+
system "time ruby -I.:lib:test -rubygems -e \"require '#{file}'\""
|
37
|
+
when 'rspec'
|
38
|
+
system "time ruby script/spec -O spec/spect.opts #{file}"
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def run_multiple_tests *files
|
43
|
+
joined_files = files.join(',')
|
44
|
+
|
45
|
+
message "running #{files.first.size} tests: #{joined_files}"
|
46
|
+
|
47
|
+
if hydra
|
48
|
+
system "time rake hydra:sauron RAILS_ENV=test FILE_LIST=#{joined_files} SAURON_WORKERS=#{$sauron.workers}"
|
49
|
+
else
|
50
|
+
case framework
|
51
|
+
when 'testunit'
|
52
|
+
system "time ruby -I.:lib:test -rubygems -e \"%w[#{files.join(' ')}].each {|f| require f}\""
|
53
|
+
when 'rspec'
|
54
|
+
system "time ruby script/spec -O spec/spect.opts #{files.join(' ')}"
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def run_all_tests
|
60
|
+
message "running all tests"
|
61
|
+
run_multiple_tests all_tests
|
62
|
+
end
|
63
|
+
|
64
|
+
def unit_tests
|
65
|
+
case framework
|
66
|
+
when 'testunit'
|
67
|
+
Dir.glob('test/unit/*_test.rb')
|
68
|
+
when 'rspec'
|
69
|
+
Dir.glob('spec/models/*_spec.rb')
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
def helper_tests
|
74
|
+
case framework
|
75
|
+
when 'testunit'
|
76
|
+
Dir.glob('test/unit/helpers/*_test.rb')
|
77
|
+
when 'rspec'
|
78
|
+
Dir.glob('spec/helpers/*_spec.rb')
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
def functional_tests
|
83
|
+
case framework
|
84
|
+
when 'testunit'
|
85
|
+
Dir.glob('test/functional/*_test.rb')
|
86
|
+
when 'rspec'
|
87
|
+
Dir.glob('spec/controllers/*_spec.rb')
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
def view_tests controller = :all
|
92
|
+
case framework
|
93
|
+
when 'testunit'
|
94
|
+
[]
|
95
|
+
when 'rspec'
|
96
|
+
if controller == :all
|
97
|
+
Dir.glob('spec/views/**/*_spec.rb')
|
98
|
+
else
|
99
|
+
Dir.glob('spec/views/#{controller}/*_spec.rb')
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
def routing_tests
|
105
|
+
case framework
|
106
|
+
when 'testunit'
|
107
|
+
Dir.glob('test/unit/rout{es,ing}_test.rb')
|
108
|
+
when 'rspec'
|
109
|
+
Dir.glob('spec/models/rout{es,ing}_spec.rb')
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
def all_tests
|
114
|
+
case framework
|
115
|
+
when 'testunit'
|
116
|
+
Dir.glob('test/**/*_test.rb')
|
117
|
+
when 'rspec'
|
118
|
+
Dir.glob('spec/**/*_spec.rb')
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
def message body
|
123
|
+
system 'clear'
|
124
|
+
puts body
|
125
|
+
end
|
126
|
+
|
127
|
+
def setup_databases
|
128
|
+
print "setting up #{workers} workers and their databases (you can change in config/sauron.yml)"
|
129
|
+
STDOUT.flush
|
130
|
+
|
131
|
+
# setup each database #
|
132
|
+
workers.times do |i|
|
133
|
+
print '.'
|
134
|
+
STDOUT.flush
|
135
|
+
|
136
|
+
i = '' if i == 0
|
137
|
+
`rake db:reset RAILS_ENV=test TEST_ENV_NUMBER=#{i}`
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
def startup
|
142
|
+
set_hydra
|
143
|
+
setup_databases
|
144
|
+
run_all_tests
|
145
|
+
end
|
146
|
+
end
|
data/lib/sauron.rb
CHANGED
data/sauron.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{sauron}
|
8
|
-
s.version = "0.1.
|
8
|
+
s.version = "0.1.10"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Jaime Bellmyer"]
|
12
|
-
s.date = %q{2010-07-
|
12
|
+
s.date = %q{2010-07-19}
|
13
13
|
s.description = %q{Speed up your automated tests with multiple databases and workers.}
|
14
14
|
s.email = %q{jaime@kconrails.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -23,12 +23,14 @@ Gem::Specification.new do |s|
|
|
23
23
|
"generators/sauron/USAGE",
|
24
24
|
"generators/sauron/sauron_generator.rb",
|
25
25
|
"generators/sauron/templates/config/hydra.yml",
|
26
|
+
"generators/sauron/templates/config/sauron.yml",
|
26
27
|
"generators/sauron/templates/lib/sauron/watchr.rb",
|
27
28
|
"generators/sauron/templates/lib/tasks/sauron.rake",
|
28
|
-
"generators/sauron/templates/sauron",
|
29
29
|
"generators/sauron/templates/sauron_watchr.rb",
|
30
|
+
"generators/sauron/templates/script/sauron",
|
30
31
|
"generators/sauron/templates/test_helper.rb",
|
31
32
|
"lib/sauron.rb",
|
33
|
+
"lib/sauron/sauron_template.rb",
|
32
34
|
"sauron.gemspec",
|
33
35
|
"test/sauron_test.rb",
|
34
36
|
"test/test_helper.rb"
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sauron
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 15
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 10
|
10
|
+
version: 0.1.10
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Jaime Bellmyer
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-07-
|
18
|
+
date: 2010-07-19 00:00:00 -05:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -65,12 +65,14 @@ files:
|
|
65
65
|
- generators/sauron/USAGE
|
66
66
|
- generators/sauron/sauron_generator.rb
|
67
67
|
- generators/sauron/templates/config/hydra.yml
|
68
|
+
- generators/sauron/templates/config/sauron.yml
|
68
69
|
- generators/sauron/templates/lib/sauron/watchr.rb
|
69
70
|
- generators/sauron/templates/lib/tasks/sauron.rake
|
70
|
-
- generators/sauron/templates/sauron
|
71
71
|
- generators/sauron/templates/sauron_watchr.rb
|
72
|
+
- generators/sauron/templates/script/sauron
|
72
73
|
- generators/sauron/templates/test_helper.rb
|
73
74
|
- lib/sauron.rb
|
75
|
+
- lib/sauron/sauron_template.rb
|
74
76
|
- sauron.gemspec
|
75
77
|
- test/sauron_test.rb
|
76
78
|
- test/test_helper.rb
|