rubocop-rspec 1.8.0 → 1.9.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 (62) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +8 -0
  3. data/Gemfile +2 -1
  4. data/Rakefile +3 -1
  5. data/config/default.yml +16 -0
  6. data/lib/rubocop-rspec.rb +6 -1
  7. data/lib/rubocop/cop/rspec/any_instance.rb +0 -2
  8. data/lib/rubocop/cop/rspec/be_eql.rb +1 -2
  9. data/lib/rubocop/cop/rspec/cop.rb +66 -0
  10. data/lib/rubocop/cop/rspec/describe_class.rb +6 -1
  11. data/lib/rubocop/cop/rspec/describe_method.rb +1 -2
  12. data/lib/rubocop/cop/rspec/described_class.rb +3 -6
  13. data/lib/rubocop/cop/rspec/empty_example_group.rb +1 -11
  14. data/lib/rubocop/cop/rspec/example_length.rb +1 -1
  15. data/lib/rubocop/cop/rspec/example_wording.rb +0 -2
  16. data/lib/rubocop/cop/rspec/expect_actual.rb +0 -2
  17. data/lib/rubocop/cop/rspec/file_path.rb +1 -1
  18. data/lib/rubocop/cop/rspec/focus.rb +4 -9
  19. data/lib/rubocop/cop/rspec/hook_argument.rb +3 -5
  20. data/lib/rubocop/cop/rspec/implicit_expect.rb +1 -1
  21. data/lib/rubocop/cop/rspec/instance_variable.rb +1 -5
  22. data/lib/rubocop/cop/rspec/leading_subject.rb +0 -2
  23. data/lib/rubocop/cop/rspec/let_setup.rb +1 -4
  24. data/lib/rubocop/cop/rspec/message_chain.rb +1 -8
  25. data/lib/rubocop/cop/rspec/message_expectation.rb +1 -1
  26. data/lib/rubocop/cop/rspec/message_spies.rb +79 -0
  27. data/lib/rubocop/cop/rspec/multiple_describes.rb +1 -2
  28. data/lib/rubocop/cop/rspec/multiple_expectations.rb +2 -6
  29. data/lib/rubocop/cop/rspec/named_subject.rb +0 -2
  30. data/lib/rubocop/cop/rspec/nested_groups.rb +2 -6
  31. data/lib/rubocop/cop/rspec/not_to_not.rb +1 -2
  32. data/lib/rubocop/cop/rspec/repeated_description.rb +59 -0
  33. data/lib/rubocop/cop/rspec/single_argument_message_chain.rb +48 -0
  34. data/lib/rubocop/cop/rspec/subject_stub.rb +1 -4
  35. data/lib/rubocop/cop/rspec/verified_doubles.rb +0 -2
  36. data/lib/rubocop/rspec.rb +1 -1
  37. data/lib/rubocop/rspec/description_extractor.rb +55 -18
  38. data/lib/rubocop/rspec/example.rb +56 -0
  39. data/lib/rubocop/rspec/example_group.rb +57 -0
  40. data/lib/rubocop/rspec/language.rb +28 -1
  41. data/lib/rubocop/rspec/language/node_pattern.rb +1 -3
  42. data/lib/rubocop/rspec/top_level_describe.rb +6 -10
  43. data/lib/rubocop/rspec/version.rb +1 -1
  44. data/spec/project/default_config_spec.rb +8 -5
  45. data/spec/project/project_requires_spec.rb +1 -1
  46. data/spec/rubocop/{rspec/spec_only_spec.rb → cop/rspec/cop_spec.rb} +2 -4
  47. data/spec/rubocop/cop/rspec/describe_class_spec.rb +36 -0
  48. data/spec/rubocop/cop/rspec/described_class_spec.rb +2 -2
  49. data/spec/rubocop/cop/rspec/example_length_spec.rb +48 -60
  50. data/spec/rubocop/cop/rspec/implicit_expect_spec.rb +1 -1
  51. data/spec/rubocop/cop/rspec/message_spies_spec.rb +93 -0
  52. data/spec/rubocop/cop/rspec/repeated_description_spec.rb +76 -0
  53. data/spec/rubocop/cop/rspec/single_argument_message_chain_spec.rb +75 -0
  54. data/spec/rubocop/rspec/description_extractor_spec.rb +46 -24
  55. data/spec/rubocop/rspec/example_group_spec.rb +44 -0
  56. data/spec/rubocop/rspec/example_spec.rb +62 -0
  57. data/spec/rubocop/rspec/language/selector_set_spec.rb +22 -2
  58. data/spec/spec_helper.rb +2 -9
  59. data/spec/support/expect_violation.rb +4 -2
  60. metadata +21 -8
  61. data/lib/rubocop/rspec/spec_only.rb +0 -61
  62. data/spec/shared/rspec_only_cop_behavior.rb +0 -68
@@ -1,61 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module RuboCop
4
- module RSpec
5
- # Mixin for cops that skips non-spec files
6
- #
7
- # The criteria for whether rubocop-rspec analyzes a certain ruby file
8
- # is configured via `AllCops/RSpec`. For example, if you want to
9
- # customize your project to scan all files within a `test/` directory
10
- # then you could add this to your configuration:
11
- #
12
- # @example configuring analyzed paths
13
- #
14
- # AllCops:
15
- # RSpec:
16
- # Patterns:
17
- # - '_spec.rb$'
18
- # - '(?:^|/)spec/'
19
- #
20
- # @note this functionality is implemented via this mixin instead of
21
- # a subclass of `RuboCop::Cop::Cop` because the `Cop` class assumes
22
- # that it will be the direct superclass of all cops. For example,
23
- # if the ancestry of a cop looked like this:
24
- #
25
- # class RuboCop::RSpec::Cop < RuboCop::Cop::Cop
26
- # end
27
- #
28
- # class RuboCop::RSpec::SpecCop < RuboCop::RSpec::Cop
29
- # end
30
- #
31
- # then `SpecCop` will fail to be registered on the class instance
32
- # variable of `Cop` which tracks all descendants via `.inherited`.
33
- #
34
- # While we could match this behavior and provide a rubocop-rspec Cop
35
- # parent class, it would rely heavily on the implementation details
36
- # of RuboCop itself which is largly private API. This would be
37
- # irresponsible since any patch level release of rubocop could break
38
- # integrations for users of rubocop-rspec
39
- #
40
- module SpecOnly
41
- DEFAULT_CONFIGURATION = CONFIG.fetch('AllCops').fetch('RSpec')
42
-
43
- def relevant_file?(file)
44
- rspec_pattern =~ file && super
45
- end
46
-
47
- private
48
-
49
- def rspec_pattern
50
- Regexp.union(rspec_pattern_config.map(&Regexp.public_method(:new)))
51
- end
52
-
53
- def rspec_pattern_config
54
- config
55
- .for_all_cops
56
- .fetch('RSpec', DEFAULT_CONFIGURATION)
57
- .fetch('Patterns')
58
- end
59
- end
60
- end
61
- end
@@ -1,68 +0,0 @@
1
- module SpecHelper
2
- # Provides a helper method for checking that `cop` works
3
- #
4
- # @note this is defined in a module so that the failure message can be
5
- # a constant without creating a bunch of warnings when the shared
6
- # context is included
7
- #
8
- module CheckCop
9
- CURRENT_FILE = Pathname.new(__FILE__).relative_path_from(ROOT).freeze
10
-
11
- FAILURE = <<-MSG.freeze
12
- Attempting to access `cop` produced the following error:
13
-
14
- %<exception>s
15
-
16
- The shared context under #{CURRENT_FILE} is included for all RSpec
17
- cops. This context expects you to define a subject named `cop` like so:
18
-
19
- describe RuboCop::Cop::RSpec::SomeCheck do
20
- subject(:cop) { described_class.new }
21
-
22
- ...
23
- end
24
-
25
- or if your cop is configurable you should have something like:
26
-
27
- describe RuboCop::Cop::RSpec::SomeConfigurableCheck, :config do
28
- subject(:cop) { described_class.new(config) }
29
-
30
- let(:cop_config) do
31
- { 'EnforcedStyle' => 'fancy', 'WhateverElse' => 'YouNeed' }
32
- end
33
-
34
- ...
35
- end
36
-
37
- This error likely means that you either don't define `cop` at the top
38
- level or you have dependent definitions (like `cop_config`) that are not
39
- defined at the top level.
40
- MSG
41
-
42
- # This method exists to reduce confusion for contributors. It is important
43
- # that these shared examples are automatically included for all cops but
44
- # it is easy for these to fail if you don't realize that your top level
45
- # describe needs to define a useable `cop` subject.
46
- def check_cop_definition
47
- cop
48
- rescue => exception
49
- raise format(FAILURE, exception: exception)
50
- end
51
- end
52
- end
53
-
54
- RSpec.shared_examples 'an rspec only cop', rspec_cop: true do
55
- include SpecHelper::CheckCop
56
-
57
- before do
58
- check_cop_definition
59
- end
60
-
61
- it 'does not deem lib/feature/thing.rb to be a relevant file' do
62
- expect(cop.relevant_file?('lib/feature/thing.rb')).to be_falsey
63
- end
64
-
65
- it 'deems spec/feature/thing_spec.rb to be a relevant file' do
66
- expect(cop.relevant_file?('spec/feature/thing_spec.rb')).to be(true)
67
- end
68
- end