File tree 4 files changed +73
-2
lines changed
4 files changed +73
-2
lines changed Original file line number Diff line number Diff line change 8
8
* Add ` RSpec/RepeatedExampleGroupBody ` cop. ([ @lazycoder9 ] [ ] )
9
9
* Add ` RSpec/RepeatedExampleGroupDescription ` cop. ([ @lazycoder9 ] [ ] )
10
10
* Add block name and other lines to ` RSpec/ScatteredSetup ` message. ([ @elebow ] [ ] )
11
+ * Fix ` RSpec/RepeatedDescription ` to take into account example metadata. ([ @lazycoder9 ] [ ] )
11
12
12
13
## 1.37.1 (2019-12-16)
13
14
Original file line number Diff line number Diff line change @@ -29,6 +29,17 @@ module RSpec
29
29
# end
30
30
# end
31
31
#
32
+ # # good
33
+ # RSpec.describe User do
34
+ # it 'is valid' do
35
+ # # ...
36
+ # end
37
+ #
38
+ # it 'is valid', :flag do
39
+ # # ...
40
+ # end
41
+ # end
42
+ #
32
43
class RepeatedDescription < Cop
33
44
MSG = "Don't repeat descriptions within an example group."
34
45
@@ -47,14 +58,18 @@ def repeated_descriptions(node)
47
58
grouped_examples =
48
59
RuboCop ::RSpec ::ExampleGroup . new ( node )
49
60
. examples
50
- . group_by ( & :doc_string )
61
+ . group_by { | example | example_signature ( example ) }
51
62
52
63
grouped_examples
53
- . select { |description , group | description && group . size > 1 }
64
+ . select { |signatures , group | signatures . any? && group . size > 1 }
54
65
. values
55
66
. flatten
56
67
. map ( &:definition )
57
68
end
69
+
70
+ def example_signature ( example )
71
+ [ example . metadata , example . doc_string ]
72
+ end
58
73
end
59
74
end
60
75
end
Original file line number Diff line number Diff line change @@ -2526,6 +2526,17 @@ RSpec.describe User do
2526
2526
# ...
2527
2527
end
2528
2528
end
2529
+
2530
+ # good
2531
+ RSpec .describe User do
2532
+ it ' is valid' do
2533
+ # ...
2534
+ end
2535
+
2536
+ it ' is valid' , :flag do
2537
+ # ...
2538
+ end
2539
+ end
2529
2540
```
2530
2541
2531
2542
### References
Original file line number Diff line number Diff line change 73
73
end
74
74
RUBY
75
75
end
76
+
77
+ it 'does not flag examples if metadata is different' do
78
+ expect_no_offenses ( <<-RUBY )
79
+ describe 'doing x' do
80
+ it 'do something' do
81
+ # ...
82
+ end
83
+
84
+ it 'do something', :flag do
85
+ # ...
86
+ end
87
+ end
88
+ RUBY
89
+ end
90
+
91
+ it 'does not flag examples with same metadata and different description' do
92
+ expect_no_offenses ( <<-RUBY )
93
+ describe 'doing x' do
94
+ it 'do something', :flag do
95
+ # ...
96
+ end
97
+
98
+ it 'do another thing', :flag do
99
+ # ...
100
+ end
101
+ end
102
+ RUBY
103
+ end
104
+
105
+ it 'registers offense for repeated description and metadata' do
106
+ expect_offense ( <<-RUBY )
107
+ describe 'doing x' do
108
+ it 'do something', :flag do
109
+ ^^^^^^^^^^^^^^^^^^^^^^^^ Don't repeat descriptions within an example group.
110
+ # ...
111
+ end
112
+
113
+ it 'do something', :flag do
114
+ ^^^^^^^^^^^^^^^^^^^^^^^^ Don't repeat descriptions within an example group.
115
+ # ...
116
+ end
117
+ end
118
+ RUBY
119
+ end
76
120
end
You can’t perform that action at this time.
0 commit comments