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
@@ -0,0 +1,3 @@
1
+ module ParallelTests
2
+ VERSION = Version = '0.7.0.alpha'
3
+ end
@@ -1,65 +1,14 @@
1
- # Generated by jeweler
2
- # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
- # -*- encoding: utf-8 -*-
1
+ $LOAD_PATH.unshift File.expand_path("../lib", __FILE__)
2
+ name = "parallel_tests"
3
+ require "#{name}/version"
5
4
 
6
- Gem::Specification.new do |s|
7
- s.name = "parallel_tests"
8
- s.version = "0.6.20"
9
-
10
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
5
+ Gem::Specification.new name, ParallelTests::VERSION do |s|
6
+ s.summary = "Run tests / specs / features in parallel"
11
7
  s.authors = ["Michael Grosser"]
12
- s.date = "2012-02-24"
13
- s.email = "grosser.michael@gmail.com"
8
+ s.email = "michael@grosser.it"
9
+ s.homepage = "http://github.com/grosser/#{name}"
10
+ s.files = `git ls-files`.split("\n")
11
+ s.license = "MIT"
14
12
  s.executables = ["parallel_cucumber", "parallel_spec", "parallel_test"]
15
- s.files = [
16
- "Gemfile",
17
- "Gemfile.lock",
18
- "Rakefile",
19
- "Readme.md",
20
- "VERSION",
21
- "bin/parallel_cucumber",
22
- "bin/parallel_spec",
23
- "bin/parallel_test",
24
- "lib/parallel_cucumber.rb",
25
- "lib/parallel_cucumber/runtime_logger.rb",
26
- "lib/parallel_specs.rb",
27
- "lib/parallel_specs/spec_failures_logger.rb",
28
- "lib/parallel_specs/spec_logger_base.rb",
29
- "lib/parallel_specs/spec_runtime_logger.rb",
30
- "lib/parallel_specs/spec_summary_logger.rb",
31
- "lib/parallel_tests.rb",
32
- "lib/parallel_tests/grouper.rb",
33
- "lib/parallel_tests/railtie.rb",
34
- "lib/parallel_tests/runtime_logger.rb",
35
- "lib/parallel_tests/tasks.rb",
36
- "lib/tasks/parallel_tests.rake",
37
- "parallel_tests.gemspec",
38
- "spec/integration_spec.rb",
39
- "spec/parallel_cucumber_spec.rb",
40
- "spec/parallel_specs/spec_failure_logger_spec.rb",
41
- "spec/parallel_specs/spec_runtime_logger_spec.rb",
42
- "spec/parallel_specs/spec_summary_logger_spec.rb",
43
- "spec/parallel_specs_spec.rb",
44
- "spec/parallel_tests/runtime_logger_spec.rb",
45
- "spec/parallel_tests_spec.rb",
46
- "spec/spec_helper.rb"
47
- ]
48
- s.homepage = "http://github.com/grosser/parallel_tests"
49
- s.require_paths = ["lib"]
50
- s.rubygems_version = "1.8.15"
51
- s.summary = "Run tests / specs / features in parallel"
52
-
53
- if s.respond_to? :specification_version then
54
- s.specification_version = 3
55
-
56
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
57
- s.add_runtime_dependency(%q<parallel>, [">= 0"])
58
- else
59
- s.add_dependency(%q<parallel>, [">= 0"])
60
- end
61
- else
62
- s.add_dependency(%q<parallel>, [">= 0"])
63
- end
13
+ s.add_runtime_dependency "parallel"
64
14
  end
65
-
@@ -0,0 +1,76 @@
1
+ require 'spec_helper'
2
+
3
+ describe ParallelTests::Cucumber do
4
+ test_tests_in_groups(ParallelTests::Cucumber::Runner, 'features', ".feature")
5
+
6
+ describe :run_tests do
7
+ before do
8
+ ParallelTests.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
+ def call(*args)
14
+ ParallelTests::Cucumber::Runner.run_tests(*args)
15
+ end
16
+
17
+ it "uses TEST_ENV_NUMBER=blank when called for process 0" do
18
+ ParallelTests::Cucumber::Runner.should_receive(:open).with{|x,y| x=~/TEST_ENV_NUMBER= /}.and_return mocked_process
19
+ call(['xxx'],0,{})
20
+ end
21
+
22
+ it "uses TEST_ENV_NUMBER=2 when called for process 1" do
23
+ ParallelTests::Cucumber::Runner.should_receive(:open).with{|x,y| x=~/TEST_ENV_NUMBER=2/}.and_return mocked_process
24
+ call(['xxx'],1,{})
25
+ end
26
+
27
+ it "returns the output" do
28
+ io = open('spec/spec_helper.rb')
29
+ $stdout.stub!(:print)
30
+ ParallelTests::Cucumber::Runner.should_receive(:open).and_return io
31
+ call(['xxx'],1,{})[:stdout].should =~ /\$LOAD_PATH << File/
32
+ end
33
+
34
+ it "runs bundle exec cucumber when on bundler 0.9" do
35
+ ParallelTests.stub!(:bundler_enabled?).and_return true
36
+ ParallelTests::Cucumber::Runner.should_receive(:open).with{|x,y| x =~ %r{bundle exec cucumber}}.and_return mocked_process
37
+ call(['xxx'],1,{})
38
+ end
39
+
40
+ it "runs script/cucumber when script/cucumber is found" do
41
+ ParallelTests::Cucumber::Runner.should_receive(:open).with{|x,y| x =~ %r{script/cucumber}}.and_return mocked_process
42
+ call(['xxx'],1,{})
43
+ end
44
+
45
+ it "runs cucumber by default" do
46
+ File.stub!(:file?).with('script/cucumber').and_return false
47
+ ParallelTests::Cucumber::Runner.should_receive(:open).with{|x,y| x !~ %r{(script/cucumber)|(bundle exec cucumber)}}.and_return mocked_process
48
+ call(['xxx'],1,{})
49
+ end
50
+
51
+ it "uses options passed in" do
52
+ ParallelTests::Cucumber::Runner.should_receive(:open).with{|x,y| x =~ %r{script/cucumber .* -p default}}.and_return mocked_process
53
+ call(['xxx'],1,:test_options => '-p default')
54
+ end
55
+ end
56
+
57
+ describe :find_results do
58
+ it "finds multiple results in test output" do
59
+ output = <<EOF
60
+ And I should not see "/en/" # features/step_definitions/webrat_steps.rb:87
61
+
62
+ 7 scenarios (3 failed, 4 passed)
63
+ 33 steps (3 failed, 2 skipped, 28 passed)
64
+ /apps/rs/features/signup.feature:2
65
+ Given I am on "/" # features/step_definitions/common_steps.rb:12
66
+ When I click "register" # features/step_definitions/common_steps.rb:6
67
+ And I should have "2" emails # features/step_definitions/user_steps.rb:25
68
+
69
+ 4 scenarios (4 passed)
70
+ 40 steps (40 passed)
71
+
72
+ EOF
73
+ ParallelTests::Cucumber::Runner.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)"]
74
+ end
75
+ end
76
+ end
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe ParallelSpecs::SpecFailuresLogger do
3
+ describe ParallelTests::Spec::FailuresLogger do
4
4
  def silence_warnings
5
5
  old_verbose, $VERBOSE = $VERBOSE, nil
6
6
  yield
@@ -14,11 +14,11 @@ describe ParallelSpecs::SpecFailuresLogger do
14
14
  @example2 = mock( 'example', :location => "#{Dir.pwd}/spec/path/to/example2:456", :full_description => 'should do other stuff', :description => 'd')
15
15
  @exception1 = mock( :to_s => 'exception', :backtrace => [ '/path/to/error/line:33' ] )
16
16
  @failure1 = mock( 'example', :location => "#{Dir.pwd}/example:123", :header => 'header', :exception => @exception1 )
17
- @logger = ParallelSpecs::SpecFailuresLogger.new( @output )
17
+ @logger = ParallelTests::Spec::FailuresLogger.new(@output)
18
18
  end
19
19
 
20
20
  after do
21
- silence_warnings{ ParallelSpecs::SpecLoggerBase::RSPEC_1 = false }
21
+ silence_warnings{ ParallelTests::Spec::LoggerBase::RSPEC_1 = false }
22
22
  end
23
23
 
24
24
  def clean_output
@@ -37,9 +37,9 @@ describe ParallelSpecs::SpecFailuresLogger do
37
37
  end
38
38
 
39
39
  it "should invoke spec for rspec 1" do
40
- silence_warnings{ ParallelSpecs::SpecLoggerBase::RSPEC_1 = true }
41
- ParallelSpecs.stub!(:bundler_enabled?).and_return true
42
- ParallelSpecs.stub!(:run).with("bundle show rspec").and_return "/foo/bar/rspec-1.0.2"
40
+ silence_warnings{ ParallelTests::Spec::LoggerBase::RSPEC_1 = true }
41
+ ParallelTests.stub!(:bundler_enabled?).and_return true
42
+ ParallelTests::Spec::Runner.stub!(:run).with("bundle show rspec").and_return "/foo/bar/rspec-1.0.2"
43
43
  @logger.example_failed @example1
44
44
 
45
45
  @logger.dump_failures
@@ -49,8 +49,8 @@ describe ParallelSpecs::SpecFailuresLogger do
49
49
  end
50
50
 
51
51
  it "should invoke rspec for rspec 2" do
52
- ParallelSpecs.stub!(:bundler_enabled?).and_return true
53
- ParallelSpecs.stub!(:run).with("bundle show rspec").and_return "/foo/bar/rspec-2.0.2"
52
+ ParallelTests.stub!(:bundler_enabled?).and_return true
53
+ ParallelTests::Spec::Runner.stub!(:run).with("bundle show rspec").and_return "/foo/bar/rspec-2.0.2"
54
54
  @logger.example_failed @example1
55
55
 
56
56
  @logger.dump_failures
@@ -0,0 +1,178 @@
1
+ require 'spec_helper'
2
+
3
+ describe ParallelTests::Spec::Runner do
4
+ test_tests_in_groups(ParallelTests::Spec::Runner, 'spec', '_spec.rb')
5
+
6
+ describe :run_tests do
7
+ before do
8
+ File.stub!(:file?).with('script/spec').and_return false
9
+ File.stub!(:file?).with('spec/spec.opts').and_return false
10
+ File.stub!(:file?).with('spec/parallel_spec.opts').and_return false
11
+ File.stub!(:file?).with('.rspec_parallel').and_return false
12
+ ParallelTests.stub!(:bundler_enabled?).and_return false
13
+ end
14
+
15
+ def call(*args)
16
+ ParallelTests::Spec::Runner.run_tests(*args)
17
+ end
18
+
19
+ it "uses TEST_ENV_NUMBER=blank when called for process 0" do
20
+ ParallelTests::Spec::Runner.should_receive(:open).with{|x,y|x=~/TEST_ENV_NUMBER= /}.and_return mocked_process
21
+ call(['xxx'], 0, {})
22
+ end
23
+
24
+ it "uses TEST_ENV_NUMBER=2 when called for process 1" do
25
+ ParallelTests::Spec::Runner.should_receive(:open).with{|x,y| x=~/TEST_ENV_NUMBER=2/}.and_return mocked_process
26
+ call(['xxx'],1,{})
27
+ end
28
+
29
+ it "runs with color when called from cmdline" do
30
+ ParallelTests::Spec::Runner.should_receive(:open).with{|x,y| x=~/ --tty /}.and_return mocked_process
31
+ $stdout.should_receive(:tty?).and_return true
32
+ call(['xxx'],1,{})
33
+ end
34
+
35
+ it "runs without color when not called from cmdline" do
36
+ ParallelTests::Spec::Runner.should_receive(:open).with{|x,y| x !~ / --tty /}.and_return mocked_process
37
+ $stdout.should_receive(:tty?).and_return false
38
+ call(['xxx'],1,{})
39
+ end
40
+
41
+ it "runs with color for rspec 1 when called for the cmdline" do
42
+ File.should_receive(:file?).with('script/spec').and_return true
43
+ ParallelTests::Spec::Runner.should_receive(:open).with{|x,y| x=~/ RSPEC_COLOR=1 /}.and_return mocked_process
44
+ $stdout.should_receive(:tty?).and_return true
45
+ call(['xxx'],1,{})
46
+ end
47
+
48
+ it "runs without color for rspec 1 when not called for the cmdline" do
49
+ File.should_receive(:file?).with('script/spec').and_return true
50
+ ParallelTests::Spec::Runner.should_receive(:open).with{|x,y| x !~ / RSPEC_COLOR=1 /}.and_return mocked_process
51
+ $stdout.should_receive(:tty?).and_return false
52
+ call(['xxx'],1,{})
53
+ end
54
+
55
+ it "run bundle exec spec when on bundler rspec 1" do
56
+ File.stub!(:file?).with('script/spec').and_return false
57
+ ParallelTests.stub!(:bundler_enabled?).and_return true
58
+ ParallelTests::Spec::Runner.stub!(:run).with("bundle show rspec").and_return "/foo/bar/rspec-1.0.2"
59
+ ParallelTests::Spec::Runner.should_receive(:open).with{|x,y| x =~ %r{bundle exec spec}}.and_return mocked_process
60
+ call(['xxx'],1,{})
61
+ end
62
+
63
+ it "run bundle exec rspec when on bundler rspec 2" do
64
+ File.stub!(:file?).with('script/spec').and_return false
65
+ ParallelTests.stub!(:bundler_enabled?).and_return true
66
+ ParallelTests::Spec::Runner.stub!(:run).with("bundle show rspec").and_return "/foo/bar/rspec-2.0.2"
67
+ ParallelTests::Spec::Runner.should_receive(:open).with{|x,y| x =~ %r{bundle exec rspec}}.and_return mocked_process
68
+ call(['xxx'],1,{})
69
+ end
70
+
71
+ it "runs script/spec when script/spec can be found" do
72
+ File.should_receive(:file?).with('script/spec').and_return true
73
+ ParallelTests::Spec::Runner.should_receive(:open).with{|x,y| x =~ %r{script/spec}}.and_return mocked_process
74
+ call(['xxx'],1,{})
75
+ end
76
+
77
+ it "runs spec when script/spec cannot be found" do
78
+ File.stub!(:file?).with('script/spec').and_return false
79
+ ParallelTests::Spec::Runner.should_receive(:open).with{|x,y| x !~ %r{script/spec}}.and_return mocked_process
80
+ call(['xxx'],1,{})
81
+ end
82
+
83
+ it "uses no -O when no opts where found" do
84
+ File.stub!(:file?).with('spec/spec.opts').and_return false
85
+ ParallelTests::Spec::Runner.should_receive(:open).with{|x,y| x !~ %r{spec/spec.opts}}.and_return mocked_process
86
+ call(['xxx'],1,{})
87
+ end
88
+
89
+ it "uses -O spec/spec.opts when found (with script/spec)" do
90
+ File.stub!(:file?).with('script/spec').and_return true
91
+ File.stub!(:file?).with('spec/spec.opts').and_return true
92
+ ParallelTests::Spec::Runner.should_receive(:open).with{|x,y| x =~ %r{script/spec\s+ -O spec/spec.opts}}.and_return mocked_process
93
+ call(['xxx'],1,{})
94
+ end
95
+
96
+ it "uses -O spec/parallel_spec.opts when found (with script/spec)" do
97
+ File.stub!(:file?).with('script/spec').and_return true
98
+ File.should_receive(:file?).with('spec/parallel_spec.opts').and_return true
99
+ ParallelTests::Spec::Runner.should_receive(:open).with{|x,y| x =~ %r{script/spec\s+ -O spec/parallel_spec.opts}}.and_return mocked_process
100
+ call(['xxx'],1,{})
101
+ end
102
+
103
+ it "uses -O .rspec_parallel when found (with script/spec)" do
104
+ File.stub!(:file?).with('script/spec').and_return true
105
+ File.should_receive(:file?).with('.rspec_parallel').and_return true
106
+ ParallelTests::Spec::Runner.should_receive(:open).with{|x,y| x =~ %r{script/spec\s+ -O .rspec_parallel}}.and_return mocked_process
107
+ call(['xxx'],1,{})
108
+ end
109
+
110
+ it "uses -O spec/parallel_spec.opts with rspec1" do
111
+ File.should_receive(:file?).with('spec/parallel_spec.opts').and_return true
112
+
113
+ ParallelTests.stub!(:bundler_enabled?).and_return true
114
+ ParallelTests::Spec::Runner.stub!(:run).with("bundle show rspec").and_return "/foo/bar/rspec-1.0.2"
115
+
116
+ ParallelTests::Spec::Runner.should_receive(:open).with{|x,y| x =~ %r{spec\s+ -O spec/parallel_spec.opts}}.and_return mocked_process
117
+ call(['xxx'],1,{})
118
+ end
119
+
120
+ it "uses -O spec/parallel_spec.opts with rspec2" do
121
+ File.should_receive(:file?).with('spec/parallel_spec.opts').and_return true
122
+
123
+ ParallelTests.stub!(:bundler_enabled?).and_return true
124
+ ParallelTests::Spec::Runner.stub!(:run).with("bundle show rspec").and_return "/foo/bar/rspec-2.4.2"
125
+
126
+ ParallelTests::Spec::Runner.should_receive(:open).with{|x,y| x =~ %r{rspec\s+ --color --tty -O spec/parallel_spec.opts}}.and_return mocked_process
127
+ call(['xxx'],1,{})
128
+ end
129
+
130
+ it "uses options passed in" do
131
+ ParallelTests::Spec::Runner.should_receive(:open).with{|x,y| x =~ %r{rspec -f n}}.and_return mocked_process
132
+ call(['xxx'],1, :test_options => '-f n')
133
+ end
134
+
135
+ it "returns the output" do
136
+ io = open('spec/spec_helper.rb')
137
+ $stdout.stub!(:print)
138
+ ParallelTests::Spec::Runner.should_receive(:open).and_return io
139
+ call(['xxx'],1,{})[:stdout].should =~ /\$LOAD_PATH << File/
140
+ end
141
+ end
142
+
143
+ describe :find_results do
144
+ def call(*args)
145
+ ParallelTests::Spec::Runner.find_results(*args)
146
+ end
147
+
148
+ it "finds multiple results in spec output" do
149
+ output = "
150
+ ....F...
151
+ ..
152
+ failute fsddsfsd
153
+ ...
154
+ ff.**..
155
+ 0 examples, 0 failures, 0 pending
156
+ ff.**..
157
+ 1 example, 1 failure, 1 pending
158
+ "
159
+
160
+ call(output).should == ['0 examples, 0 failures, 0 pending','1 example, 1 failure, 1 pending']
161
+ end
162
+
163
+ it "is robust against scrambeled output" do
164
+ output = "
165
+ ....F...
166
+ ..
167
+ failute fsddsfsd
168
+ ...
169
+ ff.**..
170
+ 0 exFampl*es, 0 failures, 0 pend.ing
171
+ ff.**..
172
+ 1 exampF.les, 1 failures, 1 pend.ing
173
+ "
174
+
175
+ call(output).should == ['0 examples, 0 failures, 0 pending','1 examples, 1 failures, 1 pending']
176
+ end
177
+ end
178
+ end
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe ParallelSpecs::SpecRuntimeLogger do
3
+ describe ParallelTests::Spec::RuntimeLogger do
4
4
  before do
5
5
  # pretend we run in parallel or the logger will log nothing
6
6
  ENV['TEST_ENV_NUMBER'] = ''
@@ -18,7 +18,7 @@ describe ParallelSpecs::SpecRuntimeLogger do
18
18
  logger = if block_given?
19
19
  yield(f)
20
20
  else
21
- ParallelSpecs::SpecRuntimeLogger.new(f)
21
+ ParallelTests::Spec::RuntimeLogger.new(f)
22
22
  end
23
23
 
24
24
  example = (mock(:location => "#{Dir.pwd}/spec/foo.rb:123"))
@@ -59,7 +59,7 @@ describe ParallelSpecs::SpecRuntimeLogger do
59
59
  it "appends to a given file" do
60
60
  result = log_for_a_file do |f|
61
61
  f.write 'FooBar'
62
- ParallelSpecs::SpecRuntimeLogger.new(f)
62
+ ParallelTests::Spec::RuntimeLogger.new(f)
63
63
  end
64
64
  result.should include('FooBar')
65
65
  result.should include('foo.rb')
@@ -68,7 +68,7 @@ describe ParallelSpecs::SpecRuntimeLogger do
68
68
  it "overwrites a given path" do
69
69
  result = log_for_a_file do |f|
70
70
  f.write 'FooBar'
71
- ParallelSpecs::SpecRuntimeLogger.new(f.path)
71
+ ParallelTests::Spec::RuntimeLogger.new(f.path)
72
72
  end
73
73
  result.should_not include('FooBar')
74
74
  result.should include('foo.rb')
@@ -1,8 +1,8 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe ParallelSpecs::SpecSummaryLogger do
3
+ describe ParallelTests::Spec::SummaryLogger do
4
4
  let(:output){ OutputLogger.new([]) }
5
- let(:logger){ ParallelSpecs::SpecSummaryLogger.new(output) }
5
+ let(:logger){ ParallelTests::Spec::SummaryLogger.new(output) }
6
6
 
7
7
  # TODO somehow generate a real example with an exception to test this
8
8
  xit "prints failing examples" do
@@ -0,0 +1,179 @@
1
+ require 'spec_helper'
2
+
3
+ describe ParallelTests::Test::Runner do
4
+ test_tests_in_groups(ParallelTests::Test::Runner, 'test', '_test.rb')
5
+
6
+ describe :run_tests do
7
+ def call(*args)
8
+ ParallelTests::Test::Runner.run_tests(*args)
9
+ end
10
+
11
+ it "uses TEST_ENV_NUMBER=blank when called for process 0" do
12
+ ParallelTests::Test::Runner.should_receive(:open).with{|x,y|x=~/TEST_ENV_NUMBER= /}.and_return mocked_process
13
+ call(['xxx'],0,{})
14
+ end
15
+
16
+ it "uses TEST_ENV_NUMBER=2 when called for process 1" do
17
+ ParallelTests::Test::Runner.should_receive(:open).with{|x,y| x=~/TEST_ENV_NUMBER=2/}.and_return mocked_process
18
+ call(['xxx'],1,{})
19
+ end
20
+
21
+ it "uses options" do
22
+ ParallelTests::Test::Runner.should_receive(:open).with{|x,y| x=~ %r{ruby -Itest .* -- -v}}.and_return mocked_process
23
+ call(['xxx'],1,:test_options => '-v')
24
+ end
25
+
26
+ it "returns the output" do
27
+ io = open('spec/spec_helper.rb')
28
+ $stdout.stub!(:print)
29
+ ParallelTests::Test::Runner.should_receive(:open).and_return io
30
+ call(['xxx'],1,{})[:stdout].should =~ /\$LOAD_PATH << File/
31
+ end
32
+ end
33
+
34
+ describe :test_in_groups do
35
+ def call(*args)
36
+ ParallelTests::Test::Runner.tests_in_groups(*args)
37
+ end
38
+
39
+ it "does not sort when passed false do_sort option" do
40
+ ParallelTests::Test::Runner.should_not_receive(:smallest_first)
41
+ call [], 1, :no_sort => true
42
+ end
43
+
44
+ it "does sort when not passed do_sort option" do
45
+ ParallelTests::Test::Runner.stub!(:tests_with_runtime).and_return([])
46
+ ParallelTests::Grouper.should_receive(:largest_first).and_return([])
47
+ call [], 1
48
+ end
49
+
50
+ it "groups by single_process pattern and then via size" do
51
+ ParallelTests::Test::Runner.should_receive(:with_runtime_info).and_return([['aaa',5],['aaa2',5],['bbb',2],['ccc',1],['ddd',1]])
52
+ result = call [], 3, :single_process => [/^a.a/]
53
+ result.should == [["aaa", "aaa2"], ["bbb"], ["ccc", "ddd"]]
54
+ end
55
+ end
56
+
57
+ describe :find_results do
58
+ def call(*args)
59
+ ParallelTests::Test::Runner.find_results(*args)
60
+ end
61
+
62
+ it "finds multiple results in test output" do
63
+ output = <<EOF
64
+ Loaded suite /opt/ruby-enterprise/lib/ruby/gems/1.8/gems/rake-0.8.4/lib/rake/rake_test_loader
65
+ Started
66
+ ..............
67
+ Finished in 0.145069 seconds.
68
+
69
+ 10 tests, 20 assertions, 0 failures, 0 errors
70
+ Loaded suite /opt/ruby-enterprise/lib/ruby/gems/1.8/gems/rake-0.8.4/lib/rake/rake_test_loader
71
+ Started
72
+ ..............
73
+ Finished in 0.145069 seconds.
74
+
75
+ 14 tests, 20 assertions, 0 failures, 0 errors
76
+
77
+ EOF
78
+
79
+ call(output).should == ['10 tests, 20 assertions, 0 failures, 0 errors','14 tests, 20 assertions, 0 failures, 0 errors']
80
+ end
81
+
82
+ it "is robust against scrambled output" do
83
+ output = <<EOF
84
+ Loaded suite /opt/ruby-enterprise/lib/ruby/gems/1.8/gems/rake-0.8.4/lib/rake/rake_test_loader
85
+ Started
86
+ ..............
87
+ Finished in 0.145069 seconds.
88
+
89
+ 10 tests, 20 assertions, 0 failures, 0 errors
90
+ Loaded suite /opt/ruby-enterprise/lib/ruby/gems/1.8/gems/rake-0.8.4/lib/rake/rake_test_loader
91
+ Started
92
+ ..............
93
+ Finished in 0.145069 seconds.
94
+
95
+ 14 te.dsts, 20 assertions, 0 failures, 0 errors
96
+ EOF
97
+
98
+ call(output).should == ['10 tests, 20 assertions, 0 failures, 0 errors','14 tedsts, 20 assertions, 0 failures, 0 errors']
99
+ end
100
+ end
101
+
102
+ describe :find_tests do
103
+ def call(*args)
104
+ ParallelTests::Test::Runner.send(:find_tests, *args)
105
+ end
106
+
107
+ it "returns if root is an array" do
108
+ call([1]).should == [1]
109
+ end
110
+
111
+ it "finds all test files" do
112
+ begin
113
+ root = "/tmp/test-find_tests-#{rand(999)}"
114
+ `mkdir #{root}`
115
+ `mkdir #{root}/a`
116
+ `mkdir #{root}/b`
117
+ `touch #{root}/x_test.rb`
118
+ `touch #{root}/a/x_test.rb`
119
+ `touch #{root}/a/test.rb`
120
+ `touch #{root}/b/y_test.rb`
121
+ `touch #{root}/b/test.rb`
122
+ `ln -s #{root}/b #{root}/c`
123
+ `ln -s #{root}/b #{root}/a/`
124
+ call(root).sort.should == [
125
+ "#{root}/a/b/y_test.rb",
126
+ "#{root}/a/x_test.rb",
127
+ "#{root}/b/y_test.rb",
128
+ "#{root}/c/y_test.rb",
129
+ "#{root}/x_test.rb"
130
+ ]
131
+ ensure
132
+ `rm -rf #{root}`
133
+ end
134
+ end
135
+
136
+ it "finds files by pattern" do
137
+ begin
138
+ root = "/tmp/test-find_tests-#{rand(999)}"
139
+ `mkdir #{root}`
140
+ `mkdir #{root}/a`
141
+ `touch #{root}/a/x_test.rb`
142
+ `touch #{root}/a/y_test.rb`
143
+ `touch #{root}/a/z_test.rb`
144
+ call(root, :pattern => '^a/(y|z)_test').sort.should == [
145
+ "#{root}/a/y_test.rb",
146
+ "#{root}/a/z_test.rb",
147
+ ]
148
+ ensure
149
+ `rm -rf #{root}`
150
+ end
151
+ end
152
+ end
153
+
154
+ describe :summarize_results do
155
+ def call(*args)
156
+ ParallelTests::Test::Runner.summarize_results(*args)
157
+ end
158
+
159
+ it "adds results" do
160
+ call(['1 foo 3 bar','2 foo 5 bar']).should == '8 bars, 3 foos'
161
+ end
162
+
163
+ it "adds results with braces" do
164
+ call(['1 foo(s) 3 bar(s)','2 foo 5 bar']).should == '8 bars, 3 foos'
165
+ end
166
+
167
+ it "adds same results with plurals" do
168
+ call(['1 foo 3 bar','2 foos 5 bar']).should == '8 bars, 3 foos'
169
+ end
170
+
171
+ it "adds non-similar results" do
172
+ call(['1 xxx 2 yyy','1 xxx 2 zzz']).should == '2 xxxs, 2 yyys, 2 zzzs'
173
+ end
174
+
175
+ it "does not pluralize 1" do
176
+ call(['1 xxx 2 yyy']).should == '1 xxx, 2 yyys'
177
+ end
178
+ end
179
+ end