rubocop-rspec 1.6.0 → 1.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (69) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +22 -0
  3. data/README.md +23 -0
  4. data/Rakefile +19 -1
  5. data/config/default.yml +78 -15
  6. data/lib/rubocop-rspec.rb +19 -1
  7. data/lib/rubocop/cop/rspec/any_instance.rb +5 -1
  8. data/lib/rubocop/cop/rspec/be_eql.rb +58 -0
  9. data/lib/rubocop/cop/rspec/describe_class.rb +2 -3
  10. data/lib/rubocop/cop/rspec/describe_method.rb +4 -3
  11. data/lib/rubocop/cop/rspec/described_class.rb +4 -35
  12. data/lib/rubocop/cop/rspec/empty_example_group.rb +100 -0
  13. data/lib/rubocop/cop/rspec/example_length.rb +5 -2
  14. data/lib/rubocop/cop/rspec/example_wording.rb +5 -2
  15. data/lib/rubocop/cop/rspec/expect_actual.rb +79 -0
  16. data/lib/rubocop/cop/rspec/file_path.rb +3 -1
  17. data/lib/rubocop/cop/rspec/focus.rb +12 -28
  18. data/lib/rubocop/cop/rspec/hook_argument.rb +122 -0
  19. data/lib/rubocop/cop/rspec/instance_variable.rb +53 -12
  20. data/lib/rubocop/cop/rspec/leading_subject.rb +58 -0
  21. data/lib/rubocop/cop/rspec/let_setup.rb +58 -0
  22. data/lib/rubocop/cop/rspec/message_chain.rb +33 -0
  23. data/lib/rubocop/cop/rspec/message_expectation.rb +58 -0
  24. data/lib/rubocop/cop/rspec/multiple_describes.rb +10 -7
  25. data/lib/rubocop/cop/rspec/multiple_expectations.rb +89 -0
  26. data/lib/rubocop/cop/rspec/named_subject.rb +10 -1
  27. data/lib/rubocop/cop/rspec/nested_groups.rb +125 -0
  28. data/lib/rubocop/cop/rspec/not_to_not.rb +3 -3
  29. data/lib/rubocop/cop/rspec/subject_stub.rb +136 -0
  30. data/lib/rubocop/cop/rspec/verified_doubles.rb +4 -1
  31. data/lib/rubocop/rspec.rb +10 -0
  32. data/lib/rubocop/rspec/config_formatter.rb +33 -0
  33. data/lib/rubocop/rspec/description_extractor.rb +35 -0
  34. data/lib/rubocop/rspec/inject.rb +2 -6
  35. data/lib/rubocop/rspec/language.rb +73 -0
  36. data/lib/rubocop/rspec/language/node_pattern.rb +16 -0
  37. data/lib/rubocop/rspec/spec_only.rb +61 -0
  38. data/lib/rubocop/rspec/top_level_describe.rb +6 -0
  39. data/lib/rubocop/rspec/version.rb +1 -1
  40. data/rubocop-rspec.gemspec +1 -0
  41. data/spec/project/changelog_spec.rb +81 -0
  42. data/spec/project/default_config_spec.rb +52 -0
  43. data/spec/project/project_requires_spec.rb +8 -0
  44. data/spec/rubocop/cop/rspec/be_eql_spec.rb +59 -0
  45. data/spec/rubocop/cop/rspec/described_class_spec.rb +2 -2
  46. data/spec/rubocop/cop/rspec/empty_example_group_spec.rb +79 -0
  47. data/spec/rubocop/cop/rspec/example_length_spec.rb +50 -30
  48. data/spec/rubocop/cop/rspec/example_wording_spec.rb +21 -3
  49. data/spec/rubocop/cop/rspec/expect_actual_spec.rb +136 -0
  50. data/spec/rubocop/cop/rspec/file_path_spec.rb +48 -71
  51. data/spec/rubocop/cop/rspec/focus_spec.rb +1 -1
  52. data/spec/rubocop/cop/rspec/hook_argument_spec.rb +189 -0
  53. data/spec/rubocop/cop/rspec/instance_variable_spec.rb +37 -0
  54. data/spec/rubocop/cop/rspec/leading_subject_spec.rb +54 -0
  55. data/spec/rubocop/cop/rspec/let_setup_spec.rb +66 -0
  56. data/spec/rubocop/cop/rspec/message_chain_spec.rb +21 -0
  57. data/spec/rubocop/cop/rspec/message_expectation_spec.rb +63 -0
  58. data/spec/rubocop/cop/rspec/multiple_expectations_spec.rb +84 -0
  59. data/spec/rubocop/cop/rspec/nested_groups_spec.rb +55 -0
  60. data/spec/rubocop/cop/rspec/not_to_not_spec.rb +12 -2
  61. data/spec/rubocop/cop/rspec/subject_stub_spec.rb +183 -0
  62. data/spec/rubocop/rspec/config_formatter_spec.rb +48 -0
  63. data/spec/rubocop/rspec/description_extractor_spec.rb +35 -0
  64. data/spec/rubocop/rspec/language/selector_set_spec.rb +29 -0
  65. data/spec/rubocop/rspec/spec_only_spec.rb +97 -0
  66. data/spec/shared/rspec_only_cop_behavior.rb +68 -0
  67. data/spec/spec_helper.rb +13 -1
  68. metadata +72 -5
  69. data/spec/project_spec.rb +0 -115
data/spec/project_spec.rb DELETED
@@ -1,115 +0,0 @@
1
- describe 'RuboCop Project' do # rubocop:disable RSpec/DescribeClass
2
- describe 'default configuration file' do
3
- let(:cop_names) do
4
- Dir.glob(File.join(File.dirname(__FILE__), '..', 'lib', 'rubocop', 'cop',
5
- 'rspec', '*.rb'))
6
- .map do |file|
7
- cop_name = File.basename(file, '.rb')
8
- .gsub(/(^|_)(.)/) { Regexp.last_match(2).upcase }
9
-
10
- "RSpec/#{cop_name}"
11
- end
12
- end
13
-
14
- subject(:default_config) do
15
- RuboCop::ConfigLoader.load_file('config/default.yml')
16
- end
17
-
18
- it 'has configuration for all cops' do
19
- expect(default_config.keys.sort).to eq(cop_names.sort)
20
- end
21
-
22
- it 'has a nicely formatted description for all cops' do
23
- cop_names.each do |name|
24
- description = default_config[name]['Description']
25
- expect(description).not_to be_nil
26
- expect(description).not_to include("\n")
27
- end
28
- end
29
- end
30
-
31
- describe 'changelog' do
32
- subject(:changelog) do
33
- path = File.join(File.dirname(__FILE__), '..', 'CHANGELOG.md')
34
- File.read(path)
35
- end
36
-
37
- it 'has link definitions for all implicit links' do
38
- implicit_link_names = changelog.scan(/\[([^\]]+)\]\[\]/).flatten.uniq
39
- implicit_link_names.each do |name|
40
- expect(changelog).to include("[#{name}]: http")
41
- end
42
- end
43
-
44
- describe 'entry' do
45
- subject(:entries) { lines.grep(/^\*/).map(&:chomp) }
46
- let(:lines) { changelog.each_line }
47
-
48
- it 'has a whitespace between the * and the body' do
49
- entries.each do |entry|
50
- expect(entry).to match(/^\* \S/)
51
- end
52
- end
53
-
54
- it 'has a link to the contributors at the end' do
55
- entries.each do |entry|
56
- expect(entry).to match(/\(\[@\S+\]\[\](?:, \[@\S+\]\[\])*\)$/)
57
- end
58
- end
59
-
60
- describe 'link to related issue on github' do
61
- let(:issues) do
62
- entries.map do |entry|
63
- entry.match(/\[(?<number>[#\d]+)\]\((?<url>[^\)]+)\)/)
64
- end.compact
65
- end
66
-
67
- it 'has an issue number prefixed with #' do
68
- issues.each do |issue|
69
- expect(issue[:number]).to match(/^#\d+$/)
70
- end
71
- end
72
-
73
- it 'has a valid URL' do
74
- issues.each do |issue|
75
- number = issue[:number].gsub(/\D/, '')
76
- pattern = %r{^https://github\.com/.+/.+/(?:issues|pull)/#{number}$} # rubocop:disable LineLength
77
- expect(issue[:url]).to match(pattern)
78
- end
79
- end
80
-
81
- it 'has a colon and a whitespace at the end' do
82
- entries_including_issue_link = entries.select do |entry|
83
- entry.match(/^\*\s*\[/)
84
- end
85
-
86
- entries_including_issue_link.each do |entry|
87
- expect(entry).to include('): ')
88
- end
89
- end
90
- end
91
-
92
- describe 'body' do
93
- let(:bodies) do
94
- entries.map do |entry|
95
- entry
96
- .sub(/^\*\s*(?:\[.+?\):\s*)?/, '')
97
- .sub(/\s*\([^\)]+\)$/, '')
98
- end
99
- end
100
-
101
- it 'does not start with a lower case' do
102
- bodies.each do |body|
103
- expect(body).not_to match(/^[a-z]/)
104
- end
105
- end
106
-
107
- it 'ends with a punctuation' do
108
- bodies.each do |body|
109
- expect(body).to match(/[\.\!]$/)
110
- end
111
- end
112
- end
113
- end
114
- end
115
- end