/
pr_template_spec.rb
115 lines (94 loc) · 3.31 KB
/
pr_template_spec.rb
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe RubocopChallenger::Github::PrTemplate do
describe '#generate' do
let(:pr_template) { described_class.new(rule) }
let(:rule) { RubocopChallenger::Rubocop::Rule.new(<<~CONTENTS) }
# Offense count: 2
# This cop supports safe auto-correction (--auto-correct).
Style/Alias:
Enabled: false
CONTENTS
context 'when normal case' do
let(:expected_template) { <<~EXPECTED }
# Rubocop challenge!
[Style/Alias](https://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Style/Alias)
**Safe autocorrect: true**
:white_check_mark: The auto-correct a cop does is safe (equivalent) by design.
## Description
> ### Overview
>
> This cop enforces the use of either `#alias` or `#alias_method`
> depending on configuration.
> It also flags uses of `alias :symbol` rather than `alias bareword`.
>
> ### Examples
>
> #### EnforcedStyle: prefer_alias (default)
>
> ```rb
> # bad
> alias_method :bar, :foo
> alias :bar :foo
>
> # good
> alias bar foo
> ```
>
> #### EnforcedStyle: prefer_alias_method
>
> ```rb
> # bad
> alias :bar :foo
> alias bar foo
>
> # good
> alias_method :bar, :foo
> ```
Auto generated by [rubocop_challenger](https://github.com/ryz310/rubocop_challenger)
EXPECTED
it 'returns PR template which includes rubydoc link and description' do
expect(pr_template.generate).to eq expected_template
end
end
context 'when any error raised' do
before do
allow(RubocopChallenger::Rubocop::Yardoc)
.to receive(:new).and_raise(error)
end
let(:error) do
Class.new(StandardError) do
def initialize
super('uninitialized constant RuboCop::Cop::Style::Alias')
end
def backtrace
[
'lib/rubocop_challenger/github/pr_template.rb:3:in `yardoc`',
'lib/rubocop_challenger/github/pr_template.rb:2:in `description`',
'lib/rubocop_challenger/github/pr_template.rb:1:in `generate`'
]
end
end
end
let(:expected_template) { <<~EXPECTED }
# Rubocop challenge!
[Style/Alias](https://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Style/Alias)
## Description
Failed to create the cop description.
Please report bugs [here](https://github.com/ryz310/rubocop_challenger/issues/new?assignees=ryz310&labels=bug&template=bug_report.md) with following error information.
```
title: Style/Alias
message: uninitialized constant RuboCop::Cop::Style::Alias
---
lib/rubocop_challenger/github/pr_template.rb:3:in `yardoc`
lib/rubocop_challenger/github/pr_template.rb:2:in `description`
lib/rubocop_challenger/github/pr_template.rb:1:in `generate`
```
Auto generated by [rubocop_challenger](https://github.com/ryz310/rubocop_challenger)
EXPECTED
it 'returns PR template which includes error information' do
expect(pr_template.generate).to eq expected_template
end
end
end
end