rubocop-rspec 1.7.0 → 3.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (193) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +955 -79
  3. data/CODE_OF_CONDUCT.md +17 -0
  4. data/MIT-LICENSE.md +1 -2
  5. data/README.md +35 -35
  6. data/config/default.yml +940 -52
  7. data/config/obsoletion.yml +30 -0
  8. data/lib/rubocop/cop/rspec/align_left_let_brace.rb +49 -0
  9. data/lib/rubocop/cop/rspec/align_right_let_brace.rb +49 -0
  10. data/lib/rubocop/cop/rspec/any_instance.rb +10 -13
  11. data/lib/rubocop/cop/rspec/around_block.rb +97 -0
  12. data/lib/rubocop/cop/rspec/base.rb +26 -0
  13. data/lib/rubocop/cop/rspec/be.rb +39 -0
  14. data/lib/rubocop/cop/rspec/be_empty.rb +45 -0
  15. data/lib/rubocop/cop/rspec/be_eq.rb +47 -0
  16. data/lib/rubocop/cop/rspec/be_eql.rb +18 -15
  17. data/lib/rubocop/cop/rspec/be_nil.rb +74 -0
  18. data/lib/rubocop/cop/rspec/before_after_all.rb +45 -0
  19. data/lib/rubocop/cop/rspec/change_by_zero.rb +184 -0
  20. data/lib/rubocop/cop/rspec/class_check.rb +101 -0
  21. data/lib/rubocop/cop/rspec/contain_exactly.rb +56 -0
  22. data/lib/rubocop/cop/rspec/context_method.rb +57 -0
  23. data/lib/rubocop/cop/rspec/context_wording.rb +117 -0
  24. data/lib/rubocop/cop/rspec/describe_class.rb +52 -21
  25. data/lib/rubocop/cop/rspec/describe_method.rb +26 -11
  26. data/lib/rubocop/cop/rspec/describe_symbol.rb +37 -0
  27. data/lib/rubocop/cop/rspec/described_class.rb +181 -34
  28. data/lib/rubocop/cop/rspec/described_class_module_wrapping.rb +38 -0
  29. data/lib/rubocop/cop/rspec/dialect.rb +84 -0
  30. data/lib/rubocop/cop/rspec/duplicated_metadata.rb +58 -0
  31. data/lib/rubocop/cop/rspec/empty_example_group.rb +134 -47
  32. data/lib/rubocop/cop/rspec/empty_hook.rb +49 -0
  33. data/lib/rubocop/cop/rspec/empty_line_after_example.rb +82 -0
  34. data/lib/rubocop/cop/rspec/empty_line_after_example_group.rb +42 -0
  35. data/lib/rubocop/cop/rspec/empty_line_after_final_let.rb +40 -0
  36. data/lib/rubocop/cop/rspec/empty_line_after_hook.rb +82 -0
  37. data/lib/rubocop/cop/rspec/empty_line_after_subject.rb +36 -0
  38. data/lib/rubocop/cop/rspec/empty_metadata.rb +46 -0
  39. data/lib/rubocop/cop/rspec/empty_output.rb +47 -0
  40. data/lib/rubocop/cop/rspec/eq.rb +47 -0
  41. data/lib/rubocop/cop/rspec/example_length.rb +38 -20
  42. data/lib/rubocop/cop/rspec/example_without_description.rb +98 -0
  43. data/lib/rubocop/cop/rspec/example_wording.rb +117 -27
  44. data/lib/rubocop/cop/rspec/excessive_docstring_spacing.rb +110 -0
  45. data/lib/rubocop/cop/rspec/expect_actual.rb +46 -20
  46. data/lib/rubocop/cop/rspec/expect_change.rb +86 -0
  47. data/lib/rubocop/cop/rspec/expect_in_hook.rb +50 -0
  48. data/lib/rubocop/cop/rspec/expect_in_let.rb +42 -0
  49. data/lib/rubocop/cop/rspec/expect_output.rb +50 -0
  50. data/lib/rubocop/cop/rspec/focus.rb +79 -25
  51. data/lib/rubocop/cop/rspec/hook_argument.rb +48 -36
  52. data/lib/rubocop/cop/rspec/hooks_before_examples.rb +81 -0
  53. data/lib/rubocop/cop/rspec/identical_equality_assertion.rb +37 -0
  54. data/lib/rubocop/cop/rspec/implicit_block_expectation.rb +68 -0
  55. data/lib/rubocop/cop/rspec/implicit_expect.rb +100 -0
  56. data/lib/rubocop/cop/rspec/implicit_subject.rb +167 -0
  57. data/lib/rubocop/cop/rspec/indexed_let.rb +112 -0
  58. data/lib/rubocop/cop/rspec/instance_spy.rb +74 -0
  59. data/lib/rubocop/cop/rspec/instance_variable.rb +28 -14
  60. data/lib/rubocop/cop/rspec/is_expected_specify.rb +45 -0
  61. data/lib/rubocop/cop/rspec/it_behaves_like.rb +49 -0
  62. data/lib/rubocop/cop/rspec/iterated_expectation.rb +74 -0
  63. data/lib/rubocop/cop/rspec/leading_subject.rb +57 -29
  64. data/lib/rubocop/cop/rspec/leaky_constant_declaration.rb +127 -0
  65. data/lib/rubocop/cop/rspec/let_before_examples.rb +101 -0
  66. data/lib/rubocop/cop/rspec/let_setup.rb +32 -16
  67. data/lib/rubocop/cop/rspec/match_array.rb +59 -0
  68. data/lib/rubocop/cop/rspec/message_chain.rb +10 -15
  69. data/lib/rubocop/cop/rspec/message_expectation.rb +12 -9
  70. data/lib/rubocop/cop/rspec/message_spies.rb +88 -0
  71. data/lib/rubocop/cop/rspec/metadata_style.rb +202 -0
  72. data/lib/rubocop/cop/rspec/missing_example_group_argument.rb +35 -0
  73. data/lib/rubocop/cop/rspec/missing_expectation_target_method.rb +54 -0
  74. data/lib/rubocop/cop/rspec/mixin/comments_help.rb +38 -0
  75. data/lib/rubocop/cop/rspec/mixin/empty_line_separation.rb +59 -0
  76. data/lib/rubocop/cop/rspec/mixin/file_help.rb +14 -0
  77. data/lib/rubocop/cop/rspec/mixin/final_end_location.rb +19 -0
  78. data/lib/rubocop/cop/rspec/mixin/inside_example_group.rb +29 -0
  79. data/lib/rubocop/cop/rspec/mixin/location_help.rb +37 -0
  80. data/lib/rubocop/cop/rspec/mixin/metadata.rb +63 -0
  81. data/lib/rubocop/cop/rspec/mixin/namespace.rb +23 -0
  82. data/lib/rubocop/cop/rspec/mixin/skip_or_pending.rb +39 -0
  83. data/lib/rubocop/cop/rspec/mixin/top_level_group.rb +54 -0
  84. data/lib/rubocop/cop/rspec/mixin/variable.rb +21 -0
  85. data/lib/rubocop/cop/rspec/multiple_describes.rb +14 -12
  86. data/lib/rubocop/cop/rspec/multiple_expectations.rb +86 -26
  87. data/lib/rubocop/cop/rspec/multiple_memoized_helpers.rb +146 -0
  88. data/lib/rubocop/cop/rspec/multiple_subjects.rb +97 -0
  89. data/lib/rubocop/cop/rspec/named_subject.rb +107 -27
  90. data/lib/rubocop/cop/rspec/nested_groups.rb +84 -47
  91. data/lib/rubocop/cop/rspec/no_expectation_example.rb +102 -0
  92. data/lib/rubocop/cop/rspec/not_to_not.rb +30 -27
  93. data/lib/rubocop/cop/rspec/overwriting_setup.rb +74 -0
  94. data/lib/rubocop/cop/rspec/pending.rb +80 -0
  95. data/lib/rubocop/cop/rspec/pending_without_reason.rb +159 -0
  96. data/lib/rubocop/cop/rspec/predicate_matcher.rb +341 -0
  97. data/lib/rubocop/cop/rspec/receive_counts.rb +89 -0
  98. data/lib/rubocop/cop/rspec/receive_messages.rb +161 -0
  99. data/lib/rubocop/cop/rspec/receive_never.rb +41 -0
  100. data/lib/rubocop/cop/rspec/redundant_around.rb +65 -0
  101. data/lib/rubocop/cop/rspec/redundant_predicate_matcher.rb +67 -0
  102. data/lib/rubocop/cop/rspec/remove_const.rb +39 -0
  103. data/lib/rubocop/cop/rspec/repeated_description.rb +98 -0
  104. data/lib/rubocop/cop/rspec/repeated_example.rb +53 -0
  105. data/lib/rubocop/cop/rspec/repeated_example_group_body.rb +100 -0
  106. data/lib/rubocop/cop/rspec/repeated_example_group_description.rb +96 -0
  107. data/lib/rubocop/cop/rspec/repeated_include_example.rb +105 -0
  108. data/lib/rubocop/cop/rspec/repeated_subject_call.rb +125 -0
  109. data/lib/rubocop/cop/rspec/return_from_stub.rb +169 -0
  110. data/lib/rubocop/cop/rspec/scattered_let.rb +59 -0
  111. data/lib/rubocop/cop/rspec/scattered_setup.rb +92 -0
  112. data/lib/rubocop/cop/rspec/shared_context.rb +107 -0
  113. data/lib/rubocop/cop/rspec/shared_examples.rb +125 -0
  114. data/lib/rubocop/cop/rspec/single_argument_message_chain.rb +93 -0
  115. data/lib/rubocop/cop/rspec/skip_block_inside_example.rb +46 -0
  116. data/lib/rubocop/cop/rspec/sort_metadata.rb +71 -0
  117. data/lib/rubocop/cop/rspec/spec_file_path_format.rb +133 -0
  118. data/lib/rubocop/cop/rspec/spec_file_path_suffix.rb +40 -0
  119. data/lib/rubocop/cop/rspec/stubbed_mock.rb +176 -0
  120. data/lib/rubocop/cop/rspec/subject_declaration.rb +46 -0
  121. data/lib/rubocop/cop/rspec/subject_stub.rb +93 -74
  122. data/lib/rubocop/cop/rspec/undescriptive_literals_description.rb +69 -0
  123. data/lib/rubocop/cop/rspec/unspecified_exception.rb +67 -0
  124. data/lib/rubocop/cop/rspec/variable_definition.rb +77 -0
  125. data/lib/rubocop/cop/rspec/variable_name.rb +68 -0
  126. data/lib/rubocop/cop/rspec/verified_double_reference.rb +111 -0
  127. data/lib/rubocop/cop/rspec/verified_doubles.rb +28 -14
  128. data/lib/rubocop/cop/rspec/void_expect.rb +60 -0
  129. data/lib/rubocop/cop/rspec/yield.rb +82 -0
  130. data/lib/rubocop/cop/rspec_cops.rb +112 -0
  131. data/lib/rubocop/rspec/align_let_brace.rb +63 -0
  132. data/lib/rubocop/rspec/concept.rb +33 -0
  133. data/lib/rubocop/rspec/config_formatter.rb +27 -4
  134. data/lib/rubocop/rspec/cop/generator.rb +25 -0
  135. data/lib/rubocop/rspec/corrector/move_node.rb +51 -0
  136. data/lib/rubocop/rspec/description_extractor.rb +60 -18
  137. data/lib/rubocop/rspec/example.rb +37 -0
  138. data/lib/rubocop/rspec/example_group.rb +67 -0
  139. data/lib/rubocop/rspec/hook.rb +79 -0
  140. data/lib/rubocop/rspec/inject.rb +3 -1
  141. data/lib/rubocop/rspec/language.rb +184 -41
  142. data/lib/rubocop/rspec/node.rb +19 -0
  143. data/lib/rubocop/rspec/shared_contexts/default_rspec_language_config_context.rb +29 -0
  144. data/lib/rubocop/rspec/version.rb +1 -1
  145. data/lib/rubocop/rspec/wording.rb +61 -19
  146. data/lib/rubocop/rspec.rb +6 -2
  147. data/lib/rubocop-rspec.rb +45 -34
  148. metadata +130 -195
  149. data/Gemfile +0 -13
  150. data/Rakefile +0 -48
  151. data/lib/rubocop/cop/rspec/file_path.rb +0 -83
  152. data/lib/rubocop/rspec/language/node_pattern.rb +0 -16
  153. data/lib/rubocop/rspec/spec_only.rb +0 -61
  154. data/lib/rubocop/rspec/top_level_describe.rb +0 -61
  155. data/lib/rubocop/rspec/util.rb +0 -19
  156. data/rubocop-rspec.gemspec +0 -42
  157. data/spec/expect_violation/expectation_spec.rb +0 -85
  158. data/spec/project/changelog_spec.rb +0 -81
  159. data/spec/project/default_config_spec.rb +0 -52
  160. data/spec/project/project_requires_spec.rb +0 -8
  161. data/spec/rubocop/cop/rspec/any_instance_spec.rb +0 -30
  162. data/spec/rubocop/cop/rspec/be_eql_spec.rb +0 -59
  163. data/spec/rubocop/cop/rspec/describe_class_spec.rb +0 -113
  164. data/spec/rubocop/cop/rspec/describe_method_spec.rb +0 -32
  165. data/spec/rubocop/cop/rspec/described_class_spec.rb +0 -219
  166. data/spec/rubocop/cop/rspec/empty_example_group_spec.rb +0 -79
  167. data/spec/rubocop/cop/rspec/example_length_spec.rb +0 -117
  168. data/spec/rubocop/cop/rspec/example_wording_spec.rb +0 -82
  169. data/spec/rubocop/cop/rspec/expect_actual_spec.rb +0 -136
  170. data/spec/rubocop/cop/rspec/file_path_spec.rb +0 -236
  171. data/spec/rubocop/cop/rspec/focus_spec.rb +0 -130
  172. data/spec/rubocop/cop/rspec/hook_argument_spec.rb +0 -189
  173. data/spec/rubocop/cop/rspec/instance_variable_spec.rb +0 -75
  174. data/spec/rubocop/cop/rspec/leading_subject_spec.rb +0 -54
  175. data/spec/rubocop/cop/rspec/let_setup_spec.rb +0 -66
  176. data/spec/rubocop/cop/rspec/message_chain_spec.rb +0 -21
  177. data/spec/rubocop/cop/rspec/message_expectation_spec.rb +0 -63
  178. data/spec/rubocop/cop/rspec/multiple_describes_spec.rb +0 -28
  179. data/spec/rubocop/cop/rspec/multiple_expectations_spec.rb +0 -84
  180. data/spec/rubocop/cop/rspec/named_subject_spec.rb +0 -62
  181. data/spec/rubocop/cop/rspec/nested_groups_spec.rb +0 -55
  182. data/spec/rubocop/cop/rspec/not_to_not_spec.rb +0 -57
  183. data/spec/rubocop/cop/rspec/subject_stub_spec.rb +0 -183
  184. data/spec/rubocop/cop/rspec/verified_doubles_spec.rb +0 -71
  185. data/spec/rubocop/rspec/config_formatter_spec.rb +0 -48
  186. data/spec/rubocop/rspec/description_extractor_spec.rb +0 -35
  187. data/spec/rubocop/rspec/language/selector_set_spec.rb +0 -29
  188. data/spec/rubocop/rspec/spec_only_spec.rb +0 -97
  189. data/spec/rubocop/rspec/util/one_spec.rb +0 -21
  190. data/spec/rubocop/rspec/wording_spec.rb +0 -44
  191. data/spec/shared/rspec_only_cop_behavior.rb +0 -68
  192. data/spec/spec_helper.rb +0 -41
  193. data/spec/support/expect_violation.rb +0 -166
@@ -1,61 +0,0 @@
1
- module RuboCop
2
- module RSpec
3
- # Helper methods for top level describe cops
4
- module TopLevelDescribe
5
- extend NodePattern::Macros
6
-
7
- def_node_matcher :described_constant, <<-PATTERN
8
- (block $(send _ :describe $(const ...)) (args) $_)
9
- PATTERN
10
-
11
- def on_send(node)
12
- return unless respond_to?(:on_top_level_describe)
13
- return unless top_level_describe?(node)
14
-
15
- _receiver, _method_name, *args = *node
16
-
17
- on_top_level_describe(node, args)
18
- end
19
-
20
- private
21
-
22
- def top_level_describe?(node)
23
- _receiver, method_name, *_args = *node
24
- return false unless method_name == :describe
25
-
26
- top_level_nodes.include?(node)
27
- end
28
-
29
- def top_level_nodes
30
- nodes = describe_statement_children(root_node)
31
- # If we have no top level describe statements, we need to check any
32
- # blocks on the top level (e.g. after a require).
33
- if nodes.empty?
34
- nodes = node_children(root_node).map do |child|
35
- describe_statement_children(child) if child.type == :block
36
- end.flatten.compact
37
- end
38
-
39
- nodes
40
- end
41
-
42
- def root_node
43
- processed_source.ast
44
- end
45
-
46
- def single_top_level_describe?
47
- top_level_nodes.count == 1
48
- end
49
-
50
- def describe_statement_children(node)
51
- node_children(node).select do |element|
52
- element.type == :send && element.children[1] == :describe
53
- end
54
- end
55
-
56
- def node_children(node)
57
- node.children.select { |e| e.is_a? Parser::AST::Node }
58
- end
59
- end
60
- end
61
- end
@@ -1,19 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module RuboCop
4
- module RSpec
5
- # Utility methods
6
- module Util
7
- # Error raised by `Util.one` if size is less than zero or greater than one
8
- SizeError = Class.new(IndexError)
9
-
10
- # Return only element in array if it contains exactly one member
11
- def one(array)
12
- return array.first if array.one?
13
-
14
- raise SizeError,
15
- "expected size to be exactly 1 but size was #{array.size}"
16
- end
17
- end
18
- end
19
- end
@@ -1,42 +0,0 @@
1
- # encoding: utf-8
2
-
3
- $LOAD_PATH.unshift File.expand_path('../lib', __FILE__)
4
- require 'rubocop/rspec/version'
5
-
6
- Gem::Specification.new do |spec|
7
- spec.name = 'rubocop-rspec'
8
- spec.summary = 'Code style checking for RSpec files'
9
- spec.description = <<-end_description
10
- Code style checking for RSpec files.
11
- A plugin for the RuboCop code style enforcing & linting tool.
12
- end_description
13
- spec.homepage = 'http://github.com/nevir/rubocop-rspec'
14
- spec.authors = ['Ian MacLeod', 'Nils Gemeinhardt']
15
- spec.email = ['ian@nevir.net', 'git@nilsgemeinhardt.de']
16
- spec.licenses = ['MIT']
17
-
18
- spec.version = RuboCop::RSpec::Version::STRING
19
- spec.platform = Gem::Platform::RUBY
20
- spec.required_ruby_version = '>= 2.2.0'
21
-
22
- spec.require_paths = ['lib']
23
- spec.files = Dir[
24
- '{config,lib,spec}/**/*',
25
- '*.md',
26
- '*.gemspec',
27
- 'Gemfile',
28
- 'Rakefile'
29
- ]
30
- spec.test_files = spec.files.grep(%r{^spec/})
31
- spec.extra_rdoc_files = ['MIT-LICENSE.md', 'README.md']
32
-
33
- spec.add_runtime_dependency 'rubocop', '>= 0.42.0'
34
-
35
- spec.add_development_dependency 'rake'
36
- spec.add_development_dependency 'rspec', '>= 3.4'
37
- spec.add_development_dependency 'simplecov'
38
- spec.add_development_dependency 'anima'
39
- spec.add_development_dependency 'concord'
40
- spec.add_development_dependency 'adamantium'
41
- spec.add_development_dependency 'yard'
42
- end
@@ -1,85 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.describe ExpectViolation::Expectation do
4
- subject(:expectation) { described_class.new(string) }
5
-
6
- context 'when given a single assertion on class end' do
7
- let(:string) do
8
- <<-SRC
9
- class Foo
10
- end
11
- ^^^ The end of `Foo` should be annotated.
12
- SRC
13
- end
14
-
15
- let(:assertion) { expectation.assertions.first }
16
-
17
- it 'has one assertion' do
18
- expect(expectation.assertions.size).to be(1)
19
- end
20
-
21
- it 'has an assertion on line 2' do
22
- expect(assertion.line_number).to be(2)
23
- end
24
-
25
- it 'has an assertion on column range 1-3' do
26
- expect(assertion.column_range).to eql(6...9)
27
- end
28
-
29
- it 'has an assertion with correct violation message' do
30
- expect(assertion.message).to eql('The end of `Foo` should be annotated.')
31
- end
32
-
33
- it 'recreates source' do
34
- expect(expectation.source).to eql(<<-RUBY)
35
- class Foo
36
- end
37
- RUBY
38
- end
39
- end
40
-
41
- context 'when given many assertions on two lines' do
42
- let(:string) do
43
- <<-SRC
44
- foo bar
45
- ^ Charlie
46
- ^^ Charlie
47
- ^^ Bronco
48
- ^^ Alpha
49
- baz
50
- ^ Delta
51
- SRC
52
- end
53
-
54
- let(:assertions) { expectation.assertions.sort }
55
-
56
- it 'has two assertions' do
57
- expect(expectation.assertions.size).to be(5)
58
- end
59
-
60
- it 'has assertions on lines 1 and 2' do
61
- expect(assertions.map(&:line_number)).to eql(
62
- [1, 1, 1, 1, 2]
63
- )
64
- end
65
-
66
- it 'has assertions on column range 1-3' do
67
- expect(assertions.map(&:column_range)).to eql(
68
- [9...11, 10...11, 10...12, 10...12, 6...7]
69
- )
70
- end
71
-
72
- it 'has an assertion with correct violation message' do
73
- expect(assertions.map(&:message)).to eql(
74
- %w(Charlie Charlie Alpha Bronco Delta)
75
- )
76
- end
77
-
78
- it 'recreates source' do
79
- expect(expectation.source).to eql(<<-RUBY)
80
- foo bar
81
- baz
82
- RUBY
83
- end
84
- end
85
- end
@@ -1,81 +0,0 @@
1
- describe 'CHANGELOG.md' do
2
- subject(:changelog) { SpecHelper::ROOT.join('CHANGELOG.md').read }
3
-
4
- it 'has link definitions for all implicit links' do
5
- implicit_link_names = changelog.scan(/\[([^\]]+)\]\[\]/).flatten.uniq
6
- implicit_link_names.each do |name|
7
- expect(changelog).to include("[#{name}]: http")
8
- end
9
- end
10
-
11
- describe 'entry' do
12
- subject(:entries) { lines.grep(/^\*/).map(&:chomp) }
13
- let(:lines) { changelog.each_line }
14
-
15
- it 'has a whitespace between the * and the body' do
16
- entries.each do |entry|
17
- expect(entry).to match(/^\* \S/)
18
- end
19
- end
20
-
21
- it 'has a link to the contributors at the end' do
22
- entries.each do |entry|
23
- expect(entry).to match(/\(\[@\S+\]\[\](?:, \[@\S+\]\[\])*\)$/)
24
- end
25
- end
26
-
27
- describe 'link to related issue on github' do
28
- let(:issues) do
29
- entries.map do |entry|
30
- entry.match(/\[(?<number>[#\d]+)\]\((?<url>[^\)]+)\)/)
31
- end.compact
32
- end
33
-
34
- it 'has an issue number prefixed with #' do
35
- issues.each do |issue|
36
- expect(issue[:number]).to match(/^#\d+$/)
37
- end
38
- end
39
-
40
- it 'has a valid URL' do
41
- issues.each do |issue|
42
- number = issue[:number].gsub(/\D/, '')
43
- pattern = %r{^https://github\.com/.+/.+/(?:issues|pull)/#{number}$} # rubocop:disable LineLength
44
- expect(issue[:url]).to match(pattern)
45
- end
46
- end
47
-
48
- it 'has a colon and a whitespace at the end' do
49
- entries_including_issue_link = entries.select do |entry|
50
- entry.match(/^\*\s*\[/)
51
- end
52
-
53
- entries_including_issue_link.each do |entry|
54
- expect(entry).to include('): ')
55
- end
56
- end
57
- end
58
-
59
- describe 'body' do
60
- let(:bodies) do
61
- entries.map do |entry|
62
- entry
63
- .sub(/^\*\s*(?:\[.+?\):\s*)?/, '')
64
- .sub(/\s*\([^\)]+\)$/, '')
65
- end
66
- end
67
-
68
- it 'does not start with a lower case' do
69
- bodies.each do |body|
70
- expect(body).not_to match(/^[a-z]/)
71
- end
72
- end
73
-
74
- it 'ends with a punctuation' do
75
- bodies.each do |body|
76
- expect(body).to match(/[\.\!]$/)
77
- end
78
- end
79
- end
80
- end
81
- end
@@ -1,52 +0,0 @@
1
- describe 'config/default.yml' do
2
- subject(:default_config) do
3
- RuboCop::ConfigLoader.load_file('config/default.yml')
4
- end
5
-
6
- let(:cop_names) do
7
- glob = SpecHelper::ROOT.join('lib', 'rubocop', 'cop', 'rspec', '*.rb')
8
-
9
- Pathname.glob(glob).map do |file|
10
- file_name = file.basename('.rb').to_s
11
- cop_name = file_name.gsub(/(^|_)(.)/) { Regexp.last_match(2).upcase }
12
-
13
- "RSpec/#{cop_name}"
14
- end
15
- end
16
-
17
- let(:config_keys) do
18
- cop_names + %w(AllCops)
19
- end
20
-
21
- def cop_configuration(config_key)
22
- cop_names.map do |cop_name|
23
- cop_config = default_config.fetch(cop_name)
24
-
25
- cop_config.fetch(config_key) do
26
- raise "Expected #{cop_name} to have #{config_key} configuration key"
27
- end
28
- end
29
- end
30
-
31
- it 'has configuration for all cops' do
32
- expect(default_config.keys.sort).to eq(config_keys.sort)
33
- end
34
-
35
- it 'has descriptions for all cops' do
36
- expect(cop_configuration('Description')).to all(be_a(String))
37
- end
38
-
39
- it 'does not have newlines in cop descriptions' do
40
- cop_configuration('Description').each do |value|
41
- expect(value).not_to include("\n")
42
- end
43
- end
44
-
45
- it 'ends every description with a period' do
46
- expect(cop_configuration('Description')).to all(end_with('.'))
47
- end
48
-
49
- it 'includes Enabled: true for every cop' do
50
- expect(cop_configuration('Enabled')).to all(be(true))
51
- end
52
- end
@@ -1,8 +0,0 @@
1
- describe 'Project requires' do
2
- it 'alphabetizes cop requires' do
3
- source = SpecHelper::ROOT.join('lib', 'rubocop-rspec.rb').read
4
- requires = source.split("\n").grep(%r{rubocop/cop})
5
-
6
- expect(requires.join("\n")).to eql(requires.sort.join("\n"))
7
- end
8
- end
@@ -1,30 +0,0 @@
1
- describe RuboCop::Cop::RSpec::AnyInstance do
2
- subject(:cop) { described_class.new }
3
-
4
- it 'finds `allow_any_instance_of` instead of an instance double' do
5
- expect_violation(<<-RUBY)
6
- before do
7
- allow_any_instance_of(Object).to receive(:foo)
8
- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Avoid stubbing using `allow_any_instance_of`
9
- end
10
- RUBY
11
- end
12
-
13
- it 'finds `expect_any_instance_of` instead of an instance double' do
14
- expect_violation(<<-RUBY)
15
- before do
16
- expect_any_instance_of(Object).to receive(:foo)
17
- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Avoid stubbing using `expect_any_instance_of`
18
- end
19
- RUBY
20
- end
21
-
22
- it 'finds old `any_instance` syntax instead of an instance double' do
23
- expect_violation(<<-RUBY)
24
- before do
25
- Object.any_instance.should_receive(:foo)
26
- ^^^^^^^^^^^^^^^^^^^ Avoid stubbing using `any_instance`
27
- end
28
- RUBY
29
- end
30
- end
@@ -1,59 +0,0 @@
1
- describe RuboCop::Cop::RSpec::BeEql do
2
- subject(:cop) { described_class.new }
3
-
4
- it 'registers an offense for `eql` when argument is a boolean' do
5
- expect_violation(<<-RUBY)
6
- it { expect(foo).to eql(true) }
7
- ^^^ Prefer `be` over `eql`
8
- it { expect(foo).to eql(false) }
9
- ^^^ Prefer `be` over `eql`
10
- RUBY
11
- end
12
-
13
- it 'registers an offense for `eql` when argument is an integer' do
14
- expect_violation(<<-RUBY)
15
- it { expect(foo).to eql(0) }
16
- ^^^ Prefer `be` over `eql`
17
- it { expect(foo).to eql(123) }
18
- ^^^ Prefer `be` over `eql`
19
- RUBY
20
- end
21
-
22
- it 'registers an offense for `eql` when argument is a float' do
23
- expect_violation(<<-RUBY)
24
- it { expect(foo).to eql(1.0) }
25
- ^^^ Prefer `be` over `eql`
26
- it { expect(foo).to eql(1.23) }
27
- ^^^ Prefer `be` over `eql`
28
- RUBY
29
- end
30
-
31
- it 'registers an offense for `eql` when argument is a symbol' do
32
- expect_violation(<<-RUBY)
33
- it { expect(foo).to eql(:foo) }
34
- ^^^ Prefer `be` over `eql`
35
- RUBY
36
- end
37
-
38
- it 'does not register an offense for `eql` when argument is a string' do
39
- expect_no_violations(<<-RUBY)
40
- it { expect(foo).to eql('foo') }
41
- RUBY
42
- end
43
-
44
- it 'does not register an offense for `eql` when expectation is negated' do
45
- expect_no_violations(<<-RUBY)
46
- it { expect(foo).to_not eql(1) }
47
- RUBY
48
- end
49
-
50
- it 'autocorrects offense to use `be`' do
51
- corrected =
52
- autocorrect_source(
53
- cop,
54
- ['it { expect(foo).to eql(1) }'],
55
- 'spec/foo_spec.rb'
56
- )
57
- expect(corrected).to eq 'it { expect(foo).to be(1) }'
58
- end
59
- end
@@ -1,113 +0,0 @@
1
- describe RuboCop::Cop::RSpec::DescribeClass do
2
- subject(:cop) { described_class.new }
3
-
4
- it 'checks first-line describe statements' do
5
- expect_violation(<<-RUBY)
6
- describe "bad describe" do
7
- ^^^^^^^^^^^^^^ The first argument to describe should be the class or module being tested.
8
- end
9
- RUBY
10
- end
11
-
12
- it 'supports RSpec.describe' do
13
- expect_no_violations(<<-RUBY)
14
- RSpec.describe Foo do
15
- end
16
- RUBY
17
- end
18
-
19
- it 'checks describe statements after a require' do
20
- expect_violation(<<-RUBY)
21
- require 'spec_helper'
22
- describe "bad describe" do
23
- ^^^^^^^^^^^^^^ The first argument to describe should be the class or module being tested.
24
- end
25
- RUBY
26
- end
27
-
28
- it 'checks highlights the first argument of a describe' do
29
- expect_violation(<<-RUBY)
30
- describe "bad describe", "blah blah" do
31
- ^^^^^^^^^^^^^^ The first argument to describe should be the class or module being tested.
32
- end
33
- RUBY
34
- end
35
-
36
- it 'ignores nested describe statements' do
37
- expect_no_violations(<<-RUBY)
38
- describe Some::Class do
39
- describe "bad describe" do
40
- end
41
- end
42
- RUBY
43
- end
44
-
45
- it 'ignores request specs' do
46
- expect_no_violations(<<-RUBY)
47
- describe 'my new feature', type: :request do
48
- end
49
- RUBY
50
- end
51
-
52
- it 'ignores feature specs' do
53
- expect_no_violations(<<-RUBY)
54
- describe 'my new feature', type: :feature do
55
- end
56
- RUBY
57
- end
58
-
59
- it 'ignores feature specs when RSpec.describe is used' do
60
- expect_no_violations(<<-RUBY)
61
- RSpec.describe 'my new feature', type: :feature do
62
- end
63
- RUBY
64
- end
65
-
66
- it 'flags specs with non :type metadata' do
67
- expect_violation(<<-RUBY)
68
- describe 'my new feature', foo: :feature do
69
- ^^^^^^^^^^^^^^^^ The first argument to describe should be the class or module being tested.
70
- end
71
- RUBY
72
- end
73
-
74
- it 'flags normal metadata in describe' do
75
- expect_violation(<<-RUBY)
76
- describe 'my new feature', blah, type: :wow do
77
- ^^^^^^^^^^^^^^^^ The first argument to describe should be the class or module being tested.
78
- end
79
- RUBY
80
- end
81
-
82
- it 'ignores feature specs - also with complex options' do
83
- expect_no_violations(<<-RUBY)
84
- describe 'my new feature', :test, :type => :feature, :foo => :bar do
85
- end
86
- RUBY
87
- end
88
-
89
- it 'ignores an empty describe' do
90
- expect_no_violations(<<-RUBY)
91
- describe do
92
- end
93
- RUBY
94
- end
95
-
96
- it 'ignores routing specs' do
97
- expect_no_violations(<<-RUBY)
98
- describe 'my new route', type: :routing do
99
- end
100
- RUBY
101
- end
102
-
103
- it 'ignores view specs' do
104
- expect_no_violations(<<-RUBY)
105
- describe 'widgets/index', type: :view do
106
- end
107
- RUBY
108
- end
109
-
110
- it "doesn't blow up on single-line describes" do
111
- expect_no_violations('describe Some::Class')
112
- end
113
- end
@@ -1,32 +0,0 @@
1
- describe RuboCop::Cop::RSpec::DescribeMethod do
2
- subject(:cop) { described_class.new }
3
-
4
- it 'ignores describes with only a class' do
5
- expect_no_violations('describe Some::Class do; end')
6
- end
7
-
8
- it 'enforces non-method names' do
9
- expect_violation(<<-RUBY)
10
- describe Some::Class, 'nope', '.incorrect_usage' do
11
- ^^^^^^ The second argument to describe should be the method being tested. '#instance' or '.class'
12
- end
13
- RUBY
14
- end
15
-
16
- it 'skips methods starting with a . or #' do
17
- expect_no_violations(<<-RUBY)
18
- describe Some::Class, '.asdf' do
19
- end
20
-
21
- describe Some::Class, '#fdsa' do
22
- end
23
- RUBY
24
- end
25
-
26
- it 'skips specs not having a string second argument' do
27
- expect_no_violations(<<-RUBY)
28
- describe Some::Class, :config do
29
- end
30
- RUBY
31
- end
32
- end