/
dialect_spec.rb
76 lines (67 loc) · 1.69 KB
/
dialect_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
# frozen_string_literal: true
RSpec.describe RuboCop::Cop::RSpec::Dialect do
let(:cop_config) do
{
'PreferredMethods' => {
'context' => 'describe'
}
}
end
it 'allows describe blocks', x: true do
expect_no_offenses(<<-RUBY)
describe 'display name presence' do
end
RUBY
end
it 'allows calling methods named context in examples' do
expect_no_offenses(<<-RUBY)
it 'tests common context invocations' do
expect(request.context).to be_empty?
end
RUBY
end
it 'registers an offense for context blocks' do
expect_offense(<<-RUBY)
context 'display name presence' do
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Prefer `describe` over `context`.
end
RUBY
expect_correction(<<-RUBY)
describe 'display name presence' do
end
RUBY
end
it 'registers an offense for RSpec.context blocks' do
expect_offense(<<-RUBY)
RSpec.context 'context' do
^^^^^^^^^^^^^^^^^^^^^^^ Prefer `describe` over `context`.
it 'tests common context invocations' do
expect(request.context).to be_empty?
end
end
RUBY
expect_correction(<<-RUBY)
RSpec.describe 'context' do
it 'tests common context invocations' do
expect(request.context).to be_empty?
end
end
RUBY
end
context 'without preferred methods' do
let(:cop_config) do
{
'PreferredMethods' => {}
}
end
it 'allows all methods blocks' do
expect_no_offenses(<<-RUBY)
context 'is important' do
specify 'for someone to work' do
everyone.should have_some_leeway
end
end
RUBY
end
end
end