knapsack_pro 0.14.0 → 0.15.0

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: e7b7869def18504a9c41c6bae22b4ab188fd4101
4
- data.tar.gz: 93e72ce429f519ccc6c55ab483e73c8b1dca9510
3
+ metadata.gz: ef44ff94f42a889b3f6cc1d896d484237b6a88f1
4
+ data.tar.gz: 5a5485e24f6ea5498382cc220578106f27760760
5
5
  SHA512:
6
- metadata.gz: af07b77b591317891a261dd6b77eacb769dcfb32fdf5072763f81d8787204662aaefe456e95186fcdacac306b98bd2ae62843104d2d2ae2e34ac1a7a611760dd
7
- data.tar.gz: 937a91770dd1e0325036f67ab32a4203cd4ffcf93d4b1e7a8e890537182973fac5129120ef99b2a62d1e16ec51a15fd4e89d3ece66575494d97ea74bf2b28bca
6
+ metadata.gz: 59e8f09d9bd4c317ffc7edf9308aa13848cbe615bfab4b881ac1ddad32b83ab29d7df765c193fafc44c60fd892b64e7651feedd083f3cc22d8daac8591cc01f2
7
+ data.tar.gz: c3bac7fff236e23715bffa05468cfd5c85663953acce36ba23b189e4295ae32bd78c9759beb69ba2578d59a9092d42996712ab3bdea15dbb3f2192ecd7206c66
@@ -2,6 +2,14 @@
2
2
 
3
3
  * TODO
4
4
 
5
+ ### 0.15.0
6
+
7
+ * Handle case when API returns no test files to execute on the node.
8
+
9
+ https://github.com/KnapsackPro/knapsack_pro-ruby/pull/19
10
+
11
+ https://github.com/KnapsackPro/knapsack_pro-ruby/compare/v0.14.0...v0.15.0
12
+
5
13
  ### 0.14.0
6
14
 
7
15
  * Use rake invoke for rspec and cucumber tasks.
@@ -22,6 +22,15 @@ module KnapsackPro
22
22
  allocator_builder.test_dir
23
23
  end
24
24
 
25
+ def test_files_to_execute_exist?
26
+ if test_file_paths.empty?
27
+ KnapsackPro.logger.info("Knapsack Pro API returned no test files to execute for the node this time. The reason might be that you changed recently a number of total nodes or you removed some test files. Please create a new commit to get a better test suite split next time.")
28
+ false
29
+ else
30
+ true
31
+ end
32
+ end
33
+
25
34
  private
26
35
 
27
36
  attr_reader :allocator_builder,
@@ -7,17 +7,19 @@ module KnapsackPro
7
7
 
8
8
  runner = new(KnapsackPro::Adapters::CucumberAdapter)
9
9
 
10
- require 'cucumber/rake/task'
10
+ if runner.test_files_to_execute_exist?
11
+ require 'cucumber/rake/task'
11
12
 
12
- task_name = 'knapsack_pro:cucumber_run'
13
- if Rake::Task.task_defined?(task_name)
14
- Rake::Task[task_name].clear
15
- end
13
+ task_name = 'knapsack_pro:cucumber_run'
14
+ if Rake::Task.task_defined?(task_name)
15
+ Rake::Task[task_name].clear
16
+ end
16
17
 
17
- Cucumber::Rake::Task.new(task_name) do |t|
18
- t.cucumber_opts = "#{args} --require #{runner.test_dir} -- #{runner.stringify_test_file_paths}"
18
+ Cucumber::Rake::Task.new(task_name) do |t|
19
+ t.cucumber_opts = "#{args} --require #{runner.test_dir} -- #{runner.stringify_test_file_paths}"
20
+ end
21
+ Rake::Task[task_name].invoke
19
22
  end
20
- Rake::Task[task_name].invoke
21
23
  end
22
24
  end
23
25
  end
@@ -7,20 +7,22 @@ module KnapsackPro
7
7
 
8
8
  runner = new(KnapsackPro::Adapters::MinitestAdapter)
9
9
 
10
- task_name = 'knapsack_pro:minitest_run'
10
+ if runner.test_files_to_execute_exist?
11
+ task_name = 'knapsack_pro:minitest_run'
11
12
 
12
- if Rake::Task.task_defined?(task_name)
13
- Rake::Task[task_name].clear
14
- end
13
+ if Rake::Task.task_defined?(task_name)
14
+ Rake::Task[task_name].clear
15
+ end
15
16
 
16
- Rake::TestTask.new(task_name) do |t|
17
- t.warning = false
18
- t.libs << runner.test_dir
19
- t.test_files = runner.test_file_paths
20
- t.options = args
21
- end
17
+ Rake::TestTask.new(task_name) do |t|
18
+ t.warning = false
19
+ t.libs << runner.test_dir
20
+ t.test_files = runner.test_file_paths
21
+ t.options = args
22
+ end
22
23
 
23
- Rake::Task[task_name].invoke
24
+ Rake::Task[task_name].invoke
25
+ end
24
26
  end
25
27
  end
26
28
  end
@@ -7,18 +7,20 @@ module KnapsackPro
7
7
 
8
8
  runner = new(KnapsackPro::Adapters::RSpecAdapter)
9
9
 
10
- require 'rspec/core/rake_task'
10
+ if runner.test_files_to_execute_exist?
11
+ require 'rspec/core/rake_task'
11
12
 
12
- task_name = 'knapsack_pro:rspec_run'
13
- if Rake::Task.task_defined?(task_name)
14
- Rake::Task[task_name].clear
15
- end
13
+ task_name = 'knapsack_pro:rspec_run'
14
+ if Rake::Task.task_defined?(task_name)
15
+ Rake::Task[task_name].clear
16
+ end
16
17
 
17
- RSpec::Core::RakeTask.new(task_name) do |t|
18
- t.rspec_opts = "#{args} --default-path #{runner.test_dir}"
19
- t.pattern = runner.test_file_paths
18
+ RSpec::Core::RakeTask.new(task_name) do |t|
19
+ t.rspec_opts = "#{args} --default-path #{runner.test_dir}"
20
+ t.pattern = runner.test_file_paths
21
+ end
22
+ Rake::Task[task_name].invoke
20
23
  end
21
- Rake::Task[task_name].invoke
22
24
  end
23
25
  end
24
26
  end
@@ -6,10 +6,12 @@ module KnapsackPro
6
6
 
7
7
  runner = new(KnapsackPro::Adapters::SpinachAdapter)
8
8
 
9
- cmd = %Q[KNAPSACK_PRO_RECORDING_ENABLED=true KNAPSACK_PRO_TEST_SUITE_TOKEN=#{ENV['KNAPSACK_PRO_TEST_SUITE_TOKEN']} bundle exec spinach #{args} --features_path #{runner.test_dir} -- #{runner.stringify_test_file_paths}]
9
+ if runner.test_files_to_execute_exist?
10
+ cmd = %Q[KNAPSACK_PRO_RECORDING_ENABLED=true KNAPSACK_PRO_TEST_SUITE_TOKEN=#{ENV['KNAPSACK_PRO_TEST_SUITE_TOKEN']} bundle exec spinach #{args} --features_path #{runner.test_dir} -- #{runner.stringify_test_file_paths}]
10
11
 
11
- Kernel.system(cmd)
12
- Kernel.exit($?.exitstatus) unless $?.exitstatus.zero?
12
+ Kernel.system(cmd)
13
+ Kernel.exit($?.exitstatus) unless $?.exitstatus.zero?
14
+ end
13
15
  end
14
16
  end
15
17
  end
@@ -1,3 +1,3 @@
1
1
  module KnapsackPro
2
- VERSION = '0.14.0'
2
+ VERSION = '0.15.0'
3
3
  end
@@ -57,5 +57,31 @@ describe KnapsackPro::Runners::BaseRunner do
57
57
 
58
58
  it { should eq test_dir }
59
59
  end
60
+
61
+ describe '#test_files_to_execute_exist?' do
62
+ subject { runner.test_files_to_execute_exist? }
63
+
64
+ before do
65
+ expect(runner).to receive(:test_file_paths).and_return(test_file_paths)
66
+ end
67
+
68
+ context 'when test files exists' do
69
+ let(:test_file_paths) { ['a_spec.rb'] }
70
+
71
+ it { should be true }
72
+ end
73
+
74
+ context "when test files doesn't exist" do
75
+ let(:test_file_paths) { [] }
76
+
77
+ before do
78
+ logger = instance_double(Logger)
79
+ expect(KnapsackPro).to receive(:logger).and_return(logger)
80
+ expect(logger).to receive(:info).with("Knapsack Pro API returned no test files to execute for the node this time. The reason might be that you changed recently a number of total nodes or you removed some test files. Please create a new commit to get a better test suite split next time.")
81
+ end
82
+
83
+ it { should be false }
84
+ end
85
+ end
60
86
  end
61
87
  end
@@ -1,3 +1,5 @@
1
+ require 'cucumber/rake/task'
2
+
1
3
  describe KnapsackPro::Runners::CucumberRunner do
2
4
  subject { described_class.new(KnapsackPro::Adapters::CucumberAdapter) }
3
5
 
@@ -6,41 +8,74 @@ describe KnapsackPro::Runners::CucumberRunner do
6
8
  describe '.run' do
7
9
  let(:args) { '--custom-arg' }
8
10
 
9
- after { described_class.run(args) }
11
+ let(:test_suite_token_cucumber) { 'fake-token' }
12
+
13
+ subject { described_class.run(args) }
10
14
 
11
15
  before do
12
- stub_const("ENV", { 'KNAPSACK_PRO_TEST_SUITE_TOKEN_CUCUMBER' => 'cucumber-token' })
16
+ expect(KnapsackPro::Config::Env).to receive(:test_suite_token_cucumber).and_return(test_suite_token_cucumber)
17
+
18
+ expect(ENV).to receive(:[]=).with('KNAPSACK_PRO_TEST_SUITE_TOKEN', test_suite_token_cucumber)
19
+ expect(ENV).to receive(:[]=).with('KNAPSACK_PRO_RECORDING_ENABLED', 'true')
13
20
 
14
- stringify_test_file_paths = 'features/a.feature features/b.feature'
15
- runner = instance_double(described_class,
16
- stringify_test_file_paths: stringify_test_file_paths)
17
21
  expect(described_class).to receive(:new)
18
22
  .with(KnapsackPro::Adapters::CucumberAdapter).and_return(runner)
19
-
20
- expect(Kernel).to receive(:system).with('KNAPSACK_PRO_RECORDING_ENABLED=true KNAPSACK_PRO_TEST_SUITE_TOKEN=cucumber-token bundle exec cucumber --custom-arg -- features/a.feature features/b.feature')
21
23
  end
22
24
 
23
- context 'when command exit with success code' do
24
- let(:exitstatus) { 0 }
25
+ context 'when test files were returned by Knapsack Pro API' do
26
+ let(:test_dir) { 'fake-test-dir' }
27
+ let(:stringify_test_file_paths) { 'features/fake1.scenario features/fake2.scenario' }
28
+ let(:runner) do
29
+ instance_double(described_class,
30
+ test_dir: test_dir,
31
+ stringify_test_file_paths: stringify_test_file_paths,
32
+ test_files_to_execute_exist?: true)
33
+ end
34
+ let(:task) { double }
25
35
 
26
36
  before do
27
- expect($?).to receive(:exitstatus).and_return(exitstatus)
37
+ expect(Rake::Task).to receive(:[]).with('knapsack_pro:cucumber_run').at_least(1).and_return(task)
38
+
39
+ t = double
40
+ expect(Cucumber::Rake::Task).to receive(:new).with('knapsack_pro:cucumber_run').and_yield(t)
41
+ expect(t).to receive(:cucumber_opts=).with('--custom-arg --require fake-test-dir -- features/fake1.scenario features/fake2.scenario')
28
42
  end
29
43
 
30
- it do
31
- expect(Kernel).not_to receive(:exit)
44
+ context 'when task already exists' do
45
+ before do
46
+ expect(Rake::Task).to receive(:task_defined?).with('knapsack_pro:cucumber_run').and_return(true)
47
+ expect(task).to receive(:clear)
48
+ end
49
+
50
+ it do
51
+ result = double(:result)
52
+ expect(task).to receive(:invoke).and_return(result)
53
+ expect(subject).to eq result
54
+ end
32
55
  end
33
- end
34
56
 
35
- context 'when command exit without success code' do
36
- let(:exitstatus) { 1 }
57
+ context "when task doesn't exist" do
58
+ before do
59
+ expect(Rake::Task).to receive(:task_defined?).with('knapsack_pro:cucumber_run').and_return(false)
60
+ expect(task).not_to receive(:clear)
61
+ end
37
62
 
38
- before do
39
- expect($?).to receive(:exitstatus).twice.and_return(exitstatus)
63
+ it do
64
+ result = double(:result)
65
+ expect(task).to receive(:invoke).and_return(result)
66
+ expect(subject).to eq result
67
+ end
68
+ end
69
+ end
70
+
71
+ context 'when test files were not returned by Knapsack Pro API' do
72
+ let(:runner) do
73
+ instance_double(described_class,
74
+ test_files_to_execute_exist?: false)
40
75
  end
41
76
 
42
- it do
43
- expect(Kernel).to receive(:exit).with(exitstatus)
77
+ it "doesn't run tests" do
78
+ subject
44
79
  end
45
80
  end
46
81
  end
@@ -13,22 +13,36 @@ describe KnapsackPro::Runners::MinitestRunner do
13
13
  stub_const("ENV", { 'KNAPSACK_PRO_TEST_SUITE_TOKEN_MINITEST' => 'minitest-token' })
14
14
  end
15
15
 
16
- it do
17
- test_file_paths = ['test_fake/a_test.rb', 'test_fake/b_test.rb']
18
- runner = instance_double(described_class,
19
- test_dir: 'test',
20
- test_file_paths: test_file_paths)
21
- expect(described_class).to receive(:new)
22
- .with(KnapsackPro::Adapters::MinitestAdapter).and_return(runner)
16
+ context 'when test files were returned by Knapsack Pro API' do
17
+ it 'runs tests' do
18
+ test_file_paths = ['test_fake/a_test.rb', 'test_fake/b_test.rb']
19
+ runner = instance_double(described_class,
20
+ test_dir: 'test',
21
+ test_file_paths: test_file_paths,
22
+ test_files_to_execute_exist?: true)
23
+ expect(described_class).to receive(:new)
24
+ .with(KnapsackPro::Adapters::MinitestAdapter).and_return(runner)
23
25
 
24
- expect(Rake::Task.task_defined?(task_name)).to be false
26
+ expect(Rake::Task.task_defined?(task_name)).to be false
25
27
 
26
- subject
28
+ subject
27
29
 
28
- expect(Rake::Task.task_defined?(task_name)).to be true
30
+ expect(Rake::Task.task_defined?(task_name)).to be true
29
31
 
30
- expect(ENV['KNAPSACK_PRO_TEST_SUITE_TOKEN']).to eq 'minitest-token'
31
- expect(ENV['KNAPSACK_PRO_RECORDING_ENABLED']).to eq 'true'
32
+ expect(ENV['KNAPSACK_PRO_TEST_SUITE_TOKEN']).to eq 'minitest-token'
33
+ expect(ENV['KNAPSACK_PRO_RECORDING_ENABLED']).to eq 'true'
34
+ end
35
+ end
36
+
37
+ context 'when test files were not returned by Knapsack Pro API' do
38
+ it "doesn't run tests" do
39
+ runner = instance_double(described_class,
40
+ test_files_to_execute_exist?: false)
41
+ expect(described_class).to receive(:new)
42
+ .with(KnapsackPro::Adapters::MinitestAdapter).and_return(runner)
43
+
44
+ subject
45
+ end
32
46
  end
33
47
  end
34
48
  end
@@ -1,3 +1,5 @@
1
+ require 'rspec/core/rake_task'
2
+
1
3
  describe KnapsackPro::Runners::RSpecRunner do
2
4
  subject { described_class.new(KnapsackPro::Adapters::RSpecAdapter) }
3
5
 
@@ -6,43 +8,75 @@ describe KnapsackPro::Runners::RSpecRunner do
6
8
  describe '.run' do
7
9
  let(:args) { '--profile --color' }
8
10
 
9
- after { described_class.run(args) }
11
+ let(:test_suite_token_rspec) { 'fake-token' }
12
+
13
+ subject { described_class.run(args) }
10
14
 
11
15
  before do
12
- stub_const("ENV", { 'KNAPSACK_PRO_TEST_SUITE_TOKEN_RSPEC' => 'rspec-token' })
16
+ expect(KnapsackPro::Config::Env).to receive(:test_suite_token_rspec).and_return(test_suite_token_rspec)
17
+
18
+ expect(ENV).to receive(:[]=).with('KNAPSACK_PRO_TEST_SUITE_TOKEN', test_suite_token_rspec)
19
+ expect(ENV).to receive(:[]=).with('KNAPSACK_PRO_RECORDING_ENABLED', 'true')
13
20
 
14
- stringify_test_file_paths = 'spec/a_spec.rb spec/b_spec.rb'
15
- runner = instance_double(described_class,
16
- test_dir: 'spec',
17
- stringify_test_file_paths: stringify_test_file_paths)
18
21
  expect(described_class).to receive(:new)
19
22
  .with(KnapsackPro::Adapters::RSpecAdapter).and_return(runner)
20
-
21
- expect(Kernel).to receive(:system)
22
- .with('KNAPSACK_PRO_RECORDING_ENABLED=true KNAPSACK_PRO_TEST_SUITE_TOKEN=rspec-token bundle exec rspec --profile --color --default-path spec -- spec/a_spec.rb spec/b_spec.rb')
23
23
  end
24
24
 
25
- context 'when command exit with success code' do
26
- let(:exitstatus) { 0 }
25
+ context 'when test files were returned by Knapsack Pro API' do
26
+ let(:test_dir) { 'fake-test-dir' }
27
+ let(:test_file_paths) { double(:test_file_paths) }
28
+ let(:runner) do
29
+ instance_double(described_class,
30
+ test_dir: test_dir,
31
+ test_file_paths: test_file_paths,
32
+ test_files_to_execute_exist?: true)
33
+ end
34
+ let(:task) { double }
27
35
 
28
36
  before do
29
- expect($?).to receive(:exitstatus).and_return(exitstatus)
37
+ expect(Rake::Task).to receive(:[]).with('knapsack_pro:rspec_run').at_least(1).and_return(task)
38
+
39
+ t = double
40
+ expect(RSpec::Core::RakeTask).to receive(:new).with('knapsack_pro:rspec_run').and_yield(t)
41
+ expect(t).to receive(:rspec_opts=).with('--profile --color --default-path fake-test-dir')
42
+ expect(t).to receive(:pattern=).with(test_file_paths)
30
43
  end
31
44
 
32
- it do
33
- expect(Kernel).not_to receive(:exit)
45
+ context 'when task already exists' do
46
+ before do
47
+ expect(Rake::Task).to receive(:task_defined?).with('knapsack_pro:rspec_run').and_return(true)
48
+ expect(task).to receive(:clear)
49
+ end
50
+
51
+ it do
52
+ result = double(:result)
53
+ expect(task).to receive(:invoke).and_return(result)
54
+ expect(subject).to eq result
55
+ end
34
56
  end
35
- end
36
57
 
37
- context 'when command exit without success code' do
38
- let(:exitstatus) { 1 }
58
+ context "when task doesn't exist" do
59
+ before do
60
+ expect(Rake::Task).to receive(:task_defined?).with('knapsack_pro:rspec_run').and_return(false)
61
+ expect(task).not_to receive(:clear)
62
+ end
39
63
 
40
- before do
41
- expect($?).to receive(:exitstatus).twice.and_return(exitstatus)
64
+ it do
65
+ result = double(:result)
66
+ expect(task).to receive(:invoke).and_return(result)
67
+ expect(subject).to eq result
68
+ end
69
+ end
70
+ end
71
+
72
+ context 'when test files were not returned by Knapsack Pro API' do
73
+ let(:runner) do
74
+ instance_double(described_class,
75
+ test_files_to_execute_exist?: false)
42
76
  end
43
77
 
44
- it do
45
- expect(Kernel).to receive(:exit).with(exitstatus)
78
+ it "doesn't run tests" do
79
+ subject
46
80
  end
47
81
  end
48
82
  end
@@ -6,41 +6,64 @@ describe KnapsackPro::Runners::SpinachRunner do
6
6
  describe '.run' do
7
7
  let(:args) { '--custom-arg' }
8
8
 
9
- after { described_class.run(args) }
9
+ subject { described_class.run(args) }
10
10
 
11
11
  before do
12
12
  stub_const("ENV", { 'KNAPSACK_PRO_TEST_SUITE_TOKEN_SPINACH' => 'spinach-token' })
13
13
 
14
- stringify_test_file_paths = 'features/a.feature features/b.feature'
15
- runner = instance_double(described_class,
16
- stringify_test_file_paths: stringify_test_file_paths)
17
14
  expect(described_class).to receive(:new)
18
15
  .with(KnapsackPro::Adapters::SpinachAdapter).and_return(runner)
19
-
20
- expect(Kernel).to receive(:system).with('KNAPSACK_PRO_RECORDING_ENABLED=true KNAPSACK_PRO_TEST_SUITE_TOKEN=spinach-token bundle exec spinach --custom-arg -- features/a.feature features/b.feature')
21
16
  end
22
17
 
23
- context 'when command exit with success code' do
24
- let(:exitstatus) { 0 }
18
+ context 'when test files were returned by Knapsack Pro API' do
19
+ let(:stringify_test_file_paths) { 'features/a.feature features/b.feature' }
20
+ let(:test_dir) { 'fake-test-dir' }
21
+ let(:runner) do
22
+ instance_double(described_class,
23
+ test_dir: test_dir,
24
+ stringify_test_file_paths: stringify_test_file_paths,
25
+ test_files_to_execute_exist?: true)
26
+ end
25
27
 
26
28
  before do
27
- expect($?).to receive(:exitstatus).and_return(exitstatus)
29
+ expect(Kernel).to receive(:system).with('KNAPSACK_PRO_RECORDING_ENABLED=true KNAPSACK_PRO_TEST_SUITE_TOKEN=spinach-token bundle exec spinach --custom-arg --features_path fake-test-dir -- features/a.feature features/b.feature')
28
30
  end
29
31
 
30
- it do
31
- expect(Kernel).not_to receive(:exit)
32
+ after { subject }
33
+
34
+ context 'when command exit with success code' do
35
+ let(:exitstatus) { 0 }
36
+
37
+ before do
38
+ expect($?).to receive(:exitstatus).and_return(exitstatus)
39
+ end
40
+
41
+ it do
42
+ expect(Kernel).not_to receive(:exit)
43
+ end
32
44
  end
33
- end
34
45
 
35
- context 'when command exit without success code' do
36
- let(:exitstatus) { 1 }
46
+ context 'when command exit without success code' do
47
+ let(:exitstatus) { 1 }
37
48
 
38
- before do
39
- expect($?).to receive(:exitstatus).twice.and_return(exitstatus)
49
+ before do
50
+ expect($?).to receive(:exitstatus).twice.and_return(exitstatus)
51
+ end
52
+
53
+ it do
54
+ expect(Kernel).to receive(:exit).with(exitstatus)
55
+ end
56
+ end
57
+ end
58
+
59
+ context 'when test files were not returned by Knapsack Pro API' do
60
+ let(:runner) do
61
+ instance_double(described_class,
62
+ test_files_to_execute_exist?: false)
40
63
  end
41
64
 
42
- it do
43
- expect(Kernel).to receive(:exit).with(exitstatus)
65
+ it "doesn't run tests" do
66
+ subject
44
67
  end
45
68
  end
46
69
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: knapsack_pro
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.14.0
4
+ version: 0.15.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - ArturT
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-09-25 00:00:00.000000000 Z
11
+ date: 2016-10-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake