spec_tiller 1.1.0 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e9b13142ceda1474ca093cd92a29fb161ea83642
4
- data.tar.gz: 45db628b9fff9bc1c00457343564c995b4599fbd
3
+ metadata.gz: b52ba79a8f884b6a06ebbb64bbd10c0abc46efd3
4
+ data.tar.gz: ae6e9591d97e21148890c91995047b021f8eb73b
5
5
  SHA512:
6
- metadata.gz: c8fecb888fa57185e06e798c688d6f897ebbfc4339b9fb9f57a1e43f84c41bf5859a8f76f74a807841d69c85c6a8f154fa89fe504f449df752ca5a532b533655
7
- data.tar.gz: 0101f1acd5dc9af7ffdb0c2e033310ed942dfde104fd89965cbc55a32b819b13c96c998a2fe2174f109c864fcf8543ae6a8d8d86825dbfd50d50d47704e3b88a
6
+ metadata.gz: 748cc635596d90d335c48383439e32a2851ef8dba2fc73ffdce62e8df77e23988335e2e8302a1f163b4d797f1ee710bf26e12b4f624a56fb9a50f803dd3c2398
7
+ data.tar.gz: 8f8f6e270ad776cca46a98ba53dbe59a6f843e0920db184e13d0f7a6ffcc81cdc45d701bfd322f7e36fd7b8159d1c813d2fa14cc382aebf3bb1118e8a90d5c2c
data/.gitignore CHANGED
@@ -15,3 +15,4 @@ spec/reports
15
15
  test/tmp
16
16
  test/version_tmp
17
17
  tmp
18
+ .idea/
data/README.md CHANGED
@@ -30,7 +30,7 @@ Upon setting this up, any time you commit or merge, you'll notice the following
30
30
  Added: [spec/file/added_spec.rb, spec/file/another_added_spec.rb]
31
31
 
32
32
  ####.travis.yml
33
- In your ``.travis.yml`` file, create a top-level variable **num_builds** and set it to the number of builds you want the spec files distributed over (deafult value is 5 builds). You must also make sure that the base of your script is as follows:
33
+ In your ``.travis.yml`` file, create a top-level variable **num_builds** and set it to the number of builds you want the spec files distributed over (default value is 5 builds). You must also make sure that the base of your script is as follows:
34
34
 
35
35
  bundle exec rspec $TEST_SUITE
36
36
 
@@ -62,6 +62,7 @@ Here is an example of what a ``.travis.yml`` file may look like after all is sai
62
62
  env:
63
63
  global:
64
64
  - SOME_OTHER_ENV_VAR="hello world"
65
+ - IGNORE_SPECS="spec/path/file_thirteen_spec.rb spec/path/file_fourteen_spec.rb"
65
66
  matrix:
66
67
  - TEST_SUITE="spec/path/file_one_spec.rb spec/path/file_two_spec.rb spec/path/file_three_spec.rb"
67
68
  - TEST_SUITE="spec/path/file_four_spec.rb"
@@ -76,6 +77,10 @@ Initially, and every so often, you will have to redistribute the spec files (mak
76
77
  spec_tiller:redistribute
77
78
 
78
79
  This will run your whole test suite, keeping track of how long each spec file takes to run, and the will distribute the spec files in order to maximize your test suite's run time, over the number of builds you've designated (with a default value of 5). **This rake task will not print the output of the rake task until it is complete.**
80
+
81
+ #### Ignoring Files
82
+ By default, both sync and redistribute will look for any tests following the "spec/**/*_spec.rb" pattern. If you want the tasks to ignore any specs, you can add the IGNORE_SPECS variable to your global variables. The value should be the patterns or specs you want to exclude, separated by spaces.
83
+
79
84
  ***
80
85
  ## Feature Requests & Bugs
81
86
  See [http://github.com/grnhse/spec-tiller/issues](http://github.com/grnhse/spec-tiller/issues)
@@ -1,23 +1,5 @@
1
- require 'rake'
2
1
  require 'yaml'
3
2
 
4
- namespace :spec_tiller do
5
- desc 'Runs whole test suite and redistributes spec files across builds according to file run time'
6
- task :redistribute => :environment do
7
- travis_yml_file = YAML::load(File.open('.travis.yml'))
8
- env_variables = travis_yml_file['env']['global']
9
- script = travis_yml_file['script'].first.gsub('$TEST_SUITE ', '')
10
-
11
- profile_results = `#{env_variables.join(' ')} #{script} --profile 1000000000`
12
-
13
- `echo "#{profile_results}" > spec/log/rspec_profile_output.txt`
14
- TravisBuildMatrix::SpecDistributor.new(travis_yml_file, profile_results) do |content|
15
- File.open('.travis.yml', 'w') { |file| file.write(content.to_yaml(:line_width => -1)) }
16
- end
17
- puts profile_results
18
- end
19
- end
20
-
21
3
  module TravisBuildMatrix
22
4
 
23
5
  DEFAULT_NUM_BUILDS = 5
@@ -1,27 +1,11 @@
1
- require 'rake'
2
1
  require 'yaml'
3
2
 
4
- namespace :spec_tiller do
5
- desc 'Compares spec files in travis.yml to current list of spec files, and syncs accordingly'
6
- task :sync do
7
- content = YAML::load(File.open('.travis.yml'))
8
- current_file_list = Dir.glob('spec/**/*_spec.rb').map { |file_path| file_path.slice(/(spec\/\S+$)/) }
9
-
10
- puts "\nSyncing list of spec files..."
11
-
12
- SyncSpecFiles.rewrite_travis_content(content, current_file_list) do |original|
13
- write_to_file(content)
14
- puts file_diff(original, current_file_list)
15
- end
16
-
17
- `git add .travis.yml`
18
- end
19
- end
20
-
21
3
  module SyncSpecFiles
22
4
  include BuildMatrixParser
23
5
 
24
6
  def rewrite_travis_content(content, current_file_list, &block)
7
+ ignore_specs = get_ignored_specs(content)
8
+ current_file_list = current_file_list.reject { |file_path| ignore_specs.include?(file_path) }
25
9
  env_matrix = BuildMatrixParser.parse_env_matrix(content)
26
10
  original = extract_spec_files(env_matrix)
27
11
  after_removed = delete_removed_files(original, current_file_list)
@@ -37,11 +21,22 @@ module SyncSpecFiles
37
21
 
38
22
  content['env']['matrix'] = BuildMatrixParser.format_matrix(env_matrix)
39
23
 
40
- block.call(original) if block
24
+ block.call(content, original, current_file_list) if block
41
25
  end
42
26
 
43
27
  module_function :rewrite_travis_content
44
28
 
29
+ def self.get_ignored_specs(content)
30
+ ignore_specs = []
31
+ content['env']['global'].each do |row|
32
+ # Input: IGNORE_SPECS="spec/a.rb spec/b.rb"
33
+ # Output: ['spec/a.rb spec/b.rb']
34
+ matches = row.match(/IGNORE_SPECS="\s*([^"]+)"/)
35
+ ignore_specs << matches[1].split(' ') unless matches.nil?
36
+ end
37
+ ignore_specs.flatten
38
+ end
39
+
45
40
  private
46
41
 
47
42
  def self.extract_spec_files(env_matrix)
@@ -77,10 +72,6 @@ module SyncSpecFiles
77
72
  current_file_list - original.flatten
78
73
  end
79
74
 
80
- def self.write_to_file(content)
81
- File.open('.travis.yml', 'w') { |file| file.write(content.to_yaml(:line_width => -1)) }
82
- end
83
-
84
75
  def self.file_diff(original, current_file_list)
85
76
  removed_files = deleted_files(original, current_file_list).sort
86
77
  removed = removed_files.empty? ? 'No spec files removed' : removed_files
@@ -1,3 +1,3 @@
1
1
  module SpecTiller
2
- VERSION = '1.1.0'
2
+ VERSION = '1.1.1'
3
3
  end
@@ -0,0 +1,36 @@
1
+ namespace :spec_tiller do
2
+ desc 'Compares spec files in travis.yml to current list of spec files, and syncs accordingly'
3
+ task :sync do
4
+ content = YAML::load(File.open('.travis.yml'))
5
+ current_file_list = Dir.glob('spec/**/*_spec.rb').map { |file_path| file_path.slice(/(spec\/\S+$)/) }
6
+
7
+ puts "\nSyncing list of spec files..."
8
+
9
+ SyncSpecFiles.rewrite_travis_content(content, current_file_list) do |content, original, current_file_list|
10
+ File.open('.travis.yml', 'w') { |file| file.write(content.to_yaml(:line_width => -1)) }
11
+ puts SyncSpecFiles.file_diff(original, current_file_list)
12
+ end
13
+
14
+ `git add .travis.yml`
15
+ end
16
+
17
+ desc 'Runs whole test suite and redistributes spec files across builds according to file run time'
18
+ task :redistribute => :environment do
19
+ travis_yml_file = YAML::load(File.open('.travis.yml'))
20
+ env_variables = travis_yml_file['env']['global']
21
+ script = travis_yml_file['script'].first.gsub('$TEST_SUITE ', '')
22
+
23
+ ignore_specs = SyncSpecFiles.get_ignored_specs(travis_yml_file).map { |spec| %Q("#{spec}") }
24
+ script += %Q( --exclude-pattern #{ignore_specs.join(',')}) unless ignore_specs.empty?
25
+
26
+ profile_results = `#{env_variables.join(' ')} #{script} --profile 1000000000`
27
+
28
+ `echo "#{profile_results}" > spec/log/rspec_profile_output.txt`
29
+ TravisBuildMatrix::SpecDistributor.new(travis_yml_file, profile_results) do |content|
30
+ File.open('.travis.yml', 'w') { |file| file.write(content.to_yaml(:line_width => -1)) }
31
+ end
32
+
33
+ puts profile_results
34
+ end
35
+
36
+ end
@@ -25,6 +25,7 @@ script:
25
25
  env:
26
26
  global:
27
27
  - RUBY_GC_HEAP_OLDOBJECT_LIMIT_FACTOR=1.1
28
+ - IGNORE_SPECS="spec/features/ignore_me.rb"
28
29
  matrix:
29
30
  - TEST_SUITE="spec/features/three_vars.rb" RUN_JS="true" FAKE_VAR="fake.value.rb"
30
31
  - TEST_SUITE="spec/features/space_after.rb spec/features/space_before.rb" FIVE_TABS_BEFORE="tabs are ignored"
@@ -0,0 +1,31 @@
1
+ ---
2
+ language: ruby
3
+ rvm:
4
+ - 2.1.2
5
+ addons:
6
+ hosts:
7
+ - example.com
8
+ branches:
9
+ only:
10
+ - develop
11
+ - master
12
+ - "/^release\\/.*$/"
13
+ - "/^hotfix\\/.*$/"
14
+ - "/^feature\\/testing-.+$/"
15
+ cache: bundler
16
+ before_install:
17
+ - export DISPLAY=:99.0
18
+ - "/sbin/start-stop-daemon --start --quiet --pidfile /tmp/custom_xvfb_99.pid --make-pidfile --background --exec /usr/bin/Xvfb -- :99 -ac -screen 0 1920x1080x16"
19
+ before_script:
20
+ - psql -c 'create database test;' -U postgres
21
+ - RAILS_ENV=test bundle exec rake --trace db:test:load db:seed
22
+ script:
23
+ - RSPEC_RETRY_COUNT=2 bundle exec rspec --pattern "spec/documents/*_spec.rb" $TEST_SUITE --tag ~local_only
24
+ env:
25
+ global:
26
+ - RUBY_GC_HEAP_OLDOBJECT_LIMIT_FACTOR=1.1
27
+ - IGNORE_SPECS="spec/documents/iterator5_spec.rb"
28
+ matrix:
29
+ - TEST_SUITE="spec/documents/iterator2_spec.rb"
30
+ - TEST_SUITE="spec/documents/iterator1_spec.rb spec/documents/iterator4_spec.rb spec/documents/iterator3_spec.rb"
31
+ num_builds: 2
@@ -0,0 +1,23 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Iterator1' do
4
+ let(:a) { Array.new(1000000) }
5
+
6
+ it 'iterates 1000000 times' do
7
+ i = 0
8
+ a.each { i += 1 }
9
+ expect(i).to eq(1000000)
10
+ end
11
+
12
+ it 'compares 1000000 times' do
13
+ a.each do
14
+ expect(1).to eq(1)
15
+ end
16
+ end
17
+
18
+ it 'compares 1000000 more times' do
19
+ a.each do
20
+ expect(1).to_not eq(2)
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,23 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Iterator2' do
4
+ let(:a) { Array.new(2000000) }
5
+
6
+ it 'iterates 2000000 times' do
7
+ i = 0
8
+ a.each { i += 1 }
9
+ expect(i).to eq(2000000)
10
+ end
11
+
12
+ it 'compares 2000000 times' do
13
+ a.each do
14
+ expect(1).to eq(1)
15
+ end
16
+ end
17
+
18
+ it 'compares 2000000 more times' do
19
+ a.each do
20
+ expect(1).to_not eq(2)
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,23 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Iterator3' do
4
+ let(:a) { Array.new(1000) }
5
+
6
+ it 'iterates 1000 times' do
7
+ i = 0
8
+ a.each { i += 1 }
9
+ expect(i).to eq(1000)
10
+ end
11
+
12
+ it 'compares 1000 times' do
13
+ a.each do
14
+ expect(1).to eq(1)
15
+ end
16
+ end
17
+
18
+ it 'compares 1000 more times' do
19
+ a.each do
20
+ expect(1).to_not eq(2)
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,23 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Iterator4' do
4
+ let(:a) { Array.new(20000) }
5
+
6
+ it 'iterates 20000 times' do
7
+ i = 0
8
+ a.each { i += 1 }
9
+ expect(i).to eq(20000)
10
+ end
11
+
12
+ it 'compares 20000 times' do
13
+ a.each do
14
+ expect(1).to eq(1)
15
+ end
16
+ end
17
+
18
+ it 'compares 20000 more times' do
19
+ a.each do
20
+ expect(1).to_not eq(2)
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,23 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Iterator1' do
4
+ let(:a) { Array.new(300000) }
5
+
6
+ it 'iterates 300000 times' do
7
+ i = 0
8
+ a.each { i += 1 }
9
+ expect(i).to eq(300000)
10
+ end
11
+
12
+ it 'compares 300000 times' do
13
+ a.each do
14
+ expect(1).to eq(1)
15
+ end
16
+ end
17
+
18
+ it 'compares 300000 more times' do
19
+ a.each do
20
+ expect(1).to_not eq(2)
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,26 @@
1
+ # From http://robots.thoughtbot.com/test-rake-tasks-like-a-boss and
2
+ require 'rake'
3
+
4
+ shared_context 'rake' do
5
+ let(:rake) { Rake::Application.new }
6
+ let(:task_name) { self.class.top_level_description }
7
+ let(:task_path) { "lib/tasks/#{task_name.split(":").first}" }
8
+ subject(:task) { rake[task_name] }
9
+
10
+ def loaded_files_excluding_current_rake_file
11
+ $".reject { |file| file == [Dir.pwd].join("#{task_path}.rake").to_s }
12
+ end
13
+
14
+ before(:each) do
15
+ original_open = File.method(:open)
16
+ allow(File).to receive(:open) do |file_name, options, &block|
17
+ file_name = 'spec/documents/.travis2.yml' if file_name == '.travis.yml'
18
+ original_open.call(file_name, options, &block)
19
+ end
20
+
21
+ Rake.application = rake
22
+ Rake.application.rake_require(task_path, [Dir.pwd], loaded_files_excluding_current_rake_file)
23
+
24
+ Rake::Task.define_task(:environment)
25
+ end
26
+ end
@@ -7,6 +7,7 @@ describe 'SyncSpecFiles' do
7
7
 
8
8
  let(:current_file_list) do
9
9
  ['spec/test/new3.rb',
10
+ 'spec/features/ignore_me.rb',
10
11
  'spec/features/space_after.rb', 'spec/features/space_before.rb',
11
12
  'spec/test/test1.rb', 'spec/test/test2.rb', 'spec/test/test3.rb', 'spec/test/test4.rb', 'spec/test/test5.rb', 'spec/test/test6.rb', 'spec/test/test7.rb', 'spec/test/test8.rb', 'spec/test/test9.rb', 'spec/test/test10.rb', 'spec/test/test11.rb', 'spec/test/test12.rb', 'spec/test/test13.rb', 'spec/test/test14.rb', 'spec/test/test15.rb', 'spec/test/test16.rb',
12
13
  'spec/test/new1.rb', 'spec/test2/new2.rb']
@@ -43,6 +44,13 @@ describe 'SyncSpecFiles' do
43
44
  expect(travis_yaml['env']['matrix'].length).to eq(2)
44
45
  end
45
46
 
47
+ it 'does not include ignored specs' do
48
+ travis_yaml['env']['matrix'].each do |bucket|
49
+ expect(bucket).not_to include('spec/features/ignore_me.rb')
50
+ end
51
+
52
+ end
53
+
46
54
  end
47
55
 
48
56
  end
@@ -0,0 +1,58 @@
1
+ require 'spec_helper'
2
+ require 'support/shared_contexts/rake'
3
+ require 'yaml'
4
+
5
+ describe 'spec_tiller:sync' do
6
+ include_context('rake')
7
+ before(:each) do
8
+ original_glob = Dir.method(:glob)
9
+ allow(Dir).to receive(:glob) do |pattern|
10
+ pattern = 'spec/documents/*_spec.rb' if pattern == 'spec/**/*_spec.rb'
11
+ original_glob.call(pattern)
12
+ end
13
+ end
14
+
15
+ it 'adds new files to last line' do
16
+ temp_file_name = 'spec/documents/new_added_spec.rb'
17
+ File.new(temp_file_name, 'w')
18
+ content_at_start = YAML::load(File.open('.travis.yml'))
19
+
20
+ task.invoke
21
+ content_at_end = YAML::load(File.open('.travis.yml'))
22
+ expect(content_at_end['env']['matrix'].last).to include(temp_file_name)
23
+
24
+ # Clean up added file and travis.yml
25
+ File.delete(temp_file_name)
26
+ File.open('.travis.yml', 'w') { |file| file.write(content_at_start.to_yaml(:line_width => -1)) }
27
+ end
28
+
29
+ it 'removes non-existent files' do
30
+ temp_file_name = 'spec/documents/old_removed_spec.rb'
31
+ content_at_start = YAML::load(File.open('.travis.yml'))
32
+ content_at_start['env']['matrix'] << %Q(TEST_SUITE="#{temp_file_name}")
33
+ File.open('.travis.yml', 'w') { |file| file.write(content_at_start.to_yaml(:line_width => -1)) }
34
+
35
+ task.invoke
36
+ content_at_end = YAML::load(File.open('.travis.yml'))
37
+
38
+ content_at_end['env']['matrix'].each do |bucket|
39
+ expect(bucket).to_not include(temp_file_name)
40
+ end
41
+
42
+ end
43
+
44
+ end
45
+
46
+ describe 'spec_tiller:redistribute' do
47
+ include_context('rake')
48
+
49
+ it 'distributes evenly based on run time' do
50
+ content_at_start = YAML::load(File.open('.travis.yml'))
51
+ task.invoke
52
+ content_at_end = YAML::load(File.open('.travis.yml'))
53
+
54
+ expect(content_at_end['env']['matrix']).to eq(content_at_start['env']['matrix'])
55
+ expect(content_at_end['env']['matrix'].length).to eq(2)
56
+ end
57
+
58
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spec_tiller
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Schmaus
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-11-20 00:00:00.000000000 Z
12
+ date: 2014-11-26 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -74,12 +74,21 @@ files:
74
74
  - lib/spec_tiller/distribute_spec_files.rb
75
75
  - lib/spec_tiller/sync_spec_file_list.rb
76
76
  - lib/spec_tiller/version.rb
77
+ - lib/tasks/spec_tiller.rake
77
78
  - spec/build_matrix_parser_spec.rb
78
79
  - spec/distribute_spec_files_spec.rb
79
80
  - spec/documents/.travis.yml
81
+ - spec/documents/.travis2.yml
82
+ - spec/documents/iterator1_spec.rb
83
+ - spec/documents/iterator2_spec.rb
84
+ - spec/documents/iterator3_spec.rb
85
+ - spec/documents/iterator4_spec.rb
86
+ - spec/documents/iterator5_spec.rb
80
87
  - spec/documents/rspec_profile_results.txt
81
88
  - spec/spec_helper.rb
89
+ - spec/support/shared_contexts/rake.rb
82
90
  - spec/sync_spec_file_list_spec.rb
91
+ - spec/tasks/spec_tiller_rake_spec.rb
83
92
  - spec_tiller.gemspec
84
93
  homepage: ''
85
94
  licenses:
@@ -109,6 +118,14 @@ test_files:
109
118
  - spec/build_matrix_parser_spec.rb
110
119
  - spec/distribute_spec_files_spec.rb
111
120
  - spec/documents/.travis.yml
121
+ - spec/documents/.travis2.yml
122
+ - spec/documents/iterator1_spec.rb
123
+ - spec/documents/iterator2_spec.rb
124
+ - spec/documents/iterator3_spec.rb
125
+ - spec/documents/iterator4_spec.rb
126
+ - spec/documents/iterator5_spec.rb
112
127
  - spec/documents/rspec_profile_results.txt
113
128
  - spec/spec_helper.rb
129
+ - spec/support/shared_contexts/rake.rb
114
130
  - spec/sync_spec_file_list_spec.rb
131
+ - spec/tasks/spec_tiller_rake_spec.rb