knapsack 0.0.3 → 0.1.0
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.
- checksums.yaml +4 -4
- data/.travis.yml +12 -1
- data/CHANGELOG.md +11 -0
- data/LICENSE.txt +1 -1
- data/README.md +71 -24
- data/Rakefile +3 -1
- data/TODO.md +5 -0
- data/knapsack_report.json +9 -12
- data/lib/knapsack.rb +25 -6
- data/lib/knapsack/adapters/{base.rb → base_adapter.rb} +18 -8
- data/lib/knapsack/adapters/{rspec.rb → rspec_adapter.rb} +13 -6
- data/lib/knapsack/allocator.rb +65 -0
- data/lib/knapsack/distributors/base_distributor.rb +67 -0
- data/lib/knapsack/distributors/leftover_distributor.rb +49 -0
- data/lib/knapsack/distributors/report_distributor.rb +76 -0
- data/lib/knapsack/presenter.rb +38 -5
- data/lib/knapsack/report.rb +27 -12
- data/lib/knapsack/task_loader.rb +11 -0
- data/lib/knapsack/tracker.rb +30 -13
- data/lib/knapsack/version.rb +1 -1
- data/lib/tasks/knapsack.rake +21 -0
- data/spec/knapsack/adapters/base_adapter_spec.rb +91 -0
- data/spec/knapsack/adapters/rspec_adapter_spec.rb +29 -0
- data/spec/knapsack/allocator_spec.rb +57 -0
- data/spec/knapsack/distributors/base_distributor_spec.rb +85 -0
- data/spec/knapsack/distributors/leftover_distributor_spec.rb +110 -0
- data/spec/knapsack/distributors/report_distributor_spec.rb +152 -0
- data/spec/knapsack/presenter_spec.rb +83 -0
- data/spec/knapsack/report_spec.rb +73 -0
- data/spec/knapsack/task_loader_spec.rb +10 -0
- data/spec/knapsack/tracker_spec.rb +84 -20
- data/spec/knapsack_spec.rb +23 -2
- data/spec/spec_helper.rb +16 -0
- data/spec_examples/fast/1_spec.rb +1 -4
- data/spec_examples/fast/2_spec.rb +1 -4
- data/spec_examples/fast/3_spec.rb +1 -4
- data/spec_examples/fast/4_spec.rb +1 -4
- data/spec_examples/fast/5_spec.rb +1 -4
- data/spec_examples/fast/6_spec.rb +1 -4
- data/spec_examples/leftover/1_spec.rb +4 -0
- data/spec_examples/leftover/a_spec.rb +8 -0
- data/spec_examples/slow/a_spec.rb +1 -3
- data/spec_examples/slow/b_spec.rb +3 -5
- data/spec_examples/slow/c_spec.rb +1 -3
- data/spec_examples/spec_helper.rb +5 -2
- metadata +32 -7
- data/spec_examples/slow/d_spec.rb +0 -7
- data/spec_examples/slow/e_spec.rb +0 -7
- data/spec_examples/slow/f_spec.rb +0 -7
@@ -0,0 +1,73 @@
|
|
1
|
+
describe Knapsack::Report do
|
2
|
+
let(:report) { described_class.send(:new) }
|
3
|
+
let(:report_path) { 'tmp/fake_report.json' }
|
4
|
+
let(:report_json) do
|
5
|
+
%Q[{"a_spec.rb": #{rand(Math::E..Math::PI)}}]
|
6
|
+
end
|
7
|
+
|
8
|
+
describe '#config' do
|
9
|
+
context 'when passed options' do
|
10
|
+
let(:opts) do
|
11
|
+
{
|
12
|
+
report_path: 'new_knapsack_report.json',
|
13
|
+
fake: true
|
14
|
+
}
|
15
|
+
end
|
16
|
+
|
17
|
+
it do
|
18
|
+
expect(report.config(opts)).to eql({
|
19
|
+
report_path: 'new_knapsack_report.json',
|
20
|
+
fake: true
|
21
|
+
})
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
context "when didn't pass options" do
|
26
|
+
it do
|
27
|
+
expect(report.config).to eql({
|
28
|
+
report_path: 'knapsack_report.json'
|
29
|
+
})
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
describe '#save', :clear_tmp do
|
35
|
+
before do
|
36
|
+
expect(report).to receive(:report_json).and_return(report_json)
|
37
|
+
report.config({
|
38
|
+
report_path: report_path
|
39
|
+
})
|
40
|
+
report.save
|
41
|
+
end
|
42
|
+
|
43
|
+
it { expect(File.read(report_path)).to eql report_json }
|
44
|
+
end
|
45
|
+
|
46
|
+
describe '.open' do
|
47
|
+
let(:subject) { report.open }
|
48
|
+
|
49
|
+
before do
|
50
|
+
report.config({
|
51
|
+
report_path: report_path
|
52
|
+
})
|
53
|
+
end
|
54
|
+
|
55
|
+
context 'when report file exists' do
|
56
|
+
before do
|
57
|
+
expect(File).to receive(:read).with(report_path).and_return(report_json)
|
58
|
+
end
|
59
|
+
|
60
|
+
it { should eql(JSON.parse(report_json)) }
|
61
|
+
end
|
62
|
+
|
63
|
+
context "when report file doesn't exist" do
|
64
|
+
let(:report_path) { 'tmp/non_existing_report.json' }
|
65
|
+
|
66
|
+
it do
|
67
|
+
expect {
|
68
|
+
subject
|
69
|
+
}.to raise_error("Knapsack report file doesn't exist. Please generate report first!")
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
@@ -1,8 +1,6 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
1
|
shared_examples 'default trakcer attributes' do
|
4
2
|
it { expect(tracker.global_time).to eql 0 }
|
5
|
-
it { expect(tracker.
|
3
|
+
it { expect(tracker.spec_files_with_time).to eql({}) }
|
6
4
|
end
|
7
5
|
|
8
6
|
describe Knapsack::Tracker do
|
@@ -10,23 +8,13 @@ describe Knapsack::Tracker do
|
|
10
8
|
|
11
9
|
it_behaves_like 'default trakcer attributes'
|
12
10
|
|
13
|
-
describe '#
|
14
|
-
|
15
|
-
|
16
|
-
context 'when ENV variable is defined' do
|
17
|
-
before do
|
18
|
-
stub_const("ENV", { 'KNAPSACK_GENERATE_REPORT' => true })
|
19
|
-
end
|
20
|
-
it { should be true }
|
21
|
-
end
|
22
|
-
|
23
|
-
context 'when ENV variable is not defined' do
|
24
|
-
it { should be false }
|
11
|
+
describe '#config' do
|
12
|
+
before do
|
13
|
+
stub_const("ENV", { 'KNAPSACK_GENERATE_REPORT' => generate_report })
|
25
14
|
end
|
26
|
-
end
|
27
15
|
|
28
|
-
describe '#config' do
|
29
16
|
context 'when passed options' do
|
17
|
+
let(:generate_report) { true }
|
30
18
|
let(:opts) do
|
31
19
|
{
|
32
20
|
enable_time_offset_warning: false,
|
@@ -37,22 +25,98 @@ describe Knapsack::Tracker do
|
|
37
25
|
it do
|
38
26
|
expect(tracker.config(opts)).to eql({
|
39
27
|
enable_time_offset_warning: false,
|
40
|
-
|
28
|
+
time_offset_in_seconds: 30,
|
29
|
+
generate_report: true,
|
41
30
|
fake: true
|
42
31
|
})
|
43
32
|
end
|
44
33
|
end
|
45
34
|
|
46
35
|
context "when didn't pass options" do
|
36
|
+
let(:generate_report) { nil }
|
37
|
+
|
47
38
|
it do
|
48
39
|
expect(tracker.config).to eql({
|
49
40
|
enable_time_offset_warning: true,
|
50
|
-
|
41
|
+
time_offset_in_seconds: 30,
|
42
|
+
generate_report: false
|
51
43
|
})
|
52
44
|
end
|
53
45
|
end
|
54
46
|
end
|
55
47
|
|
48
|
+
describe '#spec_path' do
|
49
|
+
subject { tracker.spec_path }
|
50
|
+
|
51
|
+
context 'when spec_path not set' do
|
52
|
+
it do
|
53
|
+
expect { subject }.to raise_error("spec_path needs to be set by Knapsack Adapter's bind method")
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
context 'when spec_path set' do
|
58
|
+
context 'when spec path has prefix ./' do
|
59
|
+
before { tracker.spec_path = './spec/models/user_spec.rb' }
|
60
|
+
it { should eql 'spec/models/user_spec.rb' }
|
61
|
+
end
|
62
|
+
|
63
|
+
context 'when spec path has not prefix ./' do
|
64
|
+
before { tracker.spec_path = 'spec/models/user_spec.rb' }
|
65
|
+
it { should eql 'spec/models/user_spec.rb' }
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
describe '#time_exceeded?' do
|
71
|
+
subject { tracker.time_exceeded? }
|
72
|
+
|
73
|
+
before do
|
74
|
+
expect(tracker).to receive(:global_time).and_return(global_time)
|
75
|
+
expect(tracker).to receive(:max_node_time_execution).and_return(max_node_time_execution)
|
76
|
+
end
|
77
|
+
|
78
|
+
context 'when true' do
|
79
|
+
let(:global_time) { 2 }
|
80
|
+
let(:max_node_time_execution) { 1 }
|
81
|
+
it { should be true }
|
82
|
+
end
|
83
|
+
|
84
|
+
context 'when false' do
|
85
|
+
let(:global_time) { 1 }
|
86
|
+
let(:max_node_time_execution) { 1 }
|
87
|
+
it { should be false }
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
describe '#max_node_time_execution' do
|
92
|
+
let(:report_distributor) { instance_double(Knapsack::Distributors::ReportDistributor) }
|
93
|
+
let(:node_time_execution) { 3.5 }
|
94
|
+
let(:max_node_time_execution) { node_time_execution + tracker.config[:time_offset_in_seconds] }
|
95
|
+
|
96
|
+
subject { tracker.max_node_time_execution }
|
97
|
+
|
98
|
+
before do
|
99
|
+
expect(tracker).to receive(:report_distributor).and_return(report_distributor)
|
100
|
+
expect(report_distributor).to receive(:node_time_execution).and_return(node_time_execution)
|
101
|
+
end
|
102
|
+
|
103
|
+
it { should eql max_node_time_execution }
|
104
|
+
end
|
105
|
+
|
106
|
+
describe '#exceeded_time' do
|
107
|
+
let(:global_time) { 5 }
|
108
|
+
let(:max_node_time_execution) { 2 }
|
109
|
+
|
110
|
+
subject { tracker.exceeded_time }
|
111
|
+
|
112
|
+
before do
|
113
|
+
expect(tracker).to receive(:global_time).and_return(global_time)
|
114
|
+
expect(tracker).to receive(:max_node_time_execution).and_return(max_node_time_execution)
|
115
|
+
end
|
116
|
+
|
117
|
+
it { should eql 3 }
|
118
|
+
end
|
119
|
+
|
56
120
|
describe 'track time execution' do
|
57
121
|
let(:now) { Time.now }
|
58
122
|
let(:spec_paths) { ['a_spec.rb', 'b_spec.rb'] }
|
@@ -73,7 +137,7 @@ describe Knapsack::Tracker do
|
|
73
137
|
|
74
138
|
it { expect(tracker.global_time).to eql 3.0 }
|
75
139
|
it do
|
76
|
-
expect(tracker.
|
140
|
+
expect(tracker.spec_files_with_time).to eql({
|
77
141
|
'a_spec.rb' => 1.0,
|
78
142
|
'b_spec.rb' => 2.0,
|
79
143
|
})
|
data/spec/knapsack_spec.rb
CHANGED
@@ -1,5 +1,3 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
1
|
describe Knapsack do
|
4
2
|
describe '.tracker' do
|
5
3
|
subject { described_class.tracker }
|
@@ -7,4 +5,27 @@ describe Knapsack do
|
|
7
5
|
it { should be_a Knapsack::Tracker }
|
8
6
|
it { expect(subject.object_id).to eql described_class.tracker.object_id }
|
9
7
|
end
|
8
|
+
|
9
|
+
describe '.report' do
|
10
|
+
subject { described_class.report }
|
11
|
+
|
12
|
+
it { should be_a Knapsack::Report }
|
13
|
+
it { expect(subject.object_id).to eql described_class.report.object_id }
|
14
|
+
end
|
15
|
+
|
16
|
+
describe '.root' do
|
17
|
+
subject { described_class.root }
|
18
|
+
|
19
|
+
it { expect(subject).to match 'knapsack' }
|
20
|
+
end
|
21
|
+
|
22
|
+
describe '.load_tasks' do
|
23
|
+
let(:task_loader) { instance_double(Knapsack::TaskLoader) }
|
24
|
+
|
25
|
+
it do
|
26
|
+
expect(Knapsack::TaskLoader).to receive(:new).and_return(task_loader)
|
27
|
+
expect(task_loader).to receive(:load_tasks)
|
28
|
+
described_class.load_tasks
|
29
|
+
end
|
30
|
+
end
|
10
31
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -12,4 +12,20 @@ RSpec.configure do |config|
|
|
12
12
|
mocks.syntax = :expect
|
13
13
|
mocks.verify_partial_doubles = true
|
14
14
|
end
|
15
|
+
|
16
|
+
config.expect_with :rspec do |c|
|
17
|
+
c.syntax = :expect
|
18
|
+
end
|
19
|
+
|
20
|
+
config.before(:each) do
|
21
|
+
if RSpec.current_example.metadata[:clear_tmp]
|
22
|
+
FileUtils.mkdir_p(File.join(Knapsack.root, 'tmp'))
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
config.after(:each) do
|
27
|
+
if RSpec.current_example.metadata[:clear_tmp]
|
28
|
+
FileUtils.rm_r(File.join(Knapsack.root, 'tmp'))
|
29
|
+
end
|
30
|
+
end
|
15
31
|
end
|
@@ -1,9 +1,12 @@
|
|
1
1
|
require 'knapsack'
|
2
2
|
Knapsack.tracker.config({
|
3
3
|
enable_time_offset_warning: true,
|
4
|
-
|
4
|
+
time_offset_in_seconds: 3
|
5
5
|
})
|
6
|
-
Knapsack
|
6
|
+
Knapsack.report.config({
|
7
|
+
report_path: 'knapsack_report.json'
|
8
|
+
})
|
9
|
+
Knapsack::Adapters::RspecAdapter.bind
|
7
10
|
|
8
11
|
RSpec.configure do |config|
|
9
12
|
config.order = :random
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: knapsack
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ArturT
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-07-
|
11
|
+
date: 2014-07-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -98,19 +98,36 @@ files:
|
|
98
98
|
- ".gitignore"
|
99
99
|
- ".rspec"
|
100
100
|
- ".travis.yml"
|
101
|
+
- CHANGELOG.md
|
101
102
|
- Gemfile
|
102
103
|
- LICENSE.txt
|
103
104
|
- README.md
|
104
105
|
- Rakefile
|
106
|
+
- TODO.md
|
105
107
|
- knapsack.gemspec
|
106
108
|
- knapsack_report.json
|
107
109
|
- lib/knapsack.rb
|
108
|
-
- lib/knapsack/adapters/
|
109
|
-
- lib/knapsack/adapters/
|
110
|
+
- lib/knapsack/adapters/base_adapter.rb
|
111
|
+
- lib/knapsack/adapters/rspec_adapter.rb
|
112
|
+
- lib/knapsack/allocator.rb
|
113
|
+
- lib/knapsack/distributors/base_distributor.rb
|
114
|
+
- lib/knapsack/distributors/leftover_distributor.rb
|
115
|
+
- lib/knapsack/distributors/report_distributor.rb
|
110
116
|
- lib/knapsack/presenter.rb
|
111
117
|
- lib/knapsack/report.rb
|
118
|
+
- lib/knapsack/task_loader.rb
|
112
119
|
- lib/knapsack/tracker.rb
|
113
120
|
- lib/knapsack/version.rb
|
121
|
+
- lib/tasks/knapsack.rake
|
122
|
+
- spec/knapsack/adapters/base_adapter_spec.rb
|
123
|
+
- spec/knapsack/adapters/rspec_adapter_spec.rb
|
124
|
+
- spec/knapsack/allocator_spec.rb
|
125
|
+
- spec/knapsack/distributors/base_distributor_spec.rb
|
126
|
+
- spec/knapsack/distributors/leftover_distributor_spec.rb
|
127
|
+
- spec/knapsack/distributors/report_distributor_spec.rb
|
128
|
+
- spec/knapsack/presenter_spec.rb
|
129
|
+
- spec/knapsack/report_spec.rb
|
130
|
+
- spec/knapsack/task_loader_spec.rb
|
114
131
|
- spec/knapsack/tracker_spec.rb
|
115
132
|
- spec/knapsack_spec.rb
|
116
133
|
- spec/spec_helper.rb
|
@@ -120,12 +137,11 @@ files:
|
|
120
137
|
- spec_examples/fast/4_spec.rb
|
121
138
|
- spec_examples/fast/5_spec.rb
|
122
139
|
- spec_examples/fast/6_spec.rb
|
140
|
+
- spec_examples/leftover/1_spec.rb
|
141
|
+
- spec_examples/leftover/a_spec.rb
|
123
142
|
- spec_examples/slow/a_spec.rb
|
124
143
|
- spec_examples/slow/b_spec.rb
|
125
144
|
- spec_examples/slow/c_spec.rb
|
126
|
-
- spec_examples/slow/d_spec.rb
|
127
|
-
- spec_examples/slow/e_spec.rb
|
128
|
-
- spec_examples/slow/f_spec.rb
|
129
145
|
- spec_examples/spec_helper.rb
|
130
146
|
homepage: https://github.com/ArturT/knapsack
|
131
147
|
licenses:
|
@@ -152,6 +168,15 @@ signing_key:
|
|
152
168
|
specification_version: 4
|
153
169
|
summary: Parallel specs across CI server nodes based on each spec file's time execution.
|
154
170
|
test_files:
|
171
|
+
- spec/knapsack/adapters/base_adapter_spec.rb
|
172
|
+
- spec/knapsack/adapters/rspec_adapter_spec.rb
|
173
|
+
- spec/knapsack/allocator_spec.rb
|
174
|
+
- spec/knapsack/distributors/base_distributor_spec.rb
|
175
|
+
- spec/knapsack/distributors/leftover_distributor_spec.rb
|
176
|
+
- spec/knapsack/distributors/report_distributor_spec.rb
|
177
|
+
- spec/knapsack/presenter_spec.rb
|
178
|
+
- spec/knapsack/report_spec.rb
|
179
|
+
- spec/knapsack/task_loader_spec.rb
|
155
180
|
- spec/knapsack/tracker_spec.rb
|
156
181
|
- spec/knapsack_spec.rb
|
157
182
|
- spec/spec_helper.rb
|