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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +20 -1
- data/Gemfile +0 -1
- data/config/default.yml +105 -0
- data/lib/rubocop-rspec.rb +27 -0
- data/lib/rubocop/cop/rspec/align_left_let_brace.rb +51 -0
- data/lib/rubocop/cop/rspec/align_right_let_brace.rb +51 -0
- data/lib/rubocop/cop/rspec/any_instance.rb +1 -1
- data/lib/rubocop/cop/rspec/cop.rb +4 -2
- data/lib/rubocop/cop/rspec/expect_in_hook.rb +61 -0
- data/lib/rubocop/cop/rspec/factory_girl/dynamic_attribute_defined_statically.rb +84 -0
- data/lib/rubocop/cop/rspec/hook_argument.rb +11 -5
- data/lib/rubocop/cop/rspec/invalid_predicate_matcher.rb +42 -0
- data/lib/rubocop/cop/rspec/let_before_examples.rb +66 -0
- data/lib/rubocop/cop/rspec/multiple_expectations.rb +3 -5
- data/lib/rubocop/cop/rspec/multiple_subjects.rb +80 -0
- data/lib/rubocop/cop/rspec/named_subject.rb +5 -6
- data/lib/rubocop/cop/rspec/overwriting_setup.rb +1 -1
- data/lib/rubocop/cop/rspec/predicate_matcher.rb +337 -0
- data/lib/rubocop/cop/rspec/return_from_stub.rb +83 -0
- data/lib/rubocop/cop/rspec/void_expect.rb +52 -0
- data/lib/rubocop/rspec/align_let_brace.rb +64 -0
- data/lib/rubocop/rspec/config_formatter.rb +7 -4
- data/lib/rubocop/rspec/description_extractor.rb +2 -2
- data/lib/rubocop/rspec/example_group.rb +25 -2
- data/lib/rubocop/rspec/factory_girl.rb +7 -0
- data/lib/rubocop/rspec/language.rb +6 -1
- data/lib/rubocop/rspec/version.rb +1 -1
- data/rubocop-rspec.gemspec +1 -4
- data/spec/project/default_config_spec.rb +8 -4
- data/spec/rubocop/cop/rspec/align_left_let_brace_spec.rb +62 -0
- data/spec/rubocop/cop/rspec/align_right_let_brace_spec.rb +62 -0
- data/spec/rubocop/cop/rspec/any_instance_spec.rb +3 -3
- data/spec/rubocop/cop/rspec/around_block_spec.rb +11 -11
- data/spec/rubocop/cop/rspec/be_eql_spec.rb +7 -7
- data/spec/rubocop/cop/rspec/before_after_all_spec.rb +4 -4
- data/spec/rubocop/cop/rspec/cop_spec.rb +7 -7
- data/spec/rubocop/cop/rspec/describe_class_spec.rb +18 -18
- data/spec/rubocop/cop/rspec/describe_method_spec.rb +4 -4
- data/spec/rubocop/cop/rspec/describe_symbol_spec.rb +6 -6
- data/spec/rubocop/cop/rspec/described_class_spec.rb +18 -18
- data/spec/rubocop/cop/rspec/empty_example_group_spec.rb +5 -5
- data/spec/rubocop/cop/rspec/empty_line_after_final_let_spec.rb +9 -9
- data/spec/rubocop/cop/rspec/empty_line_after_subject_spec.rb +5 -5
- data/spec/rubocop/cop/rspec/example_length_spec.rb +6 -6
- data/spec/rubocop/cop/rspec/example_wording_spec.rb +10 -10
- data/spec/rubocop/cop/rspec/expect_actual_spec.rb +10 -10
- data/spec/rubocop/cop/rspec/expect_in_hook_spec.rb +79 -0
- data/spec/rubocop/cop/rspec/expect_output_spec.rb +7 -7
- data/spec/rubocop/cop/rspec/factory_girl/dynamic_attribute_defined_statically_spec.rb +87 -0
- data/spec/rubocop/cop/rspec/file_path_spec.rb +29 -29
- data/spec/rubocop/cop/rspec/focus_spec.rb +6 -6
- data/spec/rubocop/cop/rspec/hook_argument_spec.rb +35 -23
- data/spec/rubocop/cop/rspec/implicit_expect_spec.rb +10 -10
- data/spec/rubocop/cop/rspec/instance_spy_spec.rb +4 -4
- data/spec/rubocop/cop/rspec/instance_variable_spec.rb +7 -7
- data/spec/rubocop/cop/rspec/invalid_predicate_matcher_spec.rb +37 -0
- data/spec/rubocop/cop/rspec/it_behaves_like_spec.rb +4 -4
- data/spec/rubocop/cop/rspec/iterated_expectation_spec.rb +8 -8
- data/spec/rubocop/cop/rspec/leading_subject_spec.rb +5 -5
- data/spec/rubocop/cop/rspec/let_before_examples_spec.rb +83 -0
- data/spec/rubocop/cop/rspec/let_setup_spec.rb +4 -4
- data/spec/rubocop/cop/rspec/message_chain_spec.rb +2 -2
- data/spec/rubocop/cop/rspec/message_expectation_spec.rb +4 -4
- data/spec/rubocop/cop/rspec/message_spies_spec.rb +18 -18
- data/spec/rubocop/cop/rspec/multiple_describes_spec.rb +3 -3
- data/spec/rubocop/cop/rspec/multiple_expectations_spec.rb +45 -9
- data/spec/rubocop/cop/rspec/multiple_subjects_spec.rb +96 -0
- data/spec/rubocop/cop/rspec/named_subject_spec.rb +4 -4
- data/spec/rubocop/cop/rspec/nested_groups_spec.rb +3 -3
- data/spec/rubocop/cop/rspec/not_to_not_spec.rb +4 -4
- data/spec/rubocop/cop/rspec/overwriting_setup_spec.rb +4 -4
- data/spec/rubocop/cop/rspec/predicate_matcher_spec.rb +335 -0
- data/spec/rubocop/cop/rspec/repeated_description_spec.rb +5 -5
- data/spec/rubocop/cop/rspec/repeated_example_spec.rb +5 -5
- data/spec/rubocop/cop/rspec/return_from_stub_spec.rb +85 -0
- data/spec/rubocop/cop/rspec/scattered_let_spec.rb +2 -2
- data/spec/rubocop/cop/rspec/scattered_setup_spec.rb +8 -8
- data/spec/rubocop/cop/rspec/shared_context_spec.rb +10 -10
- data/spec/rubocop/cop/rspec/single_argument_message_chain_spec.rb +10 -10
- data/spec/rubocop/cop/rspec/subject_stub_spec.rb +9 -9
- data/spec/rubocop/cop/rspec/verified_doubles_spec.rb +7 -7
- data/spec/rubocop/cop/rspec/void_expect_spec.rb +47 -0
- data/spec/rubocop/rspec/config_formatter_spec.rb +2 -0
- data/spec/spec_helper.rb +1 -1
- data/spec/support/expect_offense.rb +17 -0
- metadata +39 -51
- data/spec/expect_violation/expectation_spec.rb +0 -85
- 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
|