-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathcode_style_validation_spec.rb
More file actions
executable file
·91 lines (65 loc) · 3.17 KB
/
code_style_validation_spec.rb
File metadata and controls
executable file
·91 lines (65 loc) · 3.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
require File.expand_path('../spec_helper', __FILE__)
module Danger
describe Danger::DangerCodeStyleValidation do
it 'should be a plugin' do
expect(Danger::DangerCodeStyleValidation.new(nil)).to be_a Danger::Plugin
end
describe 'with Dangerfile' do
before do
@dangerfile = testing_dangerfile
@my_plugin = @dangerfile.code_style_validation
end
it 'Reports code style violation as error' do
diff = File.read('spec/fixtures/violated_diff.diff')
expected_message = File.read('spec/fixtures/violated_diff_message.md')
allow(@my_plugin.github).to receive(:pr_diff).and_return diff
@my_plugin.check file_extensions: ['.h', '.m', '.mm', '.cpp']
expect(@dangerfile.status_report[:errors]).to eq([DangerCodeStyleValidation::VIOLATION_ERROR_MESSAGE])
expect(@dangerfile.status_report[:markdowns].map(&:message).join("\n")).to eq(expected_message)
end
it 'Does not report error when extension is excluded' do
diff = File.read('spec/fixtures/violated_diff.diff')
allow(@my_plugin.github).to receive(:pr_diff).and_return diff
@my_plugin.check file_extensions: ['.h', '.c']
expect(@dangerfile.status_report[:errors]).to eq([])
end
it 'Does not report error when code not violated' do
diff = File.read('spec/fixtures/innocent_diff.diff')
allow(@my_plugin.github).to receive(:pr_diff).and_return diff
@my_plugin.check
expect(@dangerfile.status_report[:errors]).to eq([])
end
it 'Does not report error for different extension types of files' do
diff = File.read('spec/fixtures/ruby_diff.diff')
allow(@my_plugin.github).to receive(:pr_diff).and_return diff
@my_plugin.check
expect(@dangerfile.status_report[:errors]).to eq([])
end
it 'Does not report unexpected errors when there are only removals in the diff' do
diff = File.read('spec/fixtures/red_diff.diff')
allow(@my_plugin.github).to receive(:pr_diff).and_return diff
@my_plugin.check
expect(@dangerfile.status_report[:errors]).to eq([])
end
it 'Ignores files matching ignored patterns' do
diff = File.read('spec/fixtures/violated_diff.diff')
allow(@my_plugin.github).to receive(:pr_diff).and_return diff
@my_plugin.check file_extensions: ['.h', '.m'],
ignore_file_patterns: [%r{^spec/}]
expect(@dangerfile.status_report[:errors]).to eq([])
end
it 'Allows single pattern instead of array' do
diff = File.read('spec/fixtures/violated_diff.diff')
allow(@my_plugin.github).to receive(:pr_diff).and_return diff
@my_plugin.check ignore_file_patterns: %r{^spec/}
expect(@dangerfile.status_report[:errors]).to eq([])
end
it 'Allows single file extension instead of array' do
diff = File.read('spec/fixtures/violated_diff.diff')
allow(@my_plugin.github).to receive(:pr_diff).and_return diff
@my_plugin.check file_extensions: '.m'
expect(@dangerfile.status_report[:errors]).to eq([DangerCodeStyleValidation::VIOLATION_ERROR_MESSAGE])
end
end
end
end