rubocop-rspec 2.29.1 → 3.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (89) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +92 -3
  3. data/README.md +21 -5
  4. data/config/default.yml +64 -269
  5. data/config/obsoletion.yml +20 -21
  6. data/lib/rubocop/cop/rspec/around_block.rb +2 -4
  7. data/lib/rubocop/cop/rspec/base.rb +0 -1
  8. data/lib/rubocop/cop/rspec/be_eq.rb +1 -1
  9. data/lib/rubocop/cop/rspec/be_eql.rb +1 -1
  10. data/lib/rubocop/cop/rspec/be_nil.rb +4 -0
  11. data/lib/rubocop/cop/rspec/change_by_zero.rb +4 -5
  12. data/lib/rubocop/cop/rspec/contain_exactly.rb +1 -0
  13. data/lib/rubocop/cop/rspec/context_wording.rb +15 -9
  14. data/lib/rubocop/cop/rspec/dialect.rb +13 -0
  15. data/lib/rubocop/cop/rspec/empty_example_group.rb +2 -0
  16. data/lib/rubocop/cop/rspec/empty_metadata.rb +1 -0
  17. data/lib/rubocop/cop/rspec/example_wording.rb +3 -5
  18. data/lib/rubocop/cop/rspec/excessive_docstring_spacing.rb +1 -1
  19. data/lib/rubocop/cop/rspec/expect_actual.rb +3 -3
  20. data/lib/rubocop/cop/rspec/expect_in_hook.rb +1 -1
  21. data/lib/rubocop/cop/rspec/expect_in_let.rb +42 -0
  22. data/lib/rubocop/cop/rspec/focus.rb +14 -16
  23. data/lib/rubocop/cop/rspec/implicit_expect.rb +3 -3
  24. data/lib/rubocop/cop/rspec/implicit_subject.rb +8 -0
  25. data/lib/rubocop/cop/rspec/indexed_let.rb +6 -3
  26. data/lib/rubocop/cop/rspec/leaky_constant_declaration.rb +1 -1
  27. data/lib/rubocop/cop/rspec/match_array.rb +1 -0
  28. data/lib/rubocop/cop/rspec/message_spies.rb +4 -0
  29. data/lib/rubocop/cop/rspec/metadata_style.rb +1 -6
  30. data/lib/rubocop/cop/rspec/missing_expectation_target_method.rb +54 -0
  31. data/lib/rubocop/cop/rspec/mixin/metadata.rb +5 -8
  32. data/lib/rubocop/cop/rspec/mixin/top_level_group.rb +7 -0
  33. data/lib/rubocop/cop/rspec/multiple_describes.rb +1 -1
  34. data/lib/rubocop/cop/rspec/multiple_expectations.rb +4 -4
  35. data/lib/rubocop/cop/rspec/multiple_memoized_helpers.rb +4 -5
  36. data/lib/rubocop/cop/rspec/named_subject.rb +5 -2
  37. data/lib/rubocop/cop/rspec/nested_groups.rb +2 -1
  38. data/lib/rubocop/cop/rspec/pending_without_reason.rb +0 -5
  39. data/lib/rubocop/cop/rspec/predicate_matcher.rb +25 -11
  40. data/lib/rubocop/cop/rspec/remove_const.rb +0 -1
  41. data/lib/rubocop/cop/rspec/repeated_subject_call.rb +1 -0
  42. data/lib/rubocop/cop/rspec/return_from_stub.rb +5 -4
  43. data/lib/rubocop/cop/rspec/scattered_setup.rb +7 -1
  44. data/lib/rubocop/cop/rspec/single_argument_message_chain.rb +3 -4
  45. data/lib/rubocop/cop/rspec/sort_metadata.rb +22 -8
  46. data/lib/rubocop/cop/rspec/stubbed_mock.rb +15 -10
  47. data/lib/rubocop/cop/rspec/subject_stub.rb +2 -2
  48. data/lib/rubocop/cop/rspec/unspecified_exception.rb +21 -14
  49. data/lib/rubocop/cop/rspec/verified_double_reference.rb +14 -53
  50. data/lib/rubocop/cop/rspec/void_expect.rb +6 -1
  51. data/lib/rubocop/cop/rspec_cops.rb +2 -25
  52. data/lib/rubocop/rspec/concept.rb +0 -1
  53. data/lib/rubocop/rspec/config_formatter.rb +4 -32
  54. data/lib/rubocop/rspec/cop/generator.rb +25 -0
  55. data/lib/rubocop/rspec/description_extractor.rb +2 -2
  56. data/lib/rubocop/rspec/hook.rb +1 -1
  57. data/lib/rubocop/rspec/language.rb +0 -1
  58. data/lib/rubocop/rspec/node.rb +1 -1
  59. data/lib/rubocop/rspec/plugin.rb +37 -0
  60. data/lib/rubocop/rspec/shared_contexts/default_rspec_language_config_context.rb +1 -1
  61. data/lib/rubocop/rspec/version.rb +1 -1
  62. data/lib/rubocop/rspec/wording.rb +2 -4
  63. data/lib/rubocop/rspec.rb +0 -7
  64. data/lib/rubocop-rspec.rb +2 -20
  65. metadata +18 -62
  66. data/lib/rubocop/cop/rspec/capybara/current_path_expectation.rb +0 -39
  67. data/lib/rubocop/cop/rspec/capybara/feature_methods.rb +0 -104
  68. data/lib/rubocop/cop/rspec/capybara/match_style.rb +0 -38
  69. data/lib/rubocop/cop/rspec/capybara/negation_matcher.rb +0 -33
  70. data/lib/rubocop/cop/rspec/capybara/specific_actions.rb +0 -29
  71. data/lib/rubocop/cop/rspec/capybara/specific_finders.rb +0 -24
  72. data/lib/rubocop/cop/rspec/capybara/specific_matcher.rb +0 -35
  73. data/lib/rubocop/cop/rspec/capybara/visibility_matcher.rb +0 -36
  74. data/lib/rubocop/cop/rspec/factory_bot/attribute_defined_statically.rb +0 -35
  75. data/lib/rubocop/cop/rspec/factory_bot/consistent_parentheses_style.rb +0 -50
  76. data/lib/rubocop/cop/rspec/factory_bot/create_list.rb +0 -40
  77. data/lib/rubocop/cop/rspec/factory_bot/factory_class_name.rb +0 -29
  78. data/lib/rubocop/cop/rspec/factory_bot/factory_name_style.rb +0 -33
  79. data/lib/rubocop/cop/rspec/factory_bot/syntax_methods.rb +0 -55
  80. data/lib/rubocop/cop/rspec/file_path.rb +0 -179
  81. data/lib/rubocop/cop/rspec/rails/avoid_setup_hook.rb +0 -27
  82. data/lib/rubocop/cop/rspec/rails/have_http_status.rb +0 -35
  83. data/lib/rubocop/cop/rspec/rails/http_status.rb +0 -61
  84. data/lib/rubocop/cop/rspec/rails/inferred_spec_type.rb +0 -62
  85. data/lib/rubocop/cop/rspec/rails/minitest_assertions.rb +0 -39
  86. data/lib/rubocop/cop/rspec/rails/negation_be_valid.rb +0 -39
  87. data/lib/rubocop/cop/rspec/rails/travel_around.rb +0 -34
  88. data/lib/rubocop/rspec/inject.rb +0 -18
  89. data/lib/rubocop/rspec/language/node_pattern.rb +0 -48
@@ -1,35 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module RuboCop
4
- module Cop
5
- module RSpec
6
- module Capybara
7
- # @!parse
8
- # # Checks for there is a more specific matcher offered by Capybara.
9
- # #
10
- # # @example
11
- # #
12
- # # # bad
13
- # # expect(page).to have_selector('button')
14
- # # expect(page).to have_no_selector('button.cls')
15
- # # expect(page).to have_css('button')
16
- # # expect(page).to have_no_css('a.cls', href: 'http://example.com')
17
- # # expect(page).to have_css('table.cls')
18
- # # expect(page).to have_css('select')
19
- # # expect(page).to have_css('input', exact_text: 'foo')
20
- # #
21
- # # # good
22
- # # expect(page).to have_button
23
- # # expect(page).to have_no_button(class: 'cls')
24
- # # expect(page).to have_button
25
- # # expect(page).to have_no_link('foo', class: 'cls', href: 'http://example.com')
26
- # # expect(page).to have_table(class: 'cls')
27
- # # expect(page).to have_select
28
- # # expect(page).to have_field('foo')
29
- # #
30
- # class SpecificMatcher < ::RuboCop::Cop::Base; end
31
- SpecificMatcher = ::RuboCop::Cop::Capybara::SpecificMatcher
32
- end
33
- end
34
- end
35
- end
@@ -1,36 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module RuboCop
4
- module Cop
5
- module RSpec
6
- module Capybara
7
- # @!parse
8
- # # Checks for boolean visibility in Capybara finders.
9
- # #
10
- # # Capybara lets you find elements that match a certain visibility
11
- # # using the `:visible` option. `:visible` accepts both boolean and
12
- # # symbols as values, however using booleans can have unwanted
13
- # # effects. `visible: false` does not find just invisible elements,
14
- # # but both visible and invisible elements. For expressiveness and
15
- # # clarity, use one of the # symbol values, `:all`, `:hidden` or
16
- # # `:visible`.
17
- # # Read more in
18
- # # https://www.rubydoc.info/gems/capybara/Capybara%2FNode%2FFinders:all[the documentation].
19
- # #
20
- # # @example
21
- # # # bad
22
- # # expect(page).to have_selector('.foo', visible: false)
23
- # # expect(page).to have_css('.foo', visible: true)
24
- # # expect(page).to have_link('my link', visible: false)
25
- # #
26
- # # # good
27
- # # expect(page).to have_selector('.foo', visible: :visible)
28
- # # expect(page).to have_css('.foo', visible: :all)
29
- # # expect(page).to have_link('my link', visible: :hidden)
30
- # #
31
- # class VisibilityMatcher < ::RuboCop::Cop::Base; end
32
- VisibilityMatcher = ::RuboCop::Cop::Capybara::VisibilityMatcher
33
- end
34
- end
35
- end
36
- end
@@ -1,35 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module RuboCop
4
- module Cop
5
- module RSpec
6
- module FactoryBot
7
- # @!parse
8
- # # Always declare attribute values as blocks.
9
- # #
10
- # # @example
11
- # # # bad
12
- # # kind [:active, :rejected].sample
13
- # #
14
- # # # good
15
- # # kind { [:active, :rejected].sample }
16
- # #
17
- # # # bad
18
- # # closed_at 1.day.from_now
19
- # #
20
- # # # good
21
- # # closed_at { 1.day.from_now }
22
- # #
23
- # # # bad
24
- # # count 1
25
- # #
26
- # # # good
27
- # # count { 1 }
28
- # #
29
- # class AttributeDefinedStatically < ::RuboCop::Cop::Base; end
30
- AttributeDefinedStatically =
31
- ::RuboCop::Cop::FactoryBot::AttributeDefinedStatically
32
- end
33
- end
34
- end
35
- end
@@ -1,50 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module RuboCop
4
- module Cop
5
- module RSpec
6
- module FactoryBot
7
- # @!parse
8
- # # Use a consistent style for parentheses in factory bot calls.
9
- # #
10
- # # @example
11
- # #
12
- # # # bad
13
- # # create :user
14
- # # build(:user)
15
- # # create(:login)
16
- # # create :login
17
- # #
18
- # # @example `EnforcedStyle: require_parentheses` (default)
19
- # #
20
- # # # good
21
- # # create(:user)
22
- # # create(:user)
23
- # # create(:login)
24
- # # build(:login)
25
- # #
26
- # # @example `EnforcedStyle: omit_parentheses`
27
- # #
28
- # # # good
29
- # # create :user
30
- # # build :user
31
- # # create :login
32
- # # create :login
33
- # #
34
- # # # also good
35
- # # # when method name and first argument are not on same line
36
- # # create(
37
- # # :user
38
- # # )
39
- # # build(
40
- # # :user,
41
- # # name: 'foo'
42
- # # )
43
- # #
44
- # class ConsistentParenthesesStyle < ::RuboCop::Cop::Base; end
45
- ConsistentParenthesesStyle =
46
- ::RuboCop::Cop::FactoryBot::ConsistentParenthesesStyle
47
- end
48
- end
49
- end
50
- end
@@ -1,40 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module RuboCop
4
- module Cop
5
- module RSpec
6
- module FactoryBot
7
- # @!parse
8
- # # Checks for create_list usage.
9
- # #
10
- # # This cop can be configured using the `EnforcedStyle` option
11
- # #
12
- # # @example `EnforcedStyle: create_list` (default)
13
- # # # bad
14
- # # 3.times { create :user }
15
- # #
16
- # # # good
17
- # # create_list :user, 3
18
- # #
19
- # # # bad
20
- # # 3.times { create :user, age: 18 }
21
- # #
22
- # # # good - index is used to alter the created models attributes
23
- # # 3.times { |n| create :user, age: n }
24
- # #
25
- # # # good - contains a method call, may return different values
26
- # # 3.times { create :user, age: rand }
27
- # #
28
- # # @example `EnforcedStyle: n_times`
29
- # # # bad
30
- # # create_list :user, 3
31
- # #
32
- # # # good
33
- # # 3.times { create :user }
34
- # #
35
- # class CreateList < ::RuboCop::Cop::Base; end
36
- CreateList = ::RuboCop::Cop::FactoryBot::CreateList
37
- end
38
- end
39
- end
40
- end
@@ -1,29 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module RuboCop
4
- module Cop
5
- module RSpec
6
- module FactoryBot
7
- # @!parse
8
- # # Use string value when setting the class attribute explicitly.
9
- # #
10
- # # This cop would promote faster tests by lazy-loading of
11
- # # application files. Also, this could help you suppress potential
12
- # # bugs in combination with external libraries by avoiding a preload
13
- # # of application files from the factory files.
14
- # #
15
- # # @example
16
- # # # bad
17
- # # factory :foo, class: Foo do
18
- # # end
19
- # #
20
- # # # good
21
- # # factory :foo, class: 'Foo' do
22
- # # end
23
- # #
24
- # class FactoryClassName < ::RuboCop::Cop::Base; end
25
- FactoryClassName = ::RuboCop::Cop::FactoryBot::FactoryClassName
26
- end
27
- end
28
- end
29
- end
@@ -1,33 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module RuboCop
4
- module Cop
5
- module RSpec
6
- module FactoryBot
7
- # @!parse
8
- # # Checks for name style for argument of FactoryBot::Syntax::Methods.
9
- # #
10
- # # @example EnforcedStyle: symbol (default)
11
- # # # bad
12
- # # create('user')
13
- # # build "user", username: "NAME"
14
- # #
15
- # # # good
16
- # # create(:user)
17
- # # build :user, username: "NAME"
18
- # #
19
- # # @example EnforcedStyle: string
20
- # # # bad
21
- # # create(:user)
22
- # # build :user, username: "NAME"
23
- # #
24
- # # # good
25
- # # create('user')
26
- # # build "user", username: "NAME"
27
- # #
28
- # class FactoryNameStyle < ::RuboCop::Cop::Base; end
29
- FactoryNameStyle = ::RuboCop::Cop::FactoryBot::FactoryNameStyle
30
- end
31
- end
32
- end
33
- end
@@ -1,55 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module RuboCop
4
- module Cop
5
- module RSpec
6
- module FactoryBot
7
- # @!parse
8
- # # Use shorthands from `FactoryBot::Syntax::Methods` in your specs.
9
- # #
10
- # # @safety
11
- # # The autocorrection is marked as unsafe because the cop
12
- # # cannot verify whether you already include
13
- # # `FactoryBot::Syntax::Methods` in your test suite.
14
- # #
15
- # # If you're using Rails, add the following configuration to
16
- # # `spec/support/factory_bot.rb` and be sure to require that file
17
- # # in `rails_helper.rb`:
18
- # #
19
- # # [source,ruby]
20
- # # ----
21
- # # RSpec.configure do |config|
22
- # # config.include FactoryBot::Syntax::Methods
23
- # # end
24
- # # ----
25
- # #
26
- # # If you're not using Rails:
27
- # #
28
- # # [source,ruby]
29
- # # ----
30
- # # RSpec.configure do |config|
31
- # # config.include FactoryBot::Syntax::Methods
32
- # #
33
- # # config.before(:suite) do
34
- # # FactoryBot.find_definitions
35
- # # end
36
- # # end
37
- # # ----
38
- # #
39
- # # @example
40
- # # # bad
41
- # # FactoryBot.create(:bar)
42
- # # FactoryBot.build(:bar)
43
- # # FactoryBot.attributes_for(:bar)
44
- # #
45
- # # # good
46
- # # create(:bar)
47
- # # build(:bar)
48
- # # attributes_for(:bar)
49
- # #
50
- # class SyntaxMethods < ::RuboCop::Cop::Base; end
51
- SyntaxMethods = ::RuboCop::Cop::FactoryBot::SyntaxMethods
52
- end
53
- end
54
- end
55
- end
@@ -1,179 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module RuboCop
4
- module Cop
5
- module RSpec
6
- # Checks that spec file paths are consistent and well-formed.
7
- #
8
- # This cop is deprecated.
9
- # We plan to remove it in the next major version update to 3.0.
10
- # The migration targets are `RSpec/SpecFilePathSuffix`
11
- # and `RSpec/SpecFilePathFormat`.
12
- # If you are using this cop, please plan for migration.
13
- #
14
- # By default, this checks that spec file paths are consistent with the
15
- # test subject and enforces that it reflects the described
16
- # class/module and its optionally called out method.
17
- #
18
- # With the configuration option `IgnoreMethods` the called out method will
19
- # be ignored when determining the enforced path.
20
- #
21
- # With the configuration option `CustomTransform` modules or classes can
22
- # be specified that should not as usual be transformed from CamelCase to
23
- # snake_case (e.g. 'RuboCop' => 'rubocop' ).
24
- #
25
- # With the configuration option `SpecSuffixOnly` test files will only
26
- # be checked to ensure they end in '_spec.rb'. This option disables
27
- # checking for consistency in the test subject or test methods.
28
- #
29
- # @example
30
- # # bad
31
- # whatever_spec.rb # describe MyClass
32
- #
33
- # # bad
34
- # my_class_spec.rb # describe MyClass, '#method'
35
- #
36
- # # good
37
- # my_class_spec.rb # describe MyClass
38
- #
39
- # # good
40
- # my_class_method_spec.rb # describe MyClass, '#method'
41
- #
42
- # # good
43
- # my_class/method_spec.rb # describe MyClass, '#method'
44
- #
45
- # @example when configuration is `IgnoreMethods: true`
46
- # # bad
47
- # whatever_spec.rb # describe MyClass
48
- #
49
- # # good
50
- # my_class_spec.rb # describe MyClass
51
- #
52
- # # good
53
- # my_class_spec.rb # describe MyClass, '#method'
54
- #
55
- # @example when configuration is `SpecSuffixOnly: true`
56
- # # good
57
- # whatever_spec.rb # describe MyClass
58
- #
59
- # # good
60
- # my_class_spec.rb # describe MyClass
61
- #
62
- # # good
63
- # my_class_spec.rb # describe MyClass, '#method'
64
- #
65
- class FilePath < Base
66
- include TopLevelGroup
67
- include Namespace
68
-
69
- MSG = 'Spec path should end with `%<suffix>s`.'
70
-
71
- # @!method example_group(node)
72
- def_node_matcher :example_group, <<~PATTERN
73
- (block
74
- $(send #rspec? _example_group $_ $...) ...
75
- )
76
- PATTERN
77
-
78
- # @!method routing_metadata?(node)
79
- def_node_search :routing_metadata?, '(pair (sym :type) (sym :routing))'
80
-
81
- def on_top_level_example_group(node)
82
- return unless top_level_groups.one?
83
-
84
- example_group(node) do |send_node, example_group, arguments|
85
- ensure_correct_file_path(send_node, example_group, arguments)
86
- end
87
- end
88
-
89
- private
90
-
91
- def ensure_correct_file_path(send_node, example_group, arguments)
92
- pattern = pattern_for(example_group, arguments)
93
- return if filename_ends_with?(pattern)
94
-
95
- # For the suffix shown in the offense message, modify the regular
96
- # expression pattern to resemble a glob pattern for clearer error
97
- # messages.
98
- offense_suffix = pattern.gsub('.*', '*').sub('[^/]', '')
99
- .sub('\.', '.')
100
- add_offense(send_node, message: format(MSG, suffix: offense_suffix))
101
- end
102
-
103
- def routing_spec?(args)
104
- args.any?(&method(:routing_metadata?)) || routing_spec_path?
105
- end
106
-
107
- def pattern_for(example_group, arguments)
108
- method_name = arguments.first
109
- if spec_suffix_only? || !example_group.const_type? ||
110
- routing_spec?(arguments)
111
- return pattern_for_spec_suffix_only
112
- end
113
-
114
- [
115
- expected_path(example_group),
116
- name_pattern(method_name),
117
- '[^/]*_spec\.rb'
118
- ].join
119
- end
120
-
121
- def pattern_for_spec_suffix_only
122
- '.*_spec\.rb'
123
- end
124
-
125
- def name_pattern(method_name)
126
- return unless method_name&.str_type?
127
- return if ignore_methods?
128
-
129
- ".*#{method_name.str_content.gsub(/\s/, '_').gsub(/\W/, '')}"
130
- end
131
-
132
- def expected_path(constant)
133
- constants = namespace(constant) + constant.const_name.split('::')
134
-
135
- File.join(
136
- constants.map do |name|
137
- custom_transform.fetch(name) { camel_to_snake_case(name) }
138
- end
139
- )
140
- end
141
-
142
- def camel_to_snake_case(string)
143
- string
144
- .gsub(/([^A-Z])([A-Z]+)/, '\1_\2')
145
- .gsub(/([A-Z])([A-Z][^A-Z\d]+)/, '\1_\2')
146
- .downcase
147
- end
148
-
149
- def custom_transform
150
- cop_config.fetch('CustomTransform', {})
151
- end
152
-
153
- def ignore_methods?
154
- cop_config['IgnoreMethods']
155
- end
156
-
157
- def filename_ends_with?(pattern)
158
- expanded_file_path.match?("#{pattern}$")
159
- end
160
-
161
- def relevant_rubocop_rspec_file?(_file)
162
- true
163
- end
164
-
165
- def spec_suffix_only?
166
- cop_config['SpecSuffixOnly']
167
- end
168
-
169
- def routing_spec_path?
170
- expanded_file_path.include?('spec/routing/')
171
- end
172
-
173
- def expanded_file_path
174
- File.expand_path(processed_source.file_path)
175
- end
176
- end
177
- end
178
- end
179
- end
@@ -1,27 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module RuboCop
4
- module Cop
5
- module RSpec
6
- module Rails
7
- # @!parse
8
- # # Checks that tests use RSpec `before` hook over Rails `setup`
9
- # # method.
10
- # #
11
- # # @example
12
- # # # bad
13
- # # setup do
14
- # # allow(foo).to receive(:bar)
15
- # # end
16
- # #
17
- # # # good
18
- # # before do
19
- # # allow(foo).to receive(:bar)
20
- # # end
21
- # #
22
- # class AvoidSetupHook < RuboCop::Cop::RSpec::Base; end
23
- AvoidSetupHook = ::RuboCop::Cop::RSpecRails::AvoidSetupHook
24
- end
25
- end
26
- end
27
- end
@@ -1,35 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module RuboCop
4
- module Cop
5
- module RSpec
6
- module Rails
7
- # @!parse
8
- # # Checks that tests use `have_http_status` instead of equality matchers.
9
- # #
10
- # # @example ResponseMethods: ['response', 'last_response'] (default)
11
- # # # bad
12
- # # expect(response.status).to be(200)
13
- # # expect(last_response.code).to eq("200")
14
- # #
15
- # # # good
16
- # # expect(response).to have_http_status(200)
17
- # # expect(last_response).to have_http_status(200)
18
- # #
19
- # # @example ResponseMethods: ['foo_response']
20
- # # # bad
21
- # # expect(foo_response.status).to be(200)
22
- # #
23
- # # # good
24
- # # expect(foo_response).to have_http_status(200)
25
- # #
26
- # # # also good
27
- # # expect(response).to have_http_status(200)
28
- # # expect(last_response).to have_http_status(200)
29
- # #
30
- # class HaveHttpStatus < ::RuboCop::Cop::Base; end
31
- HaveHttpStatus = ::RuboCop::Cop::RSpecRails::HaveHttpStatus
32
- end
33
- end
34
- end
35
- end
@@ -1,61 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module RuboCop
4
- module Cop
5
- module RSpec
6
- module Rails
7
- # @!parse
8
- # # Enforces use of symbolic or numeric value to describe HTTP status.
9
- # #
10
- # # This cop inspects only `have_http_status` calls.
11
- # # So, this cop does not check if a method starting with `be_*` is
12
- # # used when setting for `EnforcedStyle: symbolic` or
13
- # # `EnforcedStyle: numeric`.
14
- # #
15
- # # @example `EnforcedStyle: symbolic` (default)
16
- # # # bad
17
- # # it { is_expected.to have_http_status 200 }
18
- # # it { is_expected.to have_http_status 404 }
19
- # # it { is_expected.to have_http_status "403" }
20
- # #
21
- # # # good
22
- # # it { is_expected.to have_http_status :ok }
23
- # # it { is_expected.to have_http_status :not_found }
24
- # # it { is_expected.to have_http_status :forbidden }
25
- # # it { is_expected.to have_http_status :success }
26
- # # it { is_expected.to have_http_status :error }
27
- # #
28
- # # @example `EnforcedStyle: numeric`
29
- # # # bad
30
- # # it { is_expected.to have_http_status :ok }
31
- # # it { is_expected.to have_http_status :not_found }
32
- # # it { is_expected.to have_http_status "forbidden" }
33
- # #
34
- # # # good
35
- # # it { is_expected.to have_http_status 200 }
36
- # # it { is_expected.to have_http_status 404 }
37
- # # it { is_expected.to have_http_status 403 }
38
- # # it { is_expected.to have_http_status :success }
39
- # # it { is_expected.to have_http_status :error }
40
- # #
41
- # # @example `EnforcedStyle: be_status`
42
- # # # bad
43
- # # it { is_expected.to have_http_status :ok }
44
- # # it { is_expected.to have_http_status :not_found }
45
- # # it { is_expected.to have_http_status "forbidden" }
46
- # # it { is_expected.to have_http_status 200 }
47
- # # it { is_expected.to have_http_status 404 }
48
- # # it { is_expected.to have_http_status "403" }
49
- # #
50
- # # # good
51
- # # it { is_expected.to be_ok }
52
- # # it { is_expected.to be_not_found }
53
- # # it { is_expected.to have_http_status :success }
54
- # # it { is_expected.to have_http_status :error }
55
- # #
56
- # class HttpStatus < RuboCop::Cop::RSpec::Base; end
57
- HttpStatus = ::RuboCop::Cop::RSpecRails::HttpStatus
58
- end
59
- end
60
- end
61
- end
@@ -1,62 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module RuboCop
4
- module Cop
5
- module RSpec
6
- module Rails
7
- # @!parse
8
- # # Identifies redundant spec type.
9
- # #
10
- # # After setting up rspec-rails, you will have enabled
11
- # # `config.infer_spec_type_from_file_location!` by default in
12
- # # spec/rails_helper.rb. This cop works in conjunction with
13
- # # this config.
14
- # # If you disable this config, disable this cop as well.
15
- # #
16
- # # @safety
17
- # # This cop is marked as unsafe because
18
- # # `config.infer_spec_type_from_file_location!` may not be enabled.
19
- # #
20
- # # @example
21
- # # # bad
22
- # # # spec/models/user_spec.rb
23
- # # RSpec.describe User, type: :model do
24
- # # end
25
- # #
26
- # # # good
27
- # # # spec/models/user_spec.rb
28
- # # RSpec.describe User do
29
- # # end
30
- # #
31
- # # # good
32
- # # # spec/models/user_spec.rb
33
- # # RSpec.describe User, type: :common do
34
- # # end
35
- # #
36
- # # @example `Inferences` configuration
37
- # # # .rubocop.yml
38
- # # # RSpec/Rails/InferredSpecType:
39
- # # # Inferences:
40
- # # # services: service
41
- # #
42
- # # # bad
43
- # # # spec/services/user_spec.rb
44
- # # RSpec.describe User, type: :service do
45
- # # end
46
- # #
47
- # # # good
48
- # # # spec/services/user_spec.rb
49
- # # RSpec.describe User do
50
- # # end
51
- # #
52
- # # # good
53
- # # # spec/services/user_spec.rb
54
- # # RSpec.describe User, type: :common do
55
- # # end
56
- # #
57
- # class InferredSpecType < RuboCop::Cop::RSpec::Base; end
58
- InferredSpecType = ::RuboCop::Cop::RSpecRails::InferredSpecType
59
- end
60
- end
61
- end
62
- end