danger-samsao 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.
@@ -0,0 +1,14 @@
1
+ require 'rspec/expectations'
2
+
3
+ RSpec::Matchers.define :have_no_warning do
4
+ match do |actual|
5
+ actual.status_report[:warnings].empty?
6
+ end
7
+
8
+ failure_message do |actual|
9
+ message = "expected that #{Danger} would have no warning but found '#{actual.status_report[:warnings].size}'"
10
+ actual.status_report[:warnings].each do |warning|
11
+ message += "\n * #{warning}"
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,25 @@
1
+ require 'rspec/expectations'
2
+
3
+ RSpec::Matchers.define :have_warning do |expected|
4
+ match do |actual|
5
+ actual.status_report[:warnings].any? do |warning|
6
+ expected.is_a?(Regexp) ? warning =~ matcher : warning.start_with?(expected)
7
+ end
8
+ end
9
+
10
+ failure_message do |actual|
11
+ message = "expected that #{Danger} would have warning '#{expected}'"
12
+
13
+ warnings = actual.status_report[:warnings]
14
+ if warnings.empty?
15
+ message += ' but there is none'
16
+ return message
17
+ end
18
+
19
+ actual.status_report[:warnings].each do |warning|
20
+ message += "\n * #{warning}"
21
+ end
22
+
23
+ message
24
+ end
25
+ end
@@ -0,0 +1,66 @@
1
+ require File.expand_path('../spec_helper', __FILE__)
2
+
3
+ module Danger
4
+ describe Danger::DangerSamsao do
5
+ describe 'with Dangerfile' do
6
+ before do
7
+ @dangerfile = testing_dangerfile
8
+ @plugin = @dangerfile.samsao
9
+ end
10
+
11
+ describe 'branch helpers' do
12
+ it 'supports feature_branch? correctly' do
13
+ data_set = [
14
+ { branch: 'feature/a', expected: true },
15
+ { branch: 'fix/a', expected: false },
16
+ { branch: 'random', expected: false },
17
+ ]
18
+
19
+ data_set.each do |data|
20
+ allow(@plugin.github).to receive(:branch_for_head).and_return(data[:branch])
21
+ expect(@plugin.feature_branch?).to be(data[:expected])
22
+ end
23
+ end
24
+
25
+ it 'supports fix_branch? correctly' do
26
+ data_set = [
27
+ { branch: 'feature/a', expected: false },
28
+ { branch: 'fix/a', expected: true },
29
+ { branch: 'random', expected: false },
30
+ ]
31
+
32
+ data_set.each do |data|
33
+ allow(@plugin.github).to receive(:branch_for_head).and_return(data[:branch])
34
+ expect(@plugin.fix_branch?).to be(data[:expected])
35
+ end
36
+ end
37
+
38
+ it 'supports release_branch? correctly' do
39
+ data_set = [
40
+ { branch: 'release/a', expected: true },
41
+ { branch: 'fix/a', expected: false },
42
+ { branch: 'random', expected: false },
43
+ ]
44
+
45
+ data_set.each do |data|
46
+ allow(@plugin.github).to receive(:branch_for_head).and_return(data[:branch])
47
+ expect(@plugin.release_branch?).to be(data[:expected])
48
+ end
49
+ end
50
+
51
+ it 'supports trivial_branch? correctly' do
52
+ data_set = [
53
+ { branch: 'trivial/a', expected: true },
54
+ { branch: 'fix/a', expected: false },
55
+ { branch: 'random', expected: false },
56
+ ]
57
+
58
+ data_set.each do |data|
59
+ allow(@plugin.github).to receive(:branch_for_head).and_return(data[:branch])
60
+ expect(@plugin.trivial_branch?).to be(data[:expected])
61
+ end
62
+ end
63
+ end
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,41 @@
1
+ require File.expand_path('../spec_helper', __FILE__)
2
+
3
+ module Danger
4
+ describe Danger::DangerSamsao do
5
+ describe 'with Dangerfile' do
6
+ before do
7
+ @dangerfile = testing_dangerfile
8
+ @plugin = @dangerfile.samsao
9
+ @wrong_branching_model = 'Your branch should be prefixed with feature/, fix/, trivial/ or release/!'
10
+ end
11
+
12
+ describe 'branching model' do
13
+ ['fix', 'feature', 'release', 'trivial'].each do |branch_prefix|
14
+ it "continues on #{branch_prefix}/ prefix" do
15
+ allow(@plugin.github).to receive(:branch_for_head).and_return("#{branch_prefix}/something")
16
+
17
+ @plugin.fail_when_wrong_branching_model
18
+
19
+ expect(@dangerfile).to have_no_error
20
+ end
21
+ end
22
+
23
+ it 'fails on wrong prefix' do
24
+ allow(@plugin.github).to receive(:branch_for_head).and_return('wrong/12')
25
+
26
+ @plugin.fail_when_wrong_branching_model
27
+
28
+ expect(@dangerfile).to have_error(@wrong_branching_model)
29
+ end
30
+
31
+ it 'fails on good prefix but wrong format' do
32
+ allow(@plugin.github).to receive(:branch_for_head).and_return('feature_12')
33
+
34
+ @plugin.fail_when_wrong_branching_model
35
+
36
+ expect(@dangerfile).to have_error(@wrong_branching_model)
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,48 @@
1
+ require File.expand_path('../spec_helper', __FILE__)
2
+
3
+ module Danger
4
+ describe Danger::DangerSamsao do
5
+ describe 'with Dangerfile' do
6
+ before do
7
+ @dangerfile = testing_dangerfile
8
+ @plugin = @dangerfile.samsao
9
+ end
10
+
11
+ describe 'changelog updated' do
12
+ it 'returns true when modified with single entry' do
13
+ allow(@plugin.git).to receive(:modified_files).and_return(['CHANGELOG.md'])
14
+
15
+ expect(@plugin.changelog_modified?('CHANGELOG.md')).to be(true)
16
+ end
17
+
18
+ it 'returns true when modified with multiple entries' do
19
+ allow(@plugin.git).to receive(:modified_files).and_return(['CHANGELOG.yml'])
20
+
21
+ expect(@plugin.changelog_modified?('CHANGELOG.md', 'CHANGELOG.yml')).to be(true)
22
+ end
23
+
24
+ it 'returns true when modified with multiple entries and multiple matches' do
25
+ allow(@plugin.git).to receive(:modified_files).and_return(['CHANGELOG.yml', 'CHANGELOG.md'])
26
+
27
+ expect(@plugin.changelog_modified?('CHANGELOG.md', 'CHANGELOG.yml')).to be(true)
28
+ end
29
+
30
+ it 'returns false when not matching file' do
31
+ allow(@plugin.git).to receive(:modified_files).and_return(['CHANGELOG.yml'])
32
+
33
+ expect(@plugin.changelog_modified?('CHANGELOG.md')).to be(false)
34
+ end
35
+
36
+ it 'uses plugin config changelogs when no arguments passed' do
37
+ @plugin.config do
38
+ changelogs 'CHANGELOG.md', 'CHANGELOG.yml'
39
+ end
40
+
41
+ allow(@plugin.git).to receive(:modified_files).and_return(['CHANGELOG.yml'])
42
+
43
+ expect(@plugin.changelog_modified?).to be(true)
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,87 @@
1
+ require File.expand_path('../spec_helper', __FILE__)
2
+
3
+ module Danger
4
+ describe Danger::DangerSamsao do
5
+ describe 'with Dangerfile' do
6
+ before do
7
+ @dangerfile = testing_dangerfile
8
+ @plugin = @dangerfile.samsao
9
+ @changelog_needs_update = 'You did a fix or a feature without updating CHANGELOG file!'
10
+
11
+ allow(@plugin.github).to receive(:pr_title).and_return('Something')
12
+ end
13
+
14
+ describe 'changelog updated' do
15
+ it 'continues on non-feature & non-fix branch' do
16
+ allow(@plugin.github).to receive(:branch_for_head).and_return('trivial/a')
17
+
18
+ @plugin.fail_when_changelog_update_missing
19
+
20
+ expect(@dangerfile).to have_no_error
21
+ end
22
+
23
+ it 'continues on feature branch and CHANGELOG updated' do
24
+ allow(@plugin.github).to receive(:branch_for_head).and_return('feature/a')
25
+ allow(@plugin.git).to receive(:modified_files).and_return(['CHANGELOG.md'])
26
+
27
+ @plugin.fail_when_changelog_update_missing
28
+
29
+ expect(@dangerfile).to have_no_error
30
+ end
31
+
32
+ it 'continues on fix branch and CHANGELOG updated' do
33
+ allow(@plugin.github).to receive(:branch_for_head).and_return('fix/a')
34
+ allow(@plugin.git).to receive(:modified_files).and_return(['CHANGELOG.md'])
35
+
36
+ @plugin.fail_when_changelog_update_missing
37
+
38
+ expect(@dangerfile).to have_no_error
39
+ end
40
+
41
+ it 'accepts customized changelogs path' do
42
+ @plugin.config do
43
+ changelogs 'CHANGELOG.yml'
44
+ end
45
+
46
+ allow(@plugin.github).to receive(:branch_for_head).and_return('fix/a')
47
+ allow(@plugin.git).to receive(:modified_files).and_return(['CHANGELOG.yml'])
48
+
49
+ @plugin.fail_when_changelog_update_missing
50
+
51
+ expect(@dangerfile).to have_no_error
52
+ end
53
+
54
+ it 'accepts multiple changelog paths' do
55
+ @plugin.config do
56
+ changelogs 'CHANGELOG.yml', 'web/CHANGELOG.md'
57
+ end
58
+
59
+ allow(@plugin.github).to receive(:branch_for_head).and_return('fix/a')
60
+ allow(@plugin.git).to receive(:modified_files).and_return(['web/CHANGELOG.md'])
61
+
62
+ @plugin.fail_when_changelog_update_missing
63
+
64
+ expect(@dangerfile).to have_no_error
65
+ end
66
+
67
+ it 'continues on trivial_change and CHANGELOG not updated' do
68
+ allow(@plugin).to receive(:trivial_change?).and_return(true)
69
+ allow(@plugin.git).to receive(:modified_files).and_return([])
70
+
71
+ @plugin.fail_when_changelog_update_missing
72
+
73
+ expect(@dangerfile).to have_no_error
74
+ end
75
+
76
+ it 'fails on feature branch and CHANGELOG not updated' do
77
+ allow(@plugin.github).to receive(:branch_for_head).and_return('feature/a')
78
+ allow(@plugin.git).to receive(:modified_files).and_return([])
79
+
80
+ @plugin.fail_when_changelog_update_missing
81
+
82
+ expect(@dangerfile).to have_error(@changelog_needs_update)
83
+ end
84
+ end
85
+ end
86
+ end
87
+ end
@@ -0,0 +1,30 @@
1
+ require File.expand_path('../spec_helper', __FILE__)
2
+
3
+ module Danger
4
+ describe Danger::DangerSamsao do
5
+ describe 'with Dangerfile' do
6
+ before do
7
+ @dangerfile = testing_dangerfile
8
+ @plugin = @dangerfile.samsao
9
+ end
10
+
11
+ describe 'samsao_config' do
12
+ it 'can configure single source' do
13
+ @plugin.config do
14
+ sources 'app/src'
15
+ end
16
+
17
+ expect(@plugin.config.sources).to eq(['app/src'])
18
+ end
19
+
20
+ it 'can configure multiple sources' do
21
+ @plugin.config do
22
+ sources 'app/src', 'lib/src'
23
+ end
24
+
25
+ expect(@plugin.config.sources).to eq(['app/src', 'lib/src'])
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,42 @@
1
+ require File.expand_path('../spec_helper', __FILE__)
2
+
3
+ module Danger
4
+ describe Danger::DangerSamsao do
5
+ describe 'with Dangerfile' do
6
+ before do
7
+ @dangerfile = testing_dangerfile
8
+ @plugin = @dangerfile.samsao
9
+ @must_have_single_commit = 'Your feature branch should have a single commit but found 2, squash them together!'
10
+ end
11
+
12
+ describe 'feature branch commits' do
13
+ it 'continues on feature branch and one commit' do
14
+ allow(@plugin.github).to receive(:branch_for_head).and_return('feature/a')
15
+ allow(@plugin.git).to receive(:commits).and_return(['sha1'])
16
+
17
+ @plugin.fail_when_non_single_commit_feature
18
+
19
+ expect(@dangerfile).to have_no_error
20
+ end
21
+
22
+ it 'continues on non-feature branch and multiple commits' do
23
+ allow(@plugin.github).to receive(:branch_for_head).and_return('fix/a')
24
+ allow(@plugin.git).to receive(:commits).and_return(['sha1', 'sha2'])
25
+
26
+ @plugin.fail_when_non_single_commit_feature
27
+
28
+ expect(@dangerfile).to have_no_error
29
+ end
30
+
31
+ it 'fails on feature branch and multiple commits' do
32
+ allow(@plugin.github).to receive(:branch_for_head).and_return('feature/a')
33
+ allow(@plugin.git).to receive(:commits).and_return(['sha1', 'sha2'])
34
+
35
+ @plugin.fail_when_non_single_commit_feature
36
+
37
+ expect(@dangerfile).to have_error(@must_have_single_commit)
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,102 @@
1
+ require File.expand_path('../spec_helper', __FILE__)
2
+
3
+ module Danger
4
+ describe Danger::DangerSamsao do
5
+ describe 'with Dangerfile' do
6
+ before do
7
+ @dangerfile = testing_dangerfile
8
+ @plugin = @dangerfile.samsao
9
+
10
+ allow(@plugin.github).to receive(:branch_for_head).and_return('something')
11
+ allow(@plugin.github).to receive(:pr_title).and_return('Something')
12
+ end
13
+
14
+ describe 'has_app_changes?' do
15
+ it 'returns true when single source has changed' do
16
+ allow(@plugin.git).to receive(:modified_files).and_return(['src/a.txt'])
17
+
18
+ expect(@plugin.has_app_changes?('src/')).to be(true)
19
+ end
20
+
21
+ it 'returns true when single nested source has changed' do
22
+ allow(@plugin.git).to receive(:modified_files).and_return(['src/a/b/c.txt'])
23
+
24
+ expect(@plugin.has_app_changes?('src/')).to be(true)
25
+ end
26
+
27
+ it 'returns true when single source has changed with multiple sources defined' do
28
+ allow(@plugin.git).to receive(:modified_files).and_return(['common/src/c.txt'])
29
+
30
+ expect(@plugin.has_app_changes?('common/src/', 'web/src')).to be(true)
31
+ end
32
+
33
+ it 'returns true when single nested source has changed with multiple sources defined' do
34
+ allow(@plugin.git).to receive(:modified_files).and_return(['web/src/a/b/c.txt'])
35
+
36
+ expect(@plugin.has_app_changes?('common/src/', 'web/src')).to be(true)
37
+ end
38
+
39
+ it 'returns true when multiple nested source has changed' do
40
+ allow(@plugin.git).to receive(:modified_files).and_return(['c.txt', 'src/a/c.txt'])
41
+
42
+ expect(@plugin.has_app_changes?('src')).to be(true)
43
+ end
44
+
45
+ it 'returns true when multiple nested source has changed with multiple sources' do
46
+ allow(@plugin.git).to receive(:modified_files).and_return([
47
+ 'c.txt',
48
+ 'common/src/a/c.txt',
49
+ 'web/src/a/c.txt',
50
+ ])
51
+
52
+ expect(@plugin.has_app_changes?('common/src', 'web/src')).to be(true)
53
+ end
54
+
55
+ it 'returns false when source is in the middle of a modified file' do
56
+ allow(@plugin.git).to receive(:modified_files).and_return([
57
+ 'a/src/c.txt',
58
+ 'a/src.txt',
59
+ ])
60
+
61
+ expect(@plugin.has_app_changes?('src')).to be(false)
62
+ end
63
+
64
+ it 'returns false when no source has changed' do
65
+ allow(@plugin.git).to receive(:modified_files).and_return([
66
+ 'c.txt',
67
+ 'common/a/c.txt',
68
+ 'web/a/c.txt',
69
+ ])
70
+
71
+ expect(@plugin.has_app_changes?('src')).to be(false)
72
+ end
73
+
74
+ it 'returns false when no source has changed with multiple sources' do
75
+ allow(@plugin.git).to receive(:modified_files).and_return([
76
+ 'c.txt',
77
+ 'common/a/c.txt',
78
+ 'web/a/c.txt',
79
+ ])
80
+
81
+ expect(@plugin.has_app_changes?('common/src', 'web/src')).to be(false)
82
+ end
83
+
84
+ it 'supports regexp source' do
85
+ allow(@plugin.git).to receive(:modified_files).and_return(['ab/1.txt'])
86
+
87
+ expect(@plugin.has_app_changes?(%r{[abc]+/[123]\.txt})).to be(true)
88
+ end
89
+
90
+ it 'uses plugin config sources when no arguments passed' do
91
+ @plugin.config do
92
+ sources %r{[abc]+/[123]\.txt}
93
+ end
94
+
95
+ allow(@plugin.git).to receive(:modified_files).and_return(['ab/1.txt'])
96
+
97
+ expect(@plugin.has_app_changes?).to be(true)
98
+ end
99
+ end
100
+ end
101
+ end
102
+ end