nitra 0.9.1 → 0.9.2
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/nitra +34 -1
- data/lib/nitra.rb +31 -11
- metadata +5 -5
data/bin/nitra
CHANGED
@@ -1,4 +1,37 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
3
|
require 'nitra'
|
4
|
-
|
4
|
+
require 'optparse'
|
5
|
+
|
6
|
+
nitra = Nitra.new
|
7
|
+
|
8
|
+
OptionParser.new do |opts|
|
9
|
+
opts.banner = "Usage: nitra [options]"
|
10
|
+
|
11
|
+
opts.on("-c", "--cpus NUMBER", Integer, "Specify the number of CPUs to use, defaults to 4") do |n|
|
12
|
+
nitra.process_count = n
|
13
|
+
end
|
14
|
+
|
15
|
+
opts.on("-e", "--environment STRING", String, "The Rails environment to use, defaults to 'nitra'") do |environment|
|
16
|
+
nitra.environment = environment
|
17
|
+
end
|
18
|
+
|
19
|
+
opts.on("--load", "Load schema into database before running specs") do
|
20
|
+
nitra.load_schema = true
|
21
|
+
end
|
22
|
+
|
23
|
+
opts.on("--migrate", "Migrate database before running specs") do
|
24
|
+
nitra.migrate = true
|
25
|
+
end
|
26
|
+
|
27
|
+
opts.on("--debug", "Print debug output") do
|
28
|
+
nitra.debug = true
|
29
|
+
end
|
30
|
+
|
31
|
+
opts.on_tail("-h", "--help", "Show this message") do
|
32
|
+
puts opts
|
33
|
+
exit
|
34
|
+
end
|
35
|
+
end.parse!
|
36
|
+
|
37
|
+
exit nitra.run
|
data/lib/nitra.rb
CHANGED
@@ -1,12 +1,17 @@
|
|
1
1
|
class Nitra
|
2
|
+
attr_accessor :load_schema, :migrate, :debug
|
3
|
+
attr_accessor :process_count, :environment
|
4
|
+
|
5
|
+
def initialize
|
6
|
+
self.process_count = 4
|
7
|
+
self.environment = "nitra"
|
8
|
+
end
|
9
|
+
|
2
10
|
def run
|
3
11
|
start_time = Time.now
|
4
|
-
ENV["RAILS_ENV"] =
|
5
|
-
|
6
|
-
process_count = 4
|
7
|
-
debug = false
|
12
|
+
ENV["RAILS_ENV"] = environment
|
8
13
|
|
9
|
-
if
|
14
|
+
if load_schema
|
10
15
|
process_count.times do |index|
|
11
16
|
puts "initialising database #{index+1}..."
|
12
17
|
ENV["TEST_ENV_NUMBER"] = (index + 1).to_s
|
@@ -14,12 +19,19 @@ class Nitra
|
|
14
19
|
end
|
15
20
|
end
|
16
21
|
|
22
|
+
if migrate
|
23
|
+
process_count.times do |index|
|
24
|
+
puts "migrating database #{index+1}..."
|
25
|
+
ENV["TEST_ENV_NUMBER"] = (index + 1).to_s
|
26
|
+
system("bundle exec rake db:migrate")
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
17
30
|
puts "loading rails environment..." if debug
|
18
31
|
|
19
32
|
ENV["TEST_ENV_NUMBER"] = "1"
|
20
33
|
|
21
|
-
require '
|
22
|
-
require 'rspec'
|
34
|
+
require 'spec/spec_helper'
|
23
35
|
require 'stringio'
|
24
36
|
|
25
37
|
ActiveRecord::Base.connection.disconnect!
|
@@ -42,7 +54,7 @@ class Nitra
|
|
42
54
|
Rails.cache.reset if Rails.cache.respond_to?(:reset)
|
43
55
|
|
44
56
|
puts "announcing availability" if debug
|
45
|
-
wr.write("0\n")
|
57
|
+
wr.write("0,0\n")
|
46
58
|
|
47
59
|
io = StringIO.new
|
48
60
|
loop do
|
@@ -52,10 +64,12 @@ class Nitra
|
|
52
64
|
filename = filename.chomp
|
53
65
|
puts "#{index} starting to process #{filename}" if debug
|
54
66
|
|
55
|
-
RSpec::Core::CommandLine.new(["-f", "p", filename]).run(io, io)
|
67
|
+
result = RSpec::Core::CommandLine.new(["-f", "p", filename]).run(io, io)
|
56
68
|
RSpec.reset
|
57
69
|
|
58
|
-
|
70
|
+
puts "#{index} #{filename} processed" if debug
|
71
|
+
|
72
|
+
wr.write("#{result.to_i},#{io.string.length}\n#{io.string}")
|
59
73
|
io.string = ""
|
60
74
|
end
|
61
75
|
end
|
@@ -78,11 +92,15 @@ class Nitra
|
|
78
92
|
@failure_count = 0
|
79
93
|
|
80
94
|
result = ""
|
95
|
+
worst_return_code = 0
|
96
|
+
|
81
97
|
while readers.length > 0
|
82
98
|
print_progress
|
83
99
|
fds = IO.select(readers)
|
84
100
|
fds.first.each do |fd|
|
85
|
-
length = fd.gets
|
101
|
+
return_code, length = fd.gets.split(",")
|
102
|
+
|
103
|
+
worst_return_code = return_code.to_i if worst_return_code < return_code.to_i
|
86
104
|
|
87
105
|
if length.nil?
|
88
106
|
break
|
@@ -116,6 +134,8 @@ class Nitra
|
|
116
134
|
result = result.gsub(/\n\n\n+/, "\n\n")
|
117
135
|
puts result
|
118
136
|
puts "\nFinished in #{"%0.1f" % (Time.now-start_time)} seconds"
|
137
|
+
|
138
|
+
worst_return_code
|
119
139
|
end
|
120
140
|
|
121
141
|
protected
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nitra
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 63
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 9
|
9
|
-
-
|
10
|
-
version: 0.9.
|
9
|
+
- 2
|
10
|
+
version: 0.9.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Roger Nesbitt
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date:
|
18
|
+
date: 2012-01-20 00:00:00 +13:00
|
19
19
|
default_executable:
|
20
20
|
dependencies: []
|
21
21
|
|
@@ -61,7 +61,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
61
61
|
requirements: []
|
62
62
|
|
63
63
|
rubyforge_project:
|
64
|
-
rubygems_version: 1.
|
64
|
+
rubygems_version: 1.6.2
|
65
65
|
signing_key:
|
66
66
|
specification_version: 3
|
67
67
|
summary: Multi-process rspec runner
|