parallel_tests 0.4.1 → 0.4.2

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/README.markdown CHANGED
@@ -108,6 +108,7 @@ inspired by [pivotal labs](http://pivotallabs.com/users/miked/blog/articles/849-
108
108
 
109
109
  ###Contributors (alphabetical)
110
110
  - [Charles Finkel](http://charlesfinkel.com/)
111
+ - [Indrek Juhkam](http://urgas.eu)
111
112
  - [Jason Morrison](http://jayunit.net)
112
113
  - [Joakim Kolsjö](http://www.rubyblocks.se)
113
114
  - [Kevin Scaldeferri](http://kevin.scaldeferri.com/blog/)
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.4.1
1
+ 0.4.2
@@ -8,7 +8,7 @@ class ParallelCucumber < ParallelTests
8
8
  end
9
9
 
10
10
  def self.executable
11
- if File.file?(".bundle/environment.rb")
11
+ if bundler_enabled?
12
12
  "bundle exec cucumber"
13
13
  elsif File.file?("script/cucumber")
14
14
  "script/cucumber"
@@ -7,7 +7,7 @@ class ParallelSpecs < ParallelTests
7
7
  end
8
8
 
9
9
  def self.executable
10
- if File.file?(".bundle/environment.rb")
10
+ if bundler_enabled?
11
11
  "bundle exec spec"
12
12
  elsif File.file?("script/spec")
13
13
  "script/spec"
@@ -65,6 +65,22 @@ class ParallelTests
65
65
 
66
66
  protected
67
67
 
68
+ # copied from http://github.com/carlhuda/bundler Bundler::SharedHelpers#find_gemfile
69
+ def self.bundler_enabled?
70
+ return true if Object.const_defined?(:Bundler)
71
+
72
+ previous = nil
73
+ current = File.expand_path(Dir.pwd)
74
+
75
+ until !File.directory?(current) || current == previous
76
+ filename = File.join(current, "Gemfile")
77
+ return true if File.exists?(filename)
78
+ current, previous = File.expand_path("..", current), current
79
+ end
80
+
81
+ false
82
+ end
83
+
68
84
  def self.line_is_result?(line)
69
85
  line =~ /\d+ failure/
70
86
  end
@@ -25,7 +25,7 @@ namespace :parallel do
25
25
  ['test', 'spec', 'features'].each do |type|
26
26
  desc "run #{type} in parallel with parallel:#{type}[num_cpus]"
27
27
  task type, :count, :path_prefix, :options do |t,args|
28
- $LOAD_PATH << File.join(File.dirname(__FILE__), '..')
28
+ $LOAD_PATH << File.expand_path(File.join(File.dirname(__FILE__), '..'))
29
29
  require "parallel_tests"
30
30
  count, prefix, options = ParallelTests.parse_rake_args(args)
31
31
  exec "#{File.join(File.dirname(__FILE__), '..', '..', 'bin', 'parallel_test')} --type #{type} -n #{count} -p '#{prefix}' -r '#{RAILS_ROOT}' -o '#{options}'"
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{parallel_tests}
8
- s.version = "0.4.1"
8
+ s.version = "0.4.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Michael Grosser"]
@@ -27,7 +27,7 @@ describe ParallelCucumber do
27
27
  end
28
28
 
29
29
  it "runs bundle exec cucumber when on bundler 0.9" do
30
- File.stub!(:file?).with('.bundle/environment.rb').and_return true
30
+ ParallelCucumber.stub!(:bundler_enabled?).and_return true
31
31
  ParallelCucumber.should_receive(:open).with{|x,y| x =~ %r{bundle exec cucumber}}.and_return mock(:getc=>false)
32
32
  ParallelCucumber.run_tests(['xxx'],1,'')
33
33
  end
@@ -34,7 +34,7 @@ describe ParallelSpecs do
34
34
  end
35
35
 
36
36
  it "run bundle exec spec when on bundler 0.9" do
37
- File.stub!(:file?).with('.bundle/environment.rb').and_return true
37
+ ParallelSpecs.stub!(:bundler_enabled?).and_return true
38
38
  ParallelSpecs.should_receive(:open).with{|x,y| x =~ %r{bundle exec spec}}.and_return mock(:getc=>false)
39
39
  ParallelSpecs.run_tests(['xxx'],1,'')
40
40
  end
@@ -11,7 +11,7 @@ describe ParallelTests do
11
11
 
12
12
  it "should default to the prefix" do
13
13
  args = {:count => "models"}
14
- ParallelTests.parse_rake_args(args).should == [2, "models", ""]
14
+ ParallelTests.parse_rake_args(args).should == [Parallel.processor_count, "models", ""]
15
15
  end
16
16
 
17
17
  it "should return the count and prefix" do
@@ -137,6 +137,35 @@ EOF
137
137
  end
138
138
  end
139
139
 
140
+ describe :bundler_enabled? do
141
+ it "should return false" do
142
+ use_temporary_directory_for do
143
+ ParallelTests.send(:bundler_enabled?).should == false
144
+ end
145
+ end
146
+
147
+ it "should return true when there is a constant called Bundler" do
148
+ use_temporary_directory_for do
149
+ Object.stub!(:const_defined?).with(:Bundler).and_return true
150
+ ParallelTests.send(:bundler_enabled?).should == true
151
+ end
152
+ end
153
+
154
+ it "should be true when there is a Gemfile" do
155
+ use_temporary_directory_for do
156
+ FileUtils.touch("Gemfile")
157
+ ParallelTests.send(:bundler_enabled?).should == true
158
+ end
159
+ end
160
+
161
+ it "should be true when there is a Gemfile in the parent directory" do
162
+ use_temporary_directory_for do
163
+ FileUtils.touch(File.join("..", "Gemfile"))
164
+ ParallelTests.send(:bundler_enabled?).should == true
165
+ end
166
+ end
167
+ end
168
+
140
169
  it "has a version" do
141
170
  ParallelTests::VERSION.should =~ /^\d+\.\d+\.\d+$/
142
171
  end
data/spec/spec_helper.rb CHANGED
@@ -11,6 +11,28 @@ def size_of(group)
11
11
  group.inject(0) { |sum, test| sum += File.stat(test).size }
12
12
  end
13
13
 
14
+ # Uses /tmp/parallel_tests/application as the cwd so we can create and remove
15
+ # files as we want to. After execution it changes cwd back to the original one.
16
+ def use_temporary_directory_for
17
+ dir = File.join("/tmp", "parallel_tests")
18
+ new_dir = File.join(dir, "application")
19
+
20
+ begin
21
+ # just in case the temporary dir already exists
22
+ FileUtils.rm_rf(dir) if File.exists?(dir)
23
+
24
+ # create the temporary directory
25
+ FileUtils.mkdir_p(new_dir)
26
+
27
+ # chdir changes cwd back to the original one after it is done
28
+ Dir.chdir(new_dir) do
29
+ yield
30
+ end
31
+ ensure
32
+ FileUtils.rm_rf(dir) if File.exists?(dir)
33
+ end
34
+ end
35
+
14
36
  def test_tests_in_groups(klass, folder, suffix)
15
37
  test_root = "#{FAKE_RAILS_ROOT}/#{folder}"
16
38
 
@@ -79,4 +101,4 @@ def test_tests_in_groups(klass, folder, suffix)
79
101
  groups[1].should == ["file2.rb", "file4.rb"]
80
102
  end
81
103
  end
82
- end
104
+ end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 4
8
- - 1
9
- version: 0.4.1
8
+ - 2
9
+ version: 0.4.2
10
10
  platform: ruby
11
11
  authors:
12
12
  - Michael Grosser