forked from civiccc/buffet
/
buffet-worker
executable file
·65 lines (53 loc) · 1.98 KB
/
buffet-worker
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/usr/bin/env ruby
require 'drb'
require 'fileutils'
if File.exist? 'Gemfile'
require 'rubygems'
require 'bundler/setup'
end
# NOTE: ARGV is used by the spec runner. If I leave the drb server address
# in ARGV, rspec will think it's an argument to the test runner.
buffet_server = DRbObject.new_with_uri(ARGV.shift)
slave_name = ARGV.shift
framework = ARGV.shift
FileUtils.mkdir_p('./tmp')
if framework == 'RSPEC1'
require 'spec'
require 'spec/runner/command_line'
require File.expand_path(File.join(File.dirname(__FILE__), 'rspec1_formatter'))
Spec::Runner::Formatter::AugmentedTextFormatter.configure buffet_server, slave_name
while file = buffet_server.next_file_for(slave_name)
# RSpec1 closes stderr/out after each run, so we reopen them each time
outlog = File.open('./tmp/buffet.out.log', 'a')
errlog = File.open('./tmp/buffet.error.log', 'a')
Spec::Runner::CommandLine.run(
Spec::Runner::OptionParser.parse(
['--format', 'Spec::Runner::Formatter::AugmentedTextFormatter', file],
errlog,
outlog
)
)
end
else
require 'rspec'
require File.expand_path(File.join(File.dirname(__FILE__), 'rspec2_formatter'))
RSpec::Core::Formatters::AugmentedTextFormatter.configure buffet_server, slave_name
RSpec.configure do |config|
config.error_stream = $stderr
config.output_stream = $stdout
config.formatter = RSpec::Core::Formatters::AugmentedTextFormatter
end
require RSpec::Core::RubyProject.root.join("spec", "spec_helper").to_s if RSpec::Core::RubyProject.root.join("spec", "spec_helper.rb").exist?
RSpec.configuration.reporter.report(-1) do |reporter|
RSpec.configuration.run_hook(:before, :suite)
begin
while (file = buffet_server.next_file_for(slave_name))
load File.expand_path(file)
RSpec.world.example_groups.map { |g| g.run(reporter) }.all? ? 0 : 1
RSpec.world.example_groups.clear
end
ensure
RSpec.configuration.run_hook(:after, :suite)
end
end
end