learn-test 3.2.4 → 3.3.0.pre.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +27 -0
- data/Gemfile +2 -0
- data/learn-test.gemspec +1 -0
- data/lib/learn_test.rb +13 -34
- data/lib/learn_test/git.rb +19 -0
- data/lib/learn_test/git/wip/base.rb +88 -0
- data/lib/learn_test/git/wip/branch.rb +36 -0
- data/lib/learn_test/git/wip/error.rb +23 -0
- data/lib/learn_test/repo_parser.rb +1 -1
- data/lib/learn_test/reporter.rb +23 -12
- data/lib/learn_test/strategy.rb +1 -1
- data/lib/learn_test/version.rb +1 -1
- data/spec/features/rspec_unit_spec.rb +19 -6
- data/spec/fixtures/rspec-unit-spec/.results.json +1 -0
- data/spec/fixtures/rspec-unit-spec/spec/spec_helper.rb +0 -82
- data/spec/learn_test/git/wip/base_spec.rb +89 -0
- data/spec/learn_test/git/wip/branch_spec.rb +121 -0
- data/spec/learn_test/git/wip/error_spec.rb +41 -0
- data/spec/learn_test/git_spec.rb +38 -32
- data/spec/learn_test/reporter_spec.rb +30 -16
- data/spec/lib/learn_test/strategies/none_spec.rb +0 -1
- data/spec/spec_helper.rb +7 -0
- metadata +36 -12
- data/bin/learn-test-wip +0 -249
- data/lib/learn_test/git_wip.rb +0 -34
@@ -0,0 +1,89 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
describe LearnTest::Git::Wip::Base do
|
4
|
+
describe 'attr_reader' do
|
5
|
+
let(:base) { LearnTest::Git::Base.open('./') }
|
6
|
+
let(:message) { 'foobar' }
|
7
|
+
let(:instance) do
|
8
|
+
described_class.new(
|
9
|
+
base: base,
|
10
|
+
message: message
|
11
|
+
)
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'should have :working_branch, :wip_branch' do
|
15
|
+
expect(instance).to respond_to(:working_branch, :wip_branch)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
describe '.process!', type: :aruba do
|
20
|
+
let!(:path) { File.join Aruba.config.home_directory, 'example' }
|
21
|
+
let(:base) { LearnTest::Git::Base.open(path) }
|
22
|
+
let(:message) { 'foobar' }
|
23
|
+
let(:instance) do
|
24
|
+
described_class.new(
|
25
|
+
base: base,
|
26
|
+
message: message
|
27
|
+
)
|
28
|
+
end
|
29
|
+
|
30
|
+
def initialize_repo(commit: true)
|
31
|
+
create_directory 'example'
|
32
|
+
cd 'example'
|
33
|
+
write_file 'README.md', 'Hello World'
|
34
|
+
run_command_and_stop 'git init'
|
35
|
+
|
36
|
+
if commit # rubocop:disable Style/GuardClause
|
37
|
+
run_command_and_stop 'git add .'
|
38
|
+
run_command_and_stop 'git commit -m "Initial Commit"'
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
context 'no commits' do
|
43
|
+
before(:each) { initialize_repo(commit: false) }
|
44
|
+
|
45
|
+
it 'should raise' do
|
46
|
+
expect { instance.process! }.to raise_error(LearnTest::Git::Wip::NoCommitsError)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
xcontext 'no changes' do
|
51
|
+
before(:each) { initialize_repo }
|
52
|
+
|
53
|
+
it 'should raise' do
|
54
|
+
expect { instance.process! }.to raise_error(LearnTest::Git::Wip::NoChangesError)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
context 'changes' do
|
59
|
+
context 'staged' do
|
60
|
+
before :each do
|
61
|
+
initialize_repo
|
62
|
+
write_file 'test.rb', ''
|
63
|
+
end
|
64
|
+
|
65
|
+
it 'should process successfully' do
|
66
|
+
instance.process!
|
67
|
+
|
68
|
+
expect(instance.success?).to eq(true)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
context 'committed' do
|
73
|
+
before :each do
|
74
|
+
initialize_repo
|
75
|
+
write_file 'test.rb', ''
|
76
|
+
|
77
|
+
run_command_and_stop 'git add .'
|
78
|
+
run_command_and_stop 'git commit -m "foo"'
|
79
|
+
end
|
80
|
+
|
81
|
+
it 'should process successfully' do
|
82
|
+
instance.process!
|
83
|
+
|
84
|
+
expect(instance.success?).to eq(true)
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
@@ -0,0 +1,121 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
describe LearnTest::Git::Wip::Branch do
|
4
|
+
let(:base) { LearnTest::Git::Base.open('./') }
|
5
|
+
let(:name) { base.current_branch }
|
6
|
+
let(:branch) do
|
7
|
+
described_class.new(
|
8
|
+
base: base,
|
9
|
+
name: name
|
10
|
+
)
|
11
|
+
end
|
12
|
+
|
13
|
+
let(:sha1) { Digest::SHA1.new.hexdigest }
|
14
|
+
let(:nothing_to_commit_error_msg) { 'nothing to commit, working directory clean' }
|
15
|
+
let(:no_commits_error_msg) do
|
16
|
+
"fatal: ambiguous argument '#{name}': unknown revision or path not in the working tree."
|
17
|
+
end
|
18
|
+
|
19
|
+
describe 'accessors' do
|
20
|
+
it 'should have :parent, :parent=' do
|
21
|
+
expect(branch).to respond_to(:parent, :parent=)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
describe '.new' do
|
26
|
+
it 'should require :base' do
|
27
|
+
expect { described_class.new(base: {}) }.to raise_error(ArgumentError, /name/)
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'should require :name' do
|
31
|
+
expect { described_class.new(name: 'foo') }.to raise_error(ArgumentError, /base/)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
describe '.to_s' do
|
36
|
+
it 'should return @name' do
|
37
|
+
expect(branch.to_s).to eq(name)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
describe '.last_revision' do
|
42
|
+
context 'success' do
|
43
|
+
it 'should return a SHA' do
|
44
|
+
expect(base)
|
45
|
+
.to receive(:revparse)
|
46
|
+
.with(name)
|
47
|
+
.and_return(sha1)
|
48
|
+
|
49
|
+
expect(branch.last_revision).to eq(sha1)
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'should only run revparse once' do
|
53
|
+
expect(base)
|
54
|
+
.to receive(:revparse)
|
55
|
+
.with(name)
|
56
|
+
.and_return(sha1)
|
57
|
+
.once
|
58
|
+
|
59
|
+
expect(branch.last_revision).to eq(sha1)
|
60
|
+
expect(branch.last_revision).to eq(sha1)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
context 'hide expected Git errors' do
|
65
|
+
it 'should hide no commits error' do
|
66
|
+
expect(base)
|
67
|
+
.to receive(:revparse)
|
68
|
+
.with(name)
|
69
|
+
.and_raise(::Git::GitExecuteError, no_commits_error_msg)
|
70
|
+
|
71
|
+
expect { branch.last_revision }.to_not raise_error
|
72
|
+
end
|
73
|
+
|
74
|
+
it 'should return false' do
|
75
|
+
expect(base)
|
76
|
+
.to receive(:revparse)
|
77
|
+
.with(name)
|
78
|
+
.and_raise(::Git::GitExecuteError, no_commits_error_msg)
|
79
|
+
|
80
|
+
expect(branch.last_revision).to eq(false)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
context 'raise expected Git errors' do
|
85
|
+
it 'should raise no commits error' do
|
86
|
+
expect(base)
|
87
|
+
.to receive(:revparse)
|
88
|
+
.with(name)
|
89
|
+
.and_raise(::Git::GitExecuteError, no_commits_error_msg)
|
90
|
+
|
91
|
+
expect do
|
92
|
+
branch.last_revision(raise_no_commits: true)
|
93
|
+
end.to raise_error(
|
94
|
+
LearnTest::Git::Wip::NoCommitsError, "Branch `#{name}` doesn't have any commits. Please commit and try again."
|
95
|
+
)
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
context 'raise unexpected Git errors' do
|
100
|
+
it 'should raise no commits error' do
|
101
|
+
expect(base)
|
102
|
+
.to receive(:revparse)
|
103
|
+
.with(name)
|
104
|
+
.and_raise(::Git::GitExecuteError, nothing_to_commit_error_msg)
|
105
|
+
|
106
|
+
expect { branch.last_revision }.to raise_error(::Git::GitExecuteError, nothing_to_commit_error_msg)
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
context 'raise unexpected errors' do
|
111
|
+
it 'should raise' do
|
112
|
+
expect(base)
|
113
|
+
.to receive(:revparse)
|
114
|
+
.with(name)
|
115
|
+
.and_raise(StandardError)
|
116
|
+
|
117
|
+
expect { branch.last_revision }.to raise_error(StandardError)
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
describe LearnTest::Git::Wip do
|
4
|
+
let(:branch) { rand(0..999_999).to_s }
|
5
|
+
|
6
|
+
describe LearnTest::Git::Wip::Error do
|
7
|
+
it 'should inherit from StandardError' do
|
8
|
+
expect(described_class).to be < StandardError
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
describe LearnTest::Git::Wip::NoChangesError do
|
13
|
+
it 'should inherit from Error' do
|
14
|
+
expect(described_class).to be < LearnTest::Git::Wip::Error
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'should require a branch' do
|
18
|
+
expect { described_class.new }.to raise_error(ArgumentError)
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'should have the correct messaging' do
|
22
|
+
error = described_class.new(branch)
|
23
|
+
expect(error.message).to eq "No changes found on `#{branch}`"
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
describe LearnTest::Git::Wip::NoCommitsError do
|
28
|
+
it 'should inherit from Error' do
|
29
|
+
expect(described_class).to be < LearnTest::Git::Wip::Error
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'should require a branch' do
|
33
|
+
expect { described_class.new }.to raise_error(ArgumentError)
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'should have the correct messaging' do
|
37
|
+
error = described_class.new(branch)
|
38
|
+
expect(error.message).to eq "Branch `#{branch}` doesn't have any commits. Please commit and try again."
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
data/spec/learn_test/git_spec.rb
CHANGED
@@ -1,47 +1,53 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
describe LearnTest::
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
let(:wait_thr_value) { double }
|
12
|
-
let(:stdout_and_stderr) { double }
|
13
|
-
|
14
|
-
context 'success' do
|
15
|
-
it 'should return the git url' do
|
16
|
-
expect(Git::Base).to receive(:open).with('./', { log: false }).and_return(git_base)
|
17
|
-
expect(git_base).to receive(:current_branch).and_return(working_branch)
|
3
|
+
describe LearnTest::Git do
|
4
|
+
describe '.open' do
|
5
|
+
context 'defaults' do
|
6
|
+
it 'should instantiate LearnTest::Git::Base' do
|
7
|
+
expect(LearnTest::Git::Base).to receive(:open).with('./', {})
|
8
|
+
LearnTest::Git.open
|
9
|
+
end
|
10
|
+
end
|
18
11
|
|
19
|
-
|
20
|
-
|
12
|
+
context 'with options' do
|
13
|
+
it 'should instantiate LearnTest::Git::Base' do
|
14
|
+
directory = './foo'
|
15
|
+
options = { logger: false }
|
21
16
|
|
22
|
-
|
17
|
+
expect(LearnTest::Git::Base).to receive(:open).with(directory, options)
|
23
18
|
|
24
|
-
|
25
|
-
|
19
|
+
LearnTest::Git.open(
|
20
|
+
directory: directory,
|
21
|
+
options: options
|
22
|
+
)
|
23
|
+
end
|
26
24
|
end
|
27
25
|
end
|
28
26
|
|
29
|
-
|
30
|
-
it 'should
|
31
|
-
expect(Git::Base).to
|
32
|
-
|
27
|
+
describe LearnTest::Git::Base do
|
28
|
+
it 'should inherit from ::Git::Base' do
|
29
|
+
expect(LearnTest::Git::Base).to be < ::Git::Base
|
30
|
+
end
|
33
31
|
|
34
|
-
|
35
|
-
|
32
|
+
describe '#wip' do
|
33
|
+
let!(:repo) { described_class.open('./') }
|
34
|
+
let!(:message) { 'FooBar' }
|
35
|
+
let!(:wip) { double(LearnTest::Git::Wip::Base) }
|
36
36
|
|
37
|
-
|
37
|
+
it 'should require a :message' do
|
38
|
+
expect { repo.wip }.to raise_error(ArgumentError)
|
39
|
+
end
|
38
40
|
|
39
|
-
|
40
|
-
|
41
|
+
it 'should instantiate and run .process!' do
|
42
|
+
expect(LearnTest::Git::Wip::Base)
|
43
|
+
.to receive(:new)
|
44
|
+
.with(base: repo, message: message)
|
45
|
+
.and_return(wip)
|
46
|
+
|
47
|
+
expect(wip).to receive(:process!)
|
41
48
|
|
42
|
-
|
43
|
-
|
44
|
-
expect(subject.run!).to eq(false)
|
49
|
+
expect(repo.wip(message: message)).to eq(wip)
|
50
|
+
end
|
45
51
|
end
|
46
52
|
end
|
47
53
|
end
|
@@ -1,15 +1,12 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
require_relative '../../lib/learn_test/reporter'
|
6
|
-
|
7
3
|
require 'tempfile'
|
8
4
|
require 'json'
|
9
5
|
|
10
6
|
describe LearnTest::Reporter do
|
11
7
|
let!(:client) { instance_spy(LearnTest::Client) }
|
12
|
-
let!(:
|
8
|
+
let!(:git_base) { double(LearnTest::Git::Base) }
|
9
|
+
let!(:git_wip) { double(LearnTest::Git::Wip::Base) }
|
13
10
|
let!(:strategy) do
|
14
11
|
instance_spy(
|
15
12
|
LearnTest::Strategy,
|
@@ -45,43 +42,62 @@ describe LearnTest::Reporter do
|
|
45
42
|
end
|
46
43
|
|
47
44
|
context 'sync with Github' do
|
48
|
-
it 'should not run LearnTest::
|
45
|
+
it 'should not run LearnTest::Git::Wip, if :post_results fails' do
|
49
46
|
expect(client).to receive(:post_results).and_return(false)
|
50
|
-
expect(LearnTest::
|
47
|
+
expect(LearnTest::Git).to_not receive(:open)
|
51
48
|
|
52
49
|
reporter.report
|
53
50
|
end
|
54
51
|
|
55
|
-
it 'should run LearnTest::
|
52
|
+
it 'should run LearnTest::Git::Wip' do
|
53
|
+
branch = double(LearnTest::Git::Wip::Branch)
|
54
|
+
branch_name = 'foo'
|
55
|
+
|
56
56
|
expect(client).to receive(:post_results).and_return(true)
|
57
|
-
expect(LearnTest::
|
57
|
+
expect(LearnTest::Git).to receive(:open).and_return(git_base)
|
58
|
+
expect(git_base).to receive(:wip).and_return(git_wip)
|
59
|
+
expect(git_wip).to receive(:success?).and_return(true)
|
60
|
+
|
61
|
+
expect(branch).to receive(:to_s).and_return(branch_name)
|
62
|
+
expect(git_wip).to receive(:wip_branch).and_return(branch)
|
63
|
+
|
64
|
+
expect(git_base)
|
65
|
+
.to receive(:push)
|
66
|
+
.with('origin', "#{branch_name}:refs/heads/fis-wip", { force: true })
|
58
67
|
|
59
68
|
reporter.report
|
60
69
|
end
|
61
70
|
|
62
71
|
it 'should not output an error message without debug' do
|
63
72
|
expect(client).to receive(:post_results).and_return(true)
|
64
|
-
expect(LearnTest::
|
73
|
+
expect(LearnTest::Git).to receive(:open).and_return(git_base)
|
74
|
+
expect(git_base).to receive(:wip).and_return(git_wip)
|
75
|
+
expect(git_wip).to receive(:success?).and_return(false)
|
76
|
+
|
77
|
+
expect(git_base).to_not receive(:push)
|
65
78
|
|
66
79
|
expect { reporter.report }.to_not output.to_stdout
|
67
80
|
end
|
68
81
|
|
69
82
|
it 'should output an error message with debug' do
|
70
83
|
expect(client).to receive(:post_results).and_return(true)
|
71
|
-
|
84
|
+
|
85
|
+
expect(LearnTest::Git).to receive(:open).and_return(git_base)
|
86
|
+
expect(git_base).to receive(:wip).and_return(git_wip)
|
87
|
+
expect(git_wip).to receive(:success?).and_return(false)
|
88
|
+
|
89
|
+
expect(git_base).to_not receive(:push)
|
72
90
|
|
73
91
|
expect do
|
74
92
|
reporter.debug = true
|
75
93
|
reporter.report
|
76
|
-
end.to output(/
|
94
|
+
end.to output(/There was a problem creating your WIP branch/i).to_stdout
|
77
95
|
end
|
78
96
|
end
|
79
97
|
|
80
98
|
it 'posts results to the service endpoint' do
|
81
99
|
reporter.report
|
82
100
|
|
83
|
-
allow(LearnTest::GitWip).to receive(:run!).and_return(:git_tree)
|
84
|
-
|
85
101
|
expect(client).to have_received(:post_results)
|
86
102
|
.with(strategy.service_endpoint, strategy.results)
|
87
103
|
end
|
@@ -131,7 +147,6 @@ describe LearnTest::Reporter do
|
|
131
147
|
|
132
148
|
it 'deletes the output file when all reports are sent successfully' do
|
133
149
|
allow(client).to receive(:post_results).and_return(true)
|
134
|
-
allow(LearnTest::GitWip).to receive(:run!).and_return(:git_tree)
|
135
150
|
|
136
151
|
reports = { hello: ['world'] }
|
137
152
|
|
@@ -145,7 +160,6 @@ describe LearnTest::Reporter do
|
|
145
160
|
|
146
161
|
it 'writes the remaining reports from the output file' do
|
147
162
|
allow(client).to receive(:post_results).and_return(true, false)
|
148
|
-
allow(LearnTest::GitWip).to receive(:run!).and_return(:git_tree)
|
149
163
|
|
150
164
|
reports = { success: ['world'], failure: ['hello'] }
|
151
165
|
|