knapsack_pro 0.0.1 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +3 -3
- data/CHANGELOG.md +4 -0
- data/README.md +368 -4
- data/bin/knapsack_pro +20 -0
- data/circle.yml +2 -0
- data/knapsack_pro.gemspec +6 -1
- data/lib/knapsack_pro.rb +74 -0
- data/lib/knapsack_pro/adapters/base_adapter.rb +30 -0
- data/lib/knapsack_pro/adapters/cucumber_adapter.rb +40 -0
- data/lib/knapsack_pro/adapters/minitest_adapter.rb +52 -0
- data/lib/knapsack_pro/adapters/rspec_adapter.rb +48 -0
- data/lib/knapsack_pro/allocator.rb +40 -0
- data/lib/knapsack_pro/allocator_builder.rb +40 -0
- data/lib/knapsack_pro/client/api/action.rb +17 -0
- data/lib/knapsack_pro/client/api/v1/base.rb +15 -0
- data/lib/knapsack_pro/client/api/v1/build_distributions.rb +29 -0
- data/lib/knapsack_pro/client/api/v1/build_subsets.rb +29 -0
- data/lib/knapsack_pro/client/connection.rb +94 -0
- data/lib/knapsack_pro/config/ci/base.rb +22 -0
- data/lib/knapsack_pro/config/ci/buildkite.rb +27 -0
- data/lib/knapsack_pro/config/ci/circle.rb +29 -0
- data/lib/knapsack_pro/config/ci/semaphore.rb +28 -0
- data/lib/knapsack_pro/config/env.rb +111 -0
- data/lib/knapsack_pro/logger_wrapper.rb +15 -0
- data/lib/knapsack_pro/presenter.rb +25 -0
- data/lib/knapsack_pro/report.rb +20 -0
- data/lib/knapsack_pro/repository_adapter_initiator.rb +12 -0
- data/lib/knapsack_pro/repository_adapters/base_adapter.rb +14 -0
- data/lib/knapsack_pro/repository_adapters/env_adapter.rb +13 -0
- data/lib/knapsack_pro/repository_adapters/git_adapter.rb +19 -0
- data/lib/knapsack_pro/runners/base_runner.rb +31 -0
- data/lib/knapsack_pro/runners/cucumber_runner.rb +16 -0
- data/lib/knapsack_pro/runners/minitest_runner.rb +26 -0
- data/lib/knapsack_pro/runners/rspec_runner.rb +16 -0
- data/lib/knapsack_pro/task_loader.rb +11 -0
- data/lib/knapsack_pro/test_file_cleaner.rb +7 -0
- data/lib/knapsack_pro/test_file_finder.rb +33 -0
- data/lib/knapsack_pro/test_file_pattern.rb +7 -0
- data/lib/knapsack_pro/test_file_presenter.rb +11 -0
- data/lib/knapsack_pro/test_flat_distributor.rb +84 -0
- data/lib/knapsack_pro/tracker.rb +64 -0
- data/lib/knapsack_pro/version.rb +1 -1
- data/lib/tasks/cucumber.rake +7 -0
- data/lib/tasks/minitest.rake +7 -0
- data/lib/tasks/rspec.rake +7 -0
- data/spec/fixtures/vcr_cassettes/api/v1/build_distributions/subset/invalid_test_suite_token.yml +50 -0
- data/spec/fixtures/vcr_cassettes/api/v1/build_distributions/subset/success.yml +52 -0
- data/spec/fixtures/vcr_cassettes/api/v1/build_subsets/create/invalid_test_suite_token.yml +50 -0
- data/spec/fixtures/vcr_cassettes/api/v1/build_subsets/create/success.yml +50 -0
- data/spec/integration/api/build_distributions_subset_spec.rb +74 -0
- data/spec/integration/api/build_subsets_create_spec.rb +76 -0
- data/spec/knapsack_pro/adapters/base_adapter_spec.rb +63 -0
- data/spec/knapsack_pro/adapters/cucumber_adapter_spec.rb +71 -0
- data/spec/knapsack_pro/adapters/minitest_adapter_spec.rb +107 -0
- data/spec/knapsack_pro/adapters/rspec_adapter_spec.rb +94 -0
- data/spec/knapsack_pro/allocator_builder_spec.rb +45 -0
- data/spec/knapsack_pro/allocator_spec.rb +80 -0
- data/spec/knapsack_pro/client/api/action_spec.rb +17 -0
- data/spec/knapsack_pro/client/api/v1/base_spec.rb +2 -0
- data/spec/knapsack_pro/client/api/v1/build_distributions_spec.rb +35 -0
- data/spec/knapsack_pro/client/api/v1/build_subsets_spec.rb +35 -0
- data/spec/knapsack_pro/client/connection_spec.rb +138 -0
- data/spec/knapsack_pro/config/ci/base_spec.rb +7 -0
- data/spec/knapsack_pro/config/ci/buildkite_spec.rb +74 -0
- data/spec/knapsack_pro/config/ci/circle_spec.rb +74 -0
- data/spec/knapsack_pro/config/ci/semaphore_spec.rb +74 -0
- data/spec/knapsack_pro/config/env_spec.rb +368 -0
- data/spec/knapsack_pro/logger_wrapper_spec.rb +15 -0
- data/spec/knapsack_pro/presenter_spec.rb +57 -0
- data/spec/knapsack_pro/report_spec.rb +68 -0
- data/spec/knapsack_pro/repository_adapter_initiator_spec.rb +21 -0
- data/spec/knapsack_pro/repository_adapters/base_adapter_spec.rb +13 -0
- data/spec/knapsack_pro/repository_adapters/env_adapter_spec.rb +27 -0
- data/spec/knapsack_pro/repository_adapters/git_adapter_spec.rb +27 -0
- data/spec/knapsack_pro/runners/base_runner_spec.rb +61 -0
- data/spec/knapsack_pro/runners/cucumber_runner_spec.rb +47 -0
- data/spec/knapsack_pro/runners/minitest_runner_spec.rb +34 -0
- data/spec/knapsack_pro/runners/rspec_runner_spec.rb +49 -0
- data/spec/knapsack_pro/task_loader_spec.rb +14 -0
- data/spec/knapsack_pro/test_file_cleaner_spec.rb +11 -0
- data/spec/knapsack_pro/test_file_finder_spec.rb +35 -0
- data/spec/knapsack_pro/test_file_pattern_spec.rb +23 -0
- data/spec/knapsack_pro/test_file_presenter_spec.rb +22 -0
- data/spec/knapsack_pro/test_flat_distributor_spec.rb +60 -0
- data/spec/knapsack_pro/tracker_spec.rb +102 -0
- data/spec/knapsack_pro_spec.rb +56 -0
- data/spec/spec_helper.rb +11 -1
- data/spec/support/fakes/cucumber.rb +12 -0
- data/spec/support/fakes/minitest.rb +12 -0
- data/spec/support/shared_examples/adapter.rb +17 -0
- data/spec_fake/controllers/users_controller_spec.rb +0 -0
- data/spec_fake/models/admin_spec.rb +0 -0
- data/spec_fake/models/user_spec.rb +0 -0
- data/spec_fake/spec_helper.rb +0 -0
- data/test_fake/a_test.rb +0 -0
- data/test_fake/b_test.rb +0 -0
- metadata +212 -12
- data/Gemfile.lock +0 -69
- data/spec/knapsack_spec.rb +0 -3
@@ -0,0 +1,50 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: post
|
5
|
+
uri: http://api.knapsackpro.dev:3000/v1/build_subsets
|
6
|
+
body:
|
7
|
+
encoding: UTF-8
|
8
|
+
string: '{"commit_hash":"abcdefg","branch":"master","node_total":"2","node_index":"1","test_files":[{"path":"a_spec.rb","time_execution":1.2},{"path":"b_spec.rb","time_execution":0.3}],"test_suite_token":"fake"}'
|
9
|
+
headers:
|
10
|
+
Content-Type:
|
11
|
+
- application/json
|
12
|
+
Accept:
|
13
|
+
- application/json
|
14
|
+
Accept-Encoding:
|
15
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
16
|
+
User-Agent:
|
17
|
+
- Ruby
|
18
|
+
response:
|
19
|
+
status:
|
20
|
+
code: 403
|
21
|
+
message: 'Forbidden '
|
22
|
+
headers:
|
23
|
+
X-Frame-Options:
|
24
|
+
- SAMEORIGIN
|
25
|
+
X-Xss-Protection:
|
26
|
+
- 1; mode=block
|
27
|
+
X-Content-Type-Options:
|
28
|
+
- nosniff
|
29
|
+
Content-Type:
|
30
|
+
- application/json; charset=utf-8
|
31
|
+
Cache-Control:
|
32
|
+
- no-cache
|
33
|
+
X-Request-Id:
|
34
|
+
- 5288d830-4498-4a36-adae-9f4230289de3
|
35
|
+
X-Runtime:
|
36
|
+
- '0.065296'
|
37
|
+
Server:
|
38
|
+
- WEBrick/1.3.1 (Ruby/2.2.2/2015-04-13)
|
39
|
+
Date:
|
40
|
+
- Fri, 31 Jul 2015 16:18:27 GMT
|
41
|
+
Content-Length:
|
42
|
+
- '39'
|
43
|
+
Connection:
|
44
|
+
- Keep-Alive
|
45
|
+
body:
|
46
|
+
encoding: UTF-8
|
47
|
+
string: '{"errors":["invalid test suite token"]}'
|
48
|
+
http_version:
|
49
|
+
recorded_at: Fri, 31 Jul 2015 16:18:27 GMT
|
50
|
+
recorded_with: VCR 2.9.3
|
@@ -0,0 +1,50 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: post
|
5
|
+
uri: http://api.knapsackpro.dev:3000/v1/build_subsets
|
6
|
+
body:
|
7
|
+
encoding: UTF-8
|
8
|
+
string: '{"commit_hash":"abcdefg","branch":"master","node_total":"2","node_index":"1","test_files":[{"path":"a_spec.rb","time_execution":1.2},{"path":"b_spec.rb","time_execution":0.3}],"test_suite_token":"3fa64859337f6e56409d49f865d13fd7"}'
|
9
|
+
headers:
|
10
|
+
Content-Type:
|
11
|
+
- application/json
|
12
|
+
Accept:
|
13
|
+
- application/json
|
14
|
+
Accept-Encoding:
|
15
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
16
|
+
User-Agent:
|
17
|
+
- Ruby
|
18
|
+
response:
|
19
|
+
status:
|
20
|
+
code: 201
|
21
|
+
message: 'Created '
|
22
|
+
headers:
|
23
|
+
X-Frame-Options:
|
24
|
+
- SAMEORIGIN
|
25
|
+
X-Xss-Protection:
|
26
|
+
- 1; mode=block
|
27
|
+
X-Content-Type-Options:
|
28
|
+
- nosniff
|
29
|
+
Content-Type:
|
30
|
+
- text/plain; charset=utf-8
|
31
|
+
Cache-Control:
|
32
|
+
- no-cache
|
33
|
+
X-Request-Id:
|
34
|
+
- 3f9741b6-36b2-43e9-8346-d94732a0841e
|
35
|
+
X-Runtime:
|
36
|
+
- '0.060958'
|
37
|
+
Server:
|
38
|
+
- WEBrick/1.3.1 (Ruby/2.2.2/2015-04-13)
|
39
|
+
Date:
|
40
|
+
- Fri, 31 Jul 2015 16:18:27 GMT
|
41
|
+
Content-Length:
|
42
|
+
- '0'
|
43
|
+
Connection:
|
44
|
+
- Keep-Alive
|
45
|
+
body:
|
46
|
+
encoding: UTF-8
|
47
|
+
string: ''
|
48
|
+
http_version:
|
49
|
+
recorded_at: Fri, 31 Jul 2015 16:18:27 GMT
|
50
|
+
recorded_with: VCR 2.9.3
|
@@ -0,0 +1,74 @@
|
|
1
|
+
describe 'Request API /v1/build_distributions/subset' do
|
2
|
+
let(:valid_endpoint) { 'http://api.knapsackpro.dev:3000' }
|
3
|
+
let(:invalid_endpoint) { 'http://api.fake-knapsackpro.dev:3000' }
|
4
|
+
let(:valid_test_suite_token) { '3fa64859337f6e56409d49f865d13fd7' }
|
5
|
+
let(:invalid_test_suite_token) { 'fake' }
|
6
|
+
|
7
|
+
let(:action) do
|
8
|
+
KnapsackPro::Client::API::V1::BuildDistributions.subset(
|
9
|
+
commit_hash: 'abcdefg',
|
10
|
+
branch: 'master',
|
11
|
+
node_total: '2',
|
12
|
+
node_index: '1',
|
13
|
+
test_files: [
|
14
|
+
{
|
15
|
+
'path' => 'a_spec.rb'
|
16
|
+
},
|
17
|
+
{
|
18
|
+
'path' => 'b_spec.rb'
|
19
|
+
}
|
20
|
+
],
|
21
|
+
)
|
22
|
+
end
|
23
|
+
let(:connection) { KnapsackPro::Client::Connection.new(action) }
|
24
|
+
let(:endpoint) { valid_endpoint }
|
25
|
+
let(:test_suite_token) { valid_test_suite_token }
|
26
|
+
|
27
|
+
before do
|
28
|
+
stub_const('ENV', {
|
29
|
+
'KNAPSACK_PRO_ENDPOINT' => endpoint,
|
30
|
+
'KNAPSACK_PRO_TEST_SUITE_TOKEN' => test_suite_token,
|
31
|
+
})
|
32
|
+
end
|
33
|
+
|
34
|
+
context 'when success' do
|
35
|
+
it do
|
36
|
+
VCR.use_cassette('api/v1/build_distributions/subset/success') do
|
37
|
+
response = connection.call
|
38
|
+
puts response
|
39
|
+
end
|
40
|
+
|
41
|
+
expect(connection.errors?).to be false
|
42
|
+
expect(connection.success?).to be true
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
context 'when invalid test suite token' do
|
47
|
+
let(:test_suite_token) { invalid_test_suite_token }
|
48
|
+
|
49
|
+
it do
|
50
|
+
VCR.use_cassette('api/v1/build_distributions/subset/invalid_test_suite_token') do
|
51
|
+
response = connection.call
|
52
|
+
puts response
|
53
|
+
end
|
54
|
+
|
55
|
+
expect(connection.errors?).to be true
|
56
|
+
expect(connection.success?).to be true
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
context 'when timeout' do
|
61
|
+
let(:endpoint) { invalid_endpoint }
|
62
|
+
|
63
|
+
it do
|
64
|
+
stub_const('KnapsackPro::Client::Connection::TIMEOUT', 0.01)
|
65
|
+
VCR.use_cassette('api/v1/build_distributions/subset/timeout') do
|
66
|
+
response = connection.call
|
67
|
+
puts response
|
68
|
+
end
|
69
|
+
|
70
|
+
expect(connection.errors?).to be false
|
71
|
+
expect(connection.success?).to be false
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
describe 'Request API /v1/build_subsets' do
|
2
|
+
let(:valid_endpoint) { 'http://api.knapsackpro.dev:3000' }
|
3
|
+
let(:invalid_endpoint) { 'http://api.fake-knapsackpro.dev:3000' }
|
4
|
+
let(:valid_test_suite_token) { '3fa64859337f6e56409d49f865d13fd7' }
|
5
|
+
let(:invalid_test_suite_token) { 'fake' }
|
6
|
+
|
7
|
+
let(:action) do
|
8
|
+
KnapsackPro::Client::API::V1::BuildSubsets.create(
|
9
|
+
commit_hash: 'abcdefg',
|
10
|
+
branch: 'master',
|
11
|
+
node_total: '2',
|
12
|
+
node_index: '1',
|
13
|
+
test_files: [
|
14
|
+
{
|
15
|
+
'path' => 'a_spec.rb',
|
16
|
+
'time_execution' => 1.2,
|
17
|
+
},
|
18
|
+
{
|
19
|
+
'path' => 'b_spec.rb',
|
20
|
+
'time_execution' => 0.3,
|
21
|
+
}
|
22
|
+
],
|
23
|
+
)
|
24
|
+
end
|
25
|
+
let(:connection) { KnapsackPro::Client::Connection.new(action) }
|
26
|
+
let(:endpoint) { valid_endpoint }
|
27
|
+
let(:test_suite_token) { valid_test_suite_token }
|
28
|
+
|
29
|
+
before do
|
30
|
+
stub_const('ENV', {
|
31
|
+
'KNAPSACK_PRO_ENDPOINT' => endpoint,
|
32
|
+
'KNAPSACK_PRO_TEST_SUITE_TOKEN' => test_suite_token,
|
33
|
+
})
|
34
|
+
end
|
35
|
+
|
36
|
+
context 'when success' do
|
37
|
+
it do
|
38
|
+
VCR.use_cassette('api/v1/build_subsets/create/success') do
|
39
|
+
response = connection.call
|
40
|
+
puts response
|
41
|
+
end
|
42
|
+
|
43
|
+
expect(connection.errors?).to be false
|
44
|
+
expect(connection.success?).to be true
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
context 'when invalid test suite token' do
|
49
|
+
let(:test_suite_token) { invalid_test_suite_token }
|
50
|
+
|
51
|
+
it do
|
52
|
+
VCR.use_cassette('api/v1/build_subsets/create/invalid_test_suite_token') do
|
53
|
+
response = connection.call
|
54
|
+
puts response
|
55
|
+
end
|
56
|
+
|
57
|
+
expect(connection.errors?).to be true
|
58
|
+
expect(connection.success?).to be true
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
context 'when timeout' do
|
63
|
+
let(:endpoint) { invalid_endpoint }
|
64
|
+
|
65
|
+
it do
|
66
|
+
stub_const('KnapsackPro::Client::Connection::TIMEOUT', 0.01)
|
67
|
+
VCR.use_cassette('api/v1/build_subsets/create/timeout') do
|
68
|
+
response = connection.call
|
69
|
+
puts response
|
70
|
+
end
|
71
|
+
|
72
|
+
expect(connection.errors?).to be false
|
73
|
+
expect(connection.success?).to be false
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
describe KnapsackPro::Adapters::BaseAdapter do
|
2
|
+
it do
|
3
|
+
expect(described_class::TEST_DIR_PATTERN).to eq 'test/**/*_test.rb'
|
4
|
+
end
|
5
|
+
|
6
|
+
describe '.bind' do
|
7
|
+
let(:adapter) { instance_double(described_class) }
|
8
|
+
|
9
|
+
subject { described_class.bind }
|
10
|
+
|
11
|
+
before do
|
12
|
+
expect(described_class).to receive(:new).and_return(adapter)
|
13
|
+
expect(adapter).to receive(:bind)
|
14
|
+
end
|
15
|
+
|
16
|
+
it { should eql adapter }
|
17
|
+
end
|
18
|
+
|
19
|
+
describe '#bind' do
|
20
|
+
before do
|
21
|
+
expect(KnapsackPro::Config::Env).to receive(:recording_enabled?).and_return(recording_enabled?)
|
22
|
+
end
|
23
|
+
|
24
|
+
context 'when recording enabled' do
|
25
|
+
let(:recording_enabled?) { true }
|
26
|
+
|
27
|
+
it do
|
28
|
+
logger = instance_double(Logger)
|
29
|
+
expect(KnapsackPro).to receive(:logger).and_return(logger)
|
30
|
+
expect(logger).to receive(:info).with('Test suite time execution recording enabled.')
|
31
|
+
expect(subject).to receive(:bind_time_tracker)
|
32
|
+
expect(subject).to receive(:bind_save_report)
|
33
|
+
subject.bind
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
context 'when recording not enabled' do
|
38
|
+
let(:recording_enabled?) { false }
|
39
|
+
|
40
|
+
it do
|
41
|
+
expect(subject).not_to receive(:bind_time_tracker)
|
42
|
+
expect(subject).not_to receive(:bind_save_report)
|
43
|
+
subject.bind
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
describe '#bind_time_tracker' do
|
49
|
+
it do
|
50
|
+
expect {
|
51
|
+
subject.bind_time_tracker
|
52
|
+
}.to raise_error(NotImplementedError)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
describe '#bind_save_report' do
|
57
|
+
it do
|
58
|
+
expect {
|
59
|
+
subject.bind_save_report
|
60
|
+
}.to raise_error(NotImplementedError)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
describe KnapsackPro::Adapters::CucumberAdapter do
|
2
|
+
it do
|
3
|
+
expect(described_class::TEST_DIR_PATTERN).to eq 'features/**/*.feature'
|
4
|
+
end
|
5
|
+
|
6
|
+
context do
|
7
|
+
before do
|
8
|
+
allow(::Cucumber::RbSupport::RbDsl).to receive(:register_rb_hook)
|
9
|
+
allow(Kernel).to receive(:at_exit)
|
10
|
+
end
|
11
|
+
|
12
|
+
it_behaves_like 'adapter'
|
13
|
+
end
|
14
|
+
|
15
|
+
describe '.test_path' do
|
16
|
+
subject { described_class.test_path(scenario_or_outline_table) }
|
17
|
+
|
18
|
+
context 'when scenario' do
|
19
|
+
let(:scenario_file) { 'features/scenario.feature' }
|
20
|
+
let(:scenario_or_outline_table) { double(file: scenario_file) }
|
21
|
+
|
22
|
+
it { should eql scenario_file }
|
23
|
+
end
|
24
|
+
|
25
|
+
context 'when scenario outline' do
|
26
|
+
let(:scenario_outline_file) { 'features/scenario_outline.feature' }
|
27
|
+
let(:scenario_or_outline_table) do
|
28
|
+
double(scenario_outline: double(file: scenario_outline_file))
|
29
|
+
end
|
30
|
+
|
31
|
+
it { should eql scenario_outline_file }
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
describe 'bind methods' do
|
36
|
+
describe '#bind_time_tracker' do
|
37
|
+
let(:file) { 'features/a.feature' }
|
38
|
+
let(:scenario) { double(file: file) }
|
39
|
+
let(:block) { double }
|
40
|
+
let(:tracker) { instance_double(KnapsackPro::Tracker) }
|
41
|
+
let(:logger) { instance_double(Logger) }
|
42
|
+
let(:global_time) { 'Global time: 01m 05s' }
|
43
|
+
|
44
|
+
it do
|
45
|
+
expect(subject).to receive(:Around).and_yield(scenario, block)
|
46
|
+
allow(KnapsackPro).to receive(:tracker).and_return(tracker)
|
47
|
+
expect(tracker).to receive(:current_test_path=).with(file)
|
48
|
+
expect(tracker).to receive(:start_timer)
|
49
|
+
expect(block).to receive(:call)
|
50
|
+
expect(tracker).to receive(:stop_timer)
|
51
|
+
|
52
|
+
expect(::Kernel).to receive(:at_exit).and_yield
|
53
|
+
expect(KnapsackPro::Presenter).to receive(:global_time).and_return(global_time)
|
54
|
+
expect(KnapsackPro).to receive(:logger).and_return(logger)
|
55
|
+
expect(logger).to receive(:info).with(global_time)
|
56
|
+
|
57
|
+
subject.bind_time_tracker
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
describe '#bind_save_report' do
|
62
|
+
it do
|
63
|
+
expect(::Kernel).to receive(:at_exit).and_yield
|
64
|
+
|
65
|
+
expect(KnapsackPro::Report).to receive(:save)
|
66
|
+
|
67
|
+
subject.bind_save_report
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
@@ -0,0 +1,107 @@
|
|
1
|
+
module FakeMinitest
|
2
|
+
class Test < ::Minitest::Test
|
3
|
+
include KnapsackPro::Adapters::MinitestAdapter::BindTimeTrackerMinitestPlugin
|
4
|
+
end
|
5
|
+
end
|
6
|
+
|
7
|
+
describe KnapsackPro::Adapters::MinitestAdapter do
|
8
|
+
it do
|
9
|
+
expect(described_class::TEST_DIR_PATTERN).to eq 'test/**/*_test.rb'
|
10
|
+
end
|
11
|
+
|
12
|
+
describe '.test_path' do
|
13
|
+
class FakeUserTest
|
14
|
+
def test_user_age; end
|
15
|
+
|
16
|
+
# method provided by Minitest
|
17
|
+
# it returns test method name
|
18
|
+
def name
|
19
|
+
:test_user_age
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
let(:obj) { FakeUserTest.new }
|
24
|
+
|
25
|
+
subject { described_class.test_path(obj) }
|
26
|
+
|
27
|
+
before do
|
28
|
+
parent_of_test_dir = File.expand_path('../../../', File.dirname(__FILE__))
|
29
|
+
parent_of_test_dir_regexp = Regexp.new("^#{parent_of_test_dir}")
|
30
|
+
described_class.class_variable_set(:@@parent_of_test_dir, parent_of_test_dir_regexp)
|
31
|
+
end
|
32
|
+
|
33
|
+
it { should eq './spec/knapsack_pro/adapters/minitest_adapter_spec.rb' }
|
34
|
+
end
|
35
|
+
|
36
|
+
describe 'BindTimeTrackerMinitestPlugin' do
|
37
|
+
let(:tracker) { instance_double(KnapsackPro::Tracker) }
|
38
|
+
|
39
|
+
subject { ::FakeMinitest::Test.new }
|
40
|
+
|
41
|
+
before do
|
42
|
+
allow(KnapsackPro).to receive(:tracker).and_return(tracker)
|
43
|
+
end
|
44
|
+
|
45
|
+
describe '#before_setup' do
|
46
|
+
let(:file) { 'test/models/user_test.rb' }
|
47
|
+
|
48
|
+
it do
|
49
|
+
expect(described_class).to receive(:test_path).with(subject).and_return(file)
|
50
|
+
expect(tracker).to receive(:current_test_path=).with(file)
|
51
|
+
expect(tracker).to receive(:start_timer)
|
52
|
+
|
53
|
+
subject.before_setup
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
describe '#after_teardown' do
|
58
|
+
it do
|
59
|
+
expect(tracker).to receive(:stop_timer)
|
60
|
+
|
61
|
+
subject.after_teardown
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
describe 'bind methods' do
|
67
|
+
describe '#bind_time_tracker' do
|
68
|
+
let(:logger) { instance_double(Logger) }
|
69
|
+
let(:global_time) { 'Global time: 01m 05s' }
|
70
|
+
|
71
|
+
it do
|
72
|
+
expect(::Minitest::Test).to receive(:send).with(:include, KnapsackPro::Adapters::MinitestAdapter::BindTimeTrackerMinitestPlugin)
|
73
|
+
|
74
|
+
expect(::Minitest).to receive(:after_run).and_yield
|
75
|
+
|
76
|
+
expect(KnapsackPro::Presenter).to receive(:global_time).and_return(global_time)
|
77
|
+
expect(KnapsackPro).to receive(:logger).and_return(logger)
|
78
|
+
expect(logger).to receive(:info).with(global_time)
|
79
|
+
|
80
|
+
subject.bind_time_tracker
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
describe '#bind_save_report' do
|
85
|
+
it do
|
86
|
+
expect(::Minitest).to receive(:after_run).and_yield
|
87
|
+
|
88
|
+
expect(KnapsackPro::Report).to receive(:save)
|
89
|
+
|
90
|
+
subject.bind_save_report
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
describe '#set_test_helper_path' do
|
96
|
+
let(:adapter) { described_class.new }
|
97
|
+
let(:test_helper_path) { '/code/project/test/test_helper.rb' }
|
98
|
+
|
99
|
+
subject { adapter.set_test_helper_path(test_helper_path) }
|
100
|
+
|
101
|
+
after do
|
102
|
+
expect(described_class.class_variable_get(:@@parent_of_test_dir)).to eq '/code/project'
|
103
|
+
end
|
104
|
+
|
105
|
+
it { should eql '/code/project' }
|
106
|
+
end
|
107
|
+
end
|