@@ -12,10 +12,13 @@ module RSpec
1212 #
1313 # @example
1414 # # bad
15- # it { is_expected.to contain_exactly(*array1, *array2) }
15+ # it { is_expected.to contain_exactly(*array) }
16+ #
17+ # # good
18+ # it { is_expected.to match_array(array) }
1619 #
1720 # # good
18- # it { is_expected.to match_array( array1 + array2) }
21+ # it { is_expected.to contain_exactly(* array1, * array2) }
1922 #
2023 # # good
2124 # it { is_expected.to contain_exactly(content, *array) }
@@ -27,29 +30,12 @@ class ContainExactly < Base
2730 RESTRICT_ON_SEND = %i[ contain_exactly ] . freeze
2831
2932 def on_send ( node )
30- return if node . arguments . empty?
31-
32- check_populated_collection ( node )
33- end
34-
35- private
36-
37- def check_populated_collection ( node )
38- return unless node . each_child_node . all? ( &:splat_type? )
33+ return unless node . arguments . one? && node . first_argument . splat_type?
3934
4035 add_offense ( node ) do |corrector |
41- autocorrect_for_populated_array ( node , corrector )
42- end
43- end
44-
45- def autocorrect_for_populated_array ( node , corrector )
46- arrays = node . arguments . map do |splat_node |
47- splat_node . children . first
36+ array = node . first_argument . children . first
37+ corrector . replace ( node , "match_array(#{ array . source } )" )
4838 end
49- corrector . replace (
50- node ,
51- "match_array(#{ arrays . map ( &:source ) . join ( ' + ' ) } )"
52- )
5339 end
5440 end
5541 end
0 commit comments