rubocop-rspec 1.15.1 → 1.16.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (89) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +20 -1
  3. data/Gemfile +0 -1
  4. data/config/default.yml +105 -0
  5. data/lib/rubocop-rspec.rb +27 -0
  6. data/lib/rubocop/cop/rspec/align_left_let_brace.rb +51 -0
  7. data/lib/rubocop/cop/rspec/align_right_let_brace.rb +51 -0
  8. data/lib/rubocop/cop/rspec/any_instance.rb +1 -1
  9. data/lib/rubocop/cop/rspec/cop.rb +4 -2
  10. data/lib/rubocop/cop/rspec/expect_in_hook.rb +61 -0
  11. data/lib/rubocop/cop/rspec/factory_girl/dynamic_attribute_defined_statically.rb +84 -0
  12. data/lib/rubocop/cop/rspec/hook_argument.rb +11 -5
  13. data/lib/rubocop/cop/rspec/invalid_predicate_matcher.rb +42 -0
  14. data/lib/rubocop/cop/rspec/let_before_examples.rb +66 -0
  15. data/lib/rubocop/cop/rspec/multiple_expectations.rb +3 -5
  16. data/lib/rubocop/cop/rspec/multiple_subjects.rb +80 -0
  17. data/lib/rubocop/cop/rspec/named_subject.rb +5 -6
  18. data/lib/rubocop/cop/rspec/overwriting_setup.rb +1 -1
  19. data/lib/rubocop/cop/rspec/predicate_matcher.rb +337 -0
  20. data/lib/rubocop/cop/rspec/return_from_stub.rb +83 -0
  21. data/lib/rubocop/cop/rspec/void_expect.rb +52 -0
  22. data/lib/rubocop/rspec/align_let_brace.rb +64 -0
  23. data/lib/rubocop/rspec/config_formatter.rb +7 -4
  24. data/lib/rubocop/rspec/description_extractor.rb +2 -2
  25. data/lib/rubocop/rspec/example_group.rb +25 -2
  26. data/lib/rubocop/rspec/factory_girl.rb +7 -0
  27. data/lib/rubocop/rspec/language.rb +6 -1
  28. data/lib/rubocop/rspec/version.rb +1 -1
  29. data/rubocop-rspec.gemspec +1 -4
  30. data/spec/project/default_config_spec.rb +8 -4
  31. data/spec/rubocop/cop/rspec/align_left_let_brace_spec.rb +62 -0
  32. data/spec/rubocop/cop/rspec/align_right_let_brace_spec.rb +62 -0
  33. data/spec/rubocop/cop/rspec/any_instance_spec.rb +3 -3
  34. data/spec/rubocop/cop/rspec/around_block_spec.rb +11 -11
  35. data/spec/rubocop/cop/rspec/be_eql_spec.rb +7 -7
  36. data/spec/rubocop/cop/rspec/before_after_all_spec.rb +4 -4
  37. data/spec/rubocop/cop/rspec/cop_spec.rb +7 -7
  38. data/spec/rubocop/cop/rspec/describe_class_spec.rb +18 -18
  39. data/spec/rubocop/cop/rspec/describe_method_spec.rb +4 -4
  40. data/spec/rubocop/cop/rspec/describe_symbol_spec.rb +6 -6
  41. data/spec/rubocop/cop/rspec/described_class_spec.rb +18 -18
  42. data/spec/rubocop/cop/rspec/empty_example_group_spec.rb +5 -5
  43. data/spec/rubocop/cop/rspec/empty_line_after_final_let_spec.rb +9 -9
  44. data/spec/rubocop/cop/rspec/empty_line_after_subject_spec.rb +5 -5
  45. data/spec/rubocop/cop/rspec/example_length_spec.rb +6 -6
  46. data/spec/rubocop/cop/rspec/example_wording_spec.rb +10 -10
  47. data/spec/rubocop/cop/rspec/expect_actual_spec.rb +10 -10
  48. data/spec/rubocop/cop/rspec/expect_in_hook_spec.rb +79 -0
  49. data/spec/rubocop/cop/rspec/expect_output_spec.rb +7 -7
  50. data/spec/rubocop/cop/rspec/factory_girl/dynamic_attribute_defined_statically_spec.rb +87 -0
  51. data/spec/rubocop/cop/rspec/file_path_spec.rb +29 -29
  52. data/spec/rubocop/cop/rspec/focus_spec.rb +6 -6
  53. data/spec/rubocop/cop/rspec/hook_argument_spec.rb +35 -23
  54. data/spec/rubocop/cop/rspec/implicit_expect_spec.rb +10 -10
  55. data/spec/rubocop/cop/rspec/instance_spy_spec.rb +4 -4
  56. data/spec/rubocop/cop/rspec/instance_variable_spec.rb +7 -7
  57. data/spec/rubocop/cop/rspec/invalid_predicate_matcher_spec.rb +37 -0
  58. data/spec/rubocop/cop/rspec/it_behaves_like_spec.rb +4 -4
  59. data/spec/rubocop/cop/rspec/iterated_expectation_spec.rb +8 -8
  60. data/spec/rubocop/cop/rspec/leading_subject_spec.rb +5 -5
  61. data/spec/rubocop/cop/rspec/let_before_examples_spec.rb +83 -0
  62. data/spec/rubocop/cop/rspec/let_setup_spec.rb +4 -4
  63. data/spec/rubocop/cop/rspec/message_chain_spec.rb +2 -2
  64. data/spec/rubocop/cop/rspec/message_expectation_spec.rb +4 -4
  65. data/spec/rubocop/cop/rspec/message_spies_spec.rb +18 -18
  66. data/spec/rubocop/cop/rspec/multiple_describes_spec.rb +3 -3
  67. data/spec/rubocop/cop/rspec/multiple_expectations_spec.rb +45 -9
  68. data/spec/rubocop/cop/rspec/multiple_subjects_spec.rb +96 -0
  69. data/spec/rubocop/cop/rspec/named_subject_spec.rb +4 -4
  70. data/spec/rubocop/cop/rspec/nested_groups_spec.rb +3 -3
  71. data/spec/rubocop/cop/rspec/not_to_not_spec.rb +4 -4
  72. data/spec/rubocop/cop/rspec/overwriting_setup_spec.rb +4 -4
  73. data/spec/rubocop/cop/rspec/predicate_matcher_spec.rb +335 -0
  74. data/spec/rubocop/cop/rspec/repeated_description_spec.rb +5 -5
  75. data/spec/rubocop/cop/rspec/repeated_example_spec.rb +5 -5
  76. data/spec/rubocop/cop/rspec/return_from_stub_spec.rb +85 -0
  77. data/spec/rubocop/cop/rspec/scattered_let_spec.rb +2 -2
  78. data/spec/rubocop/cop/rspec/scattered_setup_spec.rb +8 -8
  79. data/spec/rubocop/cop/rspec/shared_context_spec.rb +10 -10
  80. data/spec/rubocop/cop/rspec/single_argument_message_chain_spec.rb +10 -10
  81. data/spec/rubocop/cop/rspec/subject_stub_spec.rb +9 -9
  82. data/spec/rubocop/cop/rspec/verified_doubles_spec.rb +7 -7
  83. data/spec/rubocop/cop/rspec/void_expect_spec.rb +47 -0
  84. data/spec/rubocop/rspec/config_formatter_spec.rb +2 -0
  85. data/spec/spec_helper.rb +1 -1
  86. data/spec/support/expect_offense.rb +17 -0
  87. metadata +39 -51
  88. data/spec/expect_violation/expectation_spec.rb +0 -85
  89. data/spec/support/expect_violation.rb +0 -170
@@ -1,170 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'adamantium'
4
- require 'concord'
5
- require 'anima'
6
-
7
- module ExpectViolation
8
- DEFAULT_FILENAME = 'example_spec.rb'.freeze
9
-
10
- # rubocop:disable Metrics/AbcSize
11
- def expect_violation(source, filename: DEFAULT_FILENAME)
12
- expectation = Expectation.new(source)
13
- inspect_source(cop, expectation.source, filename)
14
- offenses = cop.offenses.map(&method(:to_assertion)).sort
15
-
16
- if expectation.assertions.empty?
17
- raise 'Use expect_no_violations to assert no violations'
18
- end
19
-
20
- expect(offenses).to eq(expectation.assertions.sort)
21
- end
22
-
23
- def expect_no_violations(source, filename: DEFAULT_FILENAME)
24
- inspect_source(cop, source, filename)
25
-
26
- expect(cop.offenses.empty?).to be(true)
27
- end
28
-
29
- private
30
-
31
- def to_assertion(offense)
32
- highlight = offense.highlighted_area
33
-
34
- Expectation::Assertion.new(
35
- message: offense.message,
36
- line_number: offense.location.first_line,
37
- column_range: highlight.begin_pos...highlight.end_pos
38
- )
39
- end
40
-
41
- class Expectation
42
- include Adamantium
43
- include Concord.new(:string)
44
-
45
- VIOLATION_LINE_PATTERN = /\A *\^/
46
-
47
- VIOLATION = :violation
48
- SOURCE = :line
49
-
50
- def source
51
- source_map.to_s
52
- end
53
-
54
- def assertions
55
- source_map.assertions
56
- end
57
-
58
- private
59
-
60
- def source_map
61
- tokens.reduce(Source::BLANK) do |source, (type, tokens)|
62
- tokens.reduce(source, :"add_#{type}")
63
- end
64
- end
65
- memoize :source_map
66
-
67
- def tokens
68
- string.each_line.chunk do |line|
69
- next SOURCE unless line =~ VIOLATION_LINE_PATTERN
70
-
71
- VIOLATION
72
- end
73
- end
74
-
75
- class Source
76
- include Concord.new(:lines)
77
-
78
- BLANK = new([].freeze)
79
-
80
- def add_line(line)
81
- self.class.new(lines + [Line.new(text: line, number: lines.size + 1)])
82
- end
83
-
84
- def add_violation(violation)
85
- self.class.new([*lines[0...-1], lines.last.add_violation(violation)])
86
- end
87
-
88
- def to_s
89
- lines.map(&:text).join
90
- end
91
-
92
- def assertions
93
- lines.flat_map(&:assertions)
94
- end
95
-
96
- class Line
97
- DEFAULTS = { violations: [] }.freeze
98
-
99
- include Anima.new(:text, :number, :violations)
100
-
101
- def initialize(options)
102
- super(DEFAULTS.merge(options))
103
- end
104
-
105
- def add_violation(violation)
106
- with(violations: violations + [violation])
107
- end
108
-
109
- def assertions
110
- violations.map do |violation|
111
- Assertion.parse(
112
- text: violation,
113
- line_number: number
114
- )
115
- end
116
- end
117
- end
118
- end
119
-
120
- class Assertion
121
- include Adamantium
122
- include Anima.new(:message, :column_range, :line_number)
123
- include Comparable
124
-
125
- def self.parse(text:, line_number:)
126
- parser = Parser.new(text)
127
-
128
- new(
129
- message: parser.message,
130
- column_range: parser.column_range,
131
- line_number: line_number
132
- )
133
- end
134
-
135
- def <=>(other)
136
- to_a <=> other.to_a
137
- end
138
-
139
- protected
140
-
141
- def to_a
142
- [line_number, column_range.first, column_range.last, message]
143
- end
144
-
145
- class Parser
146
- include Adamantium
147
- include Concord.new(:text)
148
-
149
- COLUMN_PATTERN = /^ *(?<carets>\^\^*) (?<message>.+)$/
150
-
151
- def column_range
152
- Range.new(*match.offset(:carets), true)
153
- end
154
-
155
- def message
156
- match[:message]
157
- end
158
-
159
- private
160
-
161
- def match
162
- text.match(COLUMN_PATTERN)
163
- end
164
- memoize :match
165
- end
166
-
167
- private_constant(*constants(false))
168
- end
169
- end
170
- end