parallel_tests 0.6.20 → 0.7.0.alpha

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. data/.gitignore +1 -0
  2. data/Gemfile +2 -4
  3. data/Gemfile.lock +7 -7
  4. data/Rakefile +18 -16
  5. data/Readme.md +15 -12
  6. data/bin/parallel_test +2 -98
  7. data/lib/parallel_tests.rb +2 -125
  8. data/lib/parallel_tests/cli.rb +102 -0
  9. data/lib/parallel_tests/cucumber/runner.rb +40 -0
  10. data/lib/parallel_tests/cucumber/runtime_logger.rb +58 -0
  11. data/lib/parallel_tests/grouper.rb +2 -2
  12. data/lib/parallel_tests/railtie.rb +3 -3
  13. data/lib/{parallel_specs/spec_failures_logger.rb → parallel_tests/spec/failures_logger.rb} +4 -3
  14. data/lib/{parallel_specs/spec_logger_base.rb → parallel_tests/spec/logger_base.rb} +7 -3
  15. data/lib/parallel_tests/spec/runner.rb +56 -0
  16. data/lib/{parallel_specs/spec_runtime_logger.rb → parallel_tests/spec/runtime_logger.rb} +2 -2
  17. data/lib/{parallel_specs/spec_summary_logger.rb → parallel_tests/spec/summary_logger.rb} +2 -2
  18. data/lib/parallel_tests/tasks.rb +0 -25
  19. data/lib/parallel_tests/test/runner.rb +126 -0
  20. data/lib/parallel_tests/test/runtime_logger.rb +92 -0
  21. data/lib/parallel_tests/version.rb +3 -0
  22. data/parallel_tests.gemspec +10 -61
  23. data/spec/parallel_tests/cucumber/runner_spec.rb +76 -0
  24. data/spec/{parallel_specs/spec_failure_logger_spec.rb → parallel_tests/spec/failure_logger_spec.rb} +8 -8
  25. data/spec/parallel_tests/spec/runner_spec.rb +178 -0
  26. data/spec/{parallel_specs/spec_runtime_logger_spec.rb → parallel_tests/spec/runtime_logger_spec.rb} +4 -4
  27. data/spec/{parallel_specs/spec_summary_logger_spec.rb → parallel_tests/spec/summary_logger_spec.rb} +2 -2
  28. data/spec/parallel_tests/test/runner_spec.rb +179 -0
  29. data/spec/parallel_tests/{runtime_logger_spec.rb → test/runtime_logger_spec.rb} +19 -16
  30. data/spec/parallel_tests_spec.rb +2 -158
  31. data/spec/spec_helper.rb +9 -7
  32. metadata +30 -26
  33. data/VERSION +0 -1
  34. data/lib/parallel_cucumber.rb +0 -36
  35. data/lib/parallel_cucumber/runtime_logger.rb +0 -57
  36. data/lib/parallel_specs.rb +0 -52
  37. data/lib/parallel_tests/runtime_logger.rb +0 -78
  38. data/lib/tasks/parallel_tests.rake +0 -1
  39. data/spec/parallel_cucumber_spec.rb +0 -72
  40. data/spec/parallel_specs_spec.rb +0 -173
@@ -1,52 +0,0 @@
1
- require 'parallel_tests'
2
-
3
- class ParallelSpecs < ParallelTests
4
- def self.run_tests(test_files, process_number, options)
5
- exe = executable # expensive, so we cache
6
- version = (exe =~ /\brspec\b/ ? 2 : 1)
7
- cmd = "#{rspec_1_color if version == 1}#{exe} #{options[:test_options]} #{rspec_2_color if version == 2}#{spec_opts(version)} #{test_files*' '}"
8
- execute_command(cmd, process_number, options)
9
- end
10
-
11
- def self.executable
12
- cmd = if File.file?("script/spec")
13
- "script/spec"
14
- elsif bundler_enabled?
15
- cmd = (run("bundle show rspec") =~ %r{/rspec-1[^/]+$} ? "spec" : "rspec")
16
- "bundle exec #{cmd}"
17
- else
18
- %w[spec rspec].detect{|cmd| system "#{cmd} --version > /dev/null 2>&1" }
19
- end
20
- cmd or raise("Can't find executables rspec or spec")
21
- end
22
-
23
- # legacy <-> people log to this file using rspec options
24
- def self.runtime_log
25
- 'tmp/parallel_profile.log'
26
- end
27
-
28
- protected
29
-
30
- # so it can be stubbed....
31
- def self.run(cmd)
32
- `#{cmd}`
33
- end
34
-
35
- def self.rspec_1_color
36
- 'RSPEC_COLOR=1 ; export RSPEC_COLOR ;' if $stdout.tty?
37
- end
38
-
39
- def self.rspec_2_color
40
- '--color --tty ' if $stdout.tty?
41
- end
42
-
43
- def self.spec_opts(rspec_version)
44
- options_file = ['.rspec_parallel', 'spec/parallel_spec.opts', 'spec/spec.opts'].detect{|f| File.file?(f) }
45
- return unless options_file
46
- "-O #{options_file}"
47
- end
48
-
49
- def self.test_suffix
50
- "_spec.rb"
51
- end
52
- end
@@ -1,78 +0,0 @@
1
- class ParallelTests::RuntimeLogger
2
- @@has_started = false
3
-
4
- def self.log(test, start_time, end_time)
5
- return if test.is_a? Test::Unit::TestSuite # don't log for suites-of-suites
6
-
7
- if !@@has_started # make empty log file
8
- File.open(ParallelTests.runtime_log, 'w') do end
9
- @@has_started = true
10
- end
11
-
12
- File.open(ParallelTests.runtime_log, 'a') do |output|
13
- begin
14
- output.flock File::LOCK_EX
15
- output.puts(self.message(test, start_time, end_time))
16
- ensure
17
- output.flock File::LOCK_UN
18
- end
19
- end
20
- end
21
-
22
- def self.message(test, start_time, end_time)
23
- delta="%.2f" % (end_time.to_f-start_time.to_f)
24
- filename=class_directory(test.class) + class_to_filename(test.class) + ".rb"
25
- message="#{filename}:#{delta}"
26
- end
27
-
28
- # Note: this is a best guess at conventional test directory structure, and may need
29
- # tweaking / post-processing to match correctly for any given project
30
- def self.class_directory(suspect)
31
- result = "test/"
32
-
33
- if defined?(Rails)
34
- result += case suspect.superclass.name
35
- when "ActionDispatch::IntegrationTest"
36
- "integration/"
37
- when "ActionDispatch::PerformanceTest"
38
- "performance/"
39
- when "ActionController::TestCase"
40
- "functional/"
41
- when "ActionView::TestCase"
42
- "unit/helpers/"
43
- else
44
- "unit/"
45
- end
46
- end
47
- result
48
- end
49
-
50
- # based on https://github.com/grosser/single_test/blob/master/lib/single_test.rb#L117
51
- def self.class_to_filename(suspect)
52
- word = suspect.to_s.dup
53
- return word unless word.match /^[A-Z]/ and not word.match %r{/[a-z]}
54
-
55
- word.gsub!(/([A-Z]+)([A-Z][a-z])/,'\1_\2')
56
- word.gsub!(/([a-z\d])([A-Z])/,'\1_\2')
57
- word.gsub!(/\:\:/,'/')
58
- word.tr!("-", "_")
59
- word.downcase!
60
- word
61
- end
62
-
63
- end
64
-
65
- require 'test/unit/testsuite'
66
- class Test::Unit::TestSuite
67
-
68
- alias :run_without_timing :run unless defined? @@timing_installed
69
-
70
- def run(result, &progress_block)
71
- start_time=Time.now
72
- run_without_timing(result, &progress_block)
73
- end_time=Time.now
74
- ParallelTests::RuntimeLogger.log(self.tests.first, start_time, end_time)
75
- end
76
- @@timing_installed = true
77
-
78
- end
@@ -1 +0,0 @@
1
- require File.join(File.dirname(__FILE__), "/../parallel_tests/tasks")
@@ -1,72 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe ParallelCucumber do
4
- test_tests_in_groups(ParallelCucumber, 'features', ".feature")
5
-
6
- describe :run_tests do
7
- before do
8
- ParallelCucumber.stub!(:bundler_enabled?).and_return false
9
- File.stub!(:file?).with('.bundle/environment.rb').and_return false
10
- File.stub!(:file?).with('script/cucumber').and_return true
11
- end
12
-
13
- it "uses TEST_ENV_NUMBER=blank when called for process 0" do
14
- ParallelCucumber.should_receive(:open).with{|x,y| x=~/TEST_ENV_NUMBER= /}.and_return mocked_process
15
- ParallelCucumber.run_tests(['xxx'],0,{})
16
- end
17
-
18
- it "uses TEST_ENV_NUMBER=2 when called for process 1" do
19
- ParallelCucumber.should_receive(:open).with{|x,y| x=~/TEST_ENV_NUMBER=2/}.and_return mocked_process
20
- ParallelCucumber.run_tests(['xxx'],1,{})
21
- end
22
-
23
- it "returns the output" do
24
- io = open('spec/spec_helper.rb')
25
- $stdout.stub!(:print)
26
- ParallelCucumber.should_receive(:open).and_return io
27
- ParallelCucumber.run_tests(['xxx'],1,{})[:stdout].should =~ /\$LOAD_PATH << File/
28
- end
29
-
30
- it "runs bundle exec cucumber when on bundler 0.9" do
31
- ParallelCucumber.stub!(:bundler_enabled?).and_return true
32
- ParallelCucumber.should_receive(:open).with{|x,y| x =~ %r{bundle exec cucumber}}.and_return mocked_process
33
- ParallelCucumber.run_tests(['xxx'],1,{})
34
- end
35
-
36
- it "runs script/cucumber when script/cucumber is found" do
37
- ParallelCucumber.should_receive(:open).with{|x,y| x =~ %r{script/cucumber}}.and_return mocked_process
38
- ParallelCucumber.run_tests(['xxx'],1,{})
39
- end
40
-
41
- it "runs cucumber by default" do
42
- File.stub!(:file?).with('script/cucumber').and_return false
43
- ParallelCucumber.should_receive(:open).with{|x,y| x !~ %r{(script/cucumber)|(bundle exec cucumber)}}.and_return mocked_process
44
- ParallelCucumber.run_tests(['xxx'],1,{})
45
- end
46
-
47
- it "uses options passed in" do
48
- ParallelCucumber.should_receive(:open).with{|x,y| x =~ %r{script/cucumber .* -p default}}.and_return mocked_process
49
- ParallelCucumber.run_tests(['xxx'],1,:test_options => '-p default')
50
- end
51
- end
52
-
53
- describe :find_results do
54
- it "finds multiple results in test output" do
55
- output = <<EOF
56
- And I should not see "/en/" # features/step_definitions/webrat_steps.rb:87
57
-
58
- 7 scenarios (3 failed, 4 passed)
59
- 33 steps (3 failed, 2 skipped, 28 passed)
60
- /apps/rs/features/signup.feature:2
61
- Given I am on "/" # features/step_definitions/common_steps.rb:12
62
- When I click "register" # features/step_definitions/common_steps.rb:6
63
- And I should have "2" emails # features/step_definitions/user_steps.rb:25
64
-
65
- 4 scenarios (4 passed)
66
- 40 steps (40 passed)
67
-
68
- EOF
69
- ParallelCucumber.find_results(output).should == ["7 scenarios (3 failed, 4 passed)", "33 steps (3 failed, 2 skipped, 28 passed)", "4 scenarios (4 passed)", "40 steps (40 passed)"]
70
- end
71
- end
72
- end
@@ -1,173 +0,0 @@
1
- require 'spec_helper'
2
- require 'parallel_specs/spec_runtime_logger'
3
- require 'parallel_specs/spec_summary_logger'
4
- require 'parallel_specs/spec_failures_logger'
5
-
6
- describe ParallelSpecs do
7
- test_tests_in_groups(ParallelSpecs, 'spec', '_spec.rb')
8
-
9
- describe :run_tests do
10
- before do
11
- File.stub!(:file?).with('script/spec').and_return false
12
- File.stub!(:file?).with('spec/spec.opts').and_return false
13
- File.stub!(:file?).with('spec/parallel_spec.opts').and_return false
14
- File.stub!(:file?).with('.rspec_parallel').and_return false
15
- ParallelSpecs.stub!(:bundler_enabled?).and_return false
16
- end
17
-
18
- it "uses TEST_ENV_NUMBER=blank when called for process 0" do
19
- ParallelSpecs.should_receive(:open).with{|x,y|x=~/TEST_ENV_NUMBER= /}.and_return mocked_process
20
- ParallelSpecs.run_tests(['xxx'],0,{})
21
- end
22
-
23
- it "uses TEST_ENV_NUMBER=2 when called for process 1" do
24
- ParallelSpecs.should_receive(:open).with{|x,y| x=~/TEST_ENV_NUMBER=2/}.and_return mocked_process
25
- ParallelSpecs.run_tests(['xxx'],1,{})
26
- end
27
-
28
- it "runs with color when called from cmdline" do
29
- ParallelSpecs.should_receive(:open).with{|x,y| x=~/ --tty /}.and_return mocked_process
30
- $stdout.should_receive(:tty?).and_return true
31
- ParallelSpecs.run_tests(['xxx'],1,{})
32
- end
33
-
34
- it "runs without color when not called from cmdline" do
35
- ParallelSpecs.should_receive(:open).with{|x,y| x !~ / --tty /}.and_return mocked_process
36
- $stdout.should_receive(:tty?).and_return false
37
- ParallelSpecs.run_tests(['xxx'],1,{})
38
- end
39
-
40
- it "runs with color for rspec 1 when called for the cmdline" do
41
- File.should_receive(:file?).with('script/spec').and_return true
42
- ParallelSpecs.should_receive(:open).with{|x,y| x=~/ RSPEC_COLOR=1 /}.and_return mocked_process
43
- $stdout.should_receive(:tty?).and_return true
44
- ParallelSpecs.run_tests(['xxx'],1,{})
45
- end
46
-
47
- it "runs without color for rspec 1 when not called for the cmdline" do
48
- File.should_receive(:file?).with('script/spec').and_return true
49
- ParallelSpecs.should_receive(:open).with{|x,y| x !~ / RSPEC_COLOR=1 /}.and_return mocked_process
50
- $stdout.should_receive(:tty?).and_return false
51
- ParallelSpecs.run_tests(['xxx'],1,{})
52
- end
53
-
54
- it "run bundle exec spec when on bundler rspec 1" do
55
- File.stub!(:file?).with('script/spec').and_return false
56
- ParallelSpecs.stub!(:bundler_enabled?).and_return true
57
- ParallelSpecs.stub!(:run).with("bundle show rspec").and_return "/foo/bar/rspec-1.0.2"
58
- ParallelSpecs.should_receive(:open).with{|x,y| x =~ %r{bundle exec spec}}.and_return mocked_process
59
- ParallelSpecs.run_tests(['xxx'],1,{})
60
- end
61
-
62
- it "run bundle exec rspec when on bundler rspec 2" do
63
- File.stub!(:file?).with('script/spec').and_return false
64
- ParallelSpecs.stub!(:bundler_enabled?).and_return true
65
- ParallelSpecs.stub!(:run).with("bundle show rspec").and_return "/foo/bar/rspec-2.0.2"
66
- ParallelSpecs.should_receive(:open).with{|x,y| x =~ %r{bundle exec rspec}}.and_return mocked_process
67
- ParallelSpecs.run_tests(['xxx'],1,{})
68
- end
69
-
70
- it "runs script/spec when script/spec can be found" do
71
- File.should_receive(:file?).with('script/spec').and_return true
72
- ParallelSpecs.should_receive(:open).with{|x,y| x =~ %r{script/spec}}.and_return mocked_process
73
- ParallelSpecs.run_tests(['xxx'],1,{})
74
- end
75
-
76
- it "runs spec when script/spec cannot be found" do
77
- File.stub!(:file?).with('script/spec').and_return false
78
- ParallelSpecs.should_receive(:open).with{|x,y| x !~ %r{script/spec}}.and_return mocked_process
79
- ParallelSpecs.run_tests(['xxx'],1,{})
80
- end
81
-
82
- it "uses no -O when no opts where found" do
83
- File.stub!(:file?).with('spec/spec.opts').and_return false
84
- ParallelSpecs.should_receive(:open).with{|x,y| x !~ %r{spec/spec.opts}}.and_return mocked_process
85
- ParallelSpecs.run_tests(['xxx'],1,{})
86
- end
87
-
88
- it "uses -O spec/spec.opts when found (with script/spec)" do
89
- File.stub!(:file?).with('script/spec').and_return true
90
- File.stub!(:file?).with('spec/spec.opts').and_return true
91
- ParallelSpecs.should_receive(:open).with{|x,y| x =~ %r{script/spec\s+ -O spec/spec.opts}}.and_return mocked_process
92
- ParallelSpecs.run_tests(['xxx'],1,{})
93
- end
94
-
95
- it "uses -O spec/parallel_spec.opts when found (with script/spec)" do
96
- File.stub!(:file?).with('script/spec').and_return true
97
- File.should_receive(:file?).with('spec/parallel_spec.opts').and_return true
98
- ParallelSpecs.should_receive(:open).with{|x,y| x =~ %r{script/spec\s+ -O spec/parallel_spec.opts}}.and_return mocked_process
99
- ParallelSpecs.run_tests(['xxx'],1,{})
100
- end
101
-
102
- it "uses -O .rspec_parallel when found (with script/spec)" do
103
- File.stub!(:file?).with('script/spec').and_return true
104
- File.should_receive(:file?).with('.rspec_parallel').and_return true
105
- ParallelSpecs.should_receive(:open).with{|x,y| x =~ %r{script/spec\s+ -O .rspec_parallel}}.and_return mocked_process
106
- ParallelSpecs.run_tests(['xxx'],1,{})
107
- end
108
-
109
- it "uses -O spec/parallel_spec.opts with rspec1" do
110
- File.should_receive(:file?).with('spec/parallel_spec.opts').and_return true
111
-
112
- ParallelSpecs.stub!(:bundler_enabled?).and_return true
113
- ParallelSpecs.stub!(:run).with("bundle show rspec").and_return "/foo/bar/rspec-1.0.2"
114
-
115
- ParallelSpecs.should_receive(:open).with{|x,y| x =~ %r{spec\s+ -O spec/parallel_spec.opts}}.and_return mocked_process
116
- ParallelSpecs.run_tests(['xxx'],1,{})
117
- end
118
-
119
- it "uses -O spec/parallel_spec.opts with rspec2" do
120
- File.should_receive(:file?).with('spec/parallel_spec.opts').and_return true
121
-
122
- ParallelSpecs.stub!(:bundler_enabled?).and_return true
123
- ParallelSpecs.stub!(:run).with("bundle show rspec").and_return "/foo/bar/rspec-2.4.2"
124
-
125
- ParallelSpecs.should_receive(:open).with{|x,y| x =~ %r{rspec\s+ --color --tty -O spec/parallel_spec.opts}}.and_return mocked_process
126
- ParallelSpecs.run_tests(['xxx'],1,{})
127
- end
128
-
129
- it "uses options passed in" do
130
- ParallelSpecs.should_receive(:open).with{|x,y| x =~ %r{rspec -f n}}.and_return mocked_process
131
- ParallelSpecs.run_tests(['xxx'],1, :test_options => '-f n')
132
- end
133
-
134
- it "returns the output" do
135
- io = open('spec/spec_helper.rb')
136
- $stdout.stub!(:print)
137
- ParallelSpecs.should_receive(:open).and_return io
138
- ParallelSpecs.run_tests(['xxx'],1,{})[:stdout].should =~ /\$LOAD_PATH << File/
139
- end
140
- end
141
-
142
- describe :find_results do
143
- it "finds multiple results in spec output" do
144
- output = <<EOF
145
- ....F...
146
- ..
147
- failute fsddsfsd
148
- ...
149
- ff.**..
150
- 0 examples, 0 failures, 0 pending
151
- ff.**..
152
- 1 example, 1 failure, 1 pending
153
- EOF
154
-
155
- ParallelSpecs.find_results(output).should == ['0 examples, 0 failures, 0 pending','1 example, 1 failure, 1 pending']
156
- end
157
-
158
- it "is robust against scrambeled output" do
159
- output = <<EOF
160
- ....F...
161
- ..
162
- failute fsddsfsd
163
- ...
164
- ff.**..
165
- 0 exFampl*es, 0 failures, 0 pend.ing
166
- ff.**..
167
- 1 exampF.les, 1 failures, 1 pend.ing
168
- EOF
169
-
170
- ParallelSpecs.find_results(output).should == ['0 examples, 0 failures, 0 pending','1 examples, 1 failures, 1 pending']
171
- end
172
- end
173
- end