-
-
Notifications
You must be signed in to change notification settings - Fork 277
/
Copy pathrepeated_example_spec.rb
92 lines (81 loc) · 2.35 KB
/
repeated_example_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
# frozen_string_literal: true
RSpec.describe RuboCop::Cop::RSpec::RepeatedExample do
it 'registers an offense for repeated example' do
expect_offense(<<~RUBY)
describe 'doing x' do
it "does x" do
^^^^^^^^^^^^^^ Don't repeat examples within an example group.
expect(foo).to be(bar)
end
it "does y" do
^^^^^^^^^^^^^^ Don't repeat examples within an example group.
expect(foo).to be(bar)
end
end
RUBY
end
it 'does not register an offense if rspec tag magic is involved' do
expect_no_offenses(<<~RUBY)
describe 'doing x' do
it "does x" do
expect(foo).to be(bar)
end
it "does y", :focus do
expect(foo).to be(bar)
end
end
RUBY
end
it 'does not flag examples with different implementations' do
expect_no_offenses(<<~RUBY)
describe 'doing x' do
it "does x" do
expect(foo).to have_attribute(foo: 1)
end
it "does y" do
expect(foo).to have_attribute(bar: 2)
end
end
RUBY
end
it 'registers an offense when repeated its are used' do
expect_offense(<<~RUBY)
describe 'doing x' do
its(:x) { is_expected.to be_present }
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Don't repeat examples within an example group.
its(:x) { is_expected.to be_present }
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Don't repeat examples within an example group.
end
RUBY
end
it 'does not flag examples when different its arguments are used' do
expect_no_offenses(<<~RUBY)
describe 'doing x' do
its(:x) { is_expected.to be_present }
its(:y) { is_expected.to be_present }
end
RUBY
end
it 'does not flag examples when different its block expectations are used' do
expect_no_offenses(<<~RUBY)
describe 'doing x' do
its(:x) { is_expected.to be_present }
its(:x) { is_expected.to be_blank }
end
RUBY
end
it 'does not flag repeated examples in different scopes' do
expect_no_offenses(<<~RUBY)
describe 'doing x' do
it "does x" do
expect(foo).to be(bar)
end
context 'when the scope changes' do
it 'does not flag anything' do
expect(foo).to be(bar)
end
end
end
RUBY
end
end