rubocop-rspec 1.5.1 → 1.5.2
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +7 -0
- data/Gemfile +0 -2
- data/README.md +0 -8
- data/Rakefile +1 -3
- data/lib/rubocop-rspec.rb +2 -2
- data/lib/rubocop/cop/rspec/any_instance.rb +1 -10
- data/lib/rubocop/cop/rspec/describe_class.rb +23 -15
- data/lib/rubocop/cop/rspec/describe_method.rb +4 -6
- data/lib/rubocop/cop/rspec/described_class.rb +5 -8
- data/lib/rubocop/cop/rspec/example_length.rb +4 -9
- data/lib/rubocop/cop/rspec/example_wording.rb +13 -37
- data/lib/rubocop/cop/rspec/file_path.rb +10 -13
- data/lib/rubocop/cop/rspec/focus.rb +48 -30
- data/lib/rubocop/cop/rspec/instance_variable.rb +0 -1
- data/lib/rubocop/cop/rspec/multiple_describes.rb +2 -3
- data/lib/rubocop/cop/rspec/not_to_not.rb +3 -5
- data/lib/rubocop/cop/rspec/verified_doubles.rb +7 -15
- data/lib/rubocop/rspec/inject.rb +0 -1
- data/lib/rubocop/rspec/top_level_describe.rb +0 -2
- data/lib/rubocop/rspec/util.rb +19 -0
- data/lib/rubocop/rspec/version.rb +1 -2
- data/lib/rubocop/rspec/wording.rb +47 -0
- data/rubocop-rspec.gemspec +2 -2
- data/spec/project_spec.rb +0 -2
- data/spec/rubocop/cop/rspec/any_instance_spec.rb +0 -2
- data/spec/rubocop/cop/rspec/describe_class_spec.rb +36 -2
- data/spec/rubocop/cop/rspec/describe_method_spec.rb +10 -3
- data/spec/rubocop/cop/rspec/described_class_spec.rb +32 -2
- data/spec/rubocop/cop/rspec/example_length_spec.rb +17 -3
- data/spec/rubocop/cop/rspec/example_wording_spec.rb +61 -62
- data/spec/rubocop/cop/rspec/file_path_spec.rb +61 -21
- data/spec/rubocop/cop/rspec/focus_spec.rb +11 -3
- data/spec/rubocop/cop/rspec/instance_variable_spec.rb +13 -2
- data/spec/rubocop/cop/rspec/multiple_describes_spec.rb +0 -2
- data/spec/rubocop/cop/rspec/not_to_not_spec.rb +0 -2
- data/spec/rubocop/cop/rspec/verified_doubles_spec.rb +41 -19
- data/spec/rubocop/rspec/util/one_spec.rb +21 -0
- data/spec/rubocop/rspec/wording_spec.rb +44 -0
- data/spec/spec_helper.rb +1 -9
- metadata +11 -5
@@ -1,8 +1,5 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
1
|
describe RuboCop::Cop::RSpec::FilePath, :config do
|
4
2
|
subject(:cop) { described_class.new(config) }
|
5
|
-
let(:cop_config) { { 'CustomTransform' => { 'FooFoo' => 'foofoo' } } }
|
6
3
|
|
7
4
|
it 'checks the path' do
|
8
5
|
inspect_source(
|
@@ -28,6 +25,36 @@ describe RuboCop::Cop::RSpec::FilePath, :config do
|
|
28
25
|
.to eq(['Spec path should end with `my_class*foo*_spec.rb`'])
|
29
26
|
end
|
30
27
|
|
28
|
+
it 'flags foo_spec.rb.rb' do
|
29
|
+
inspect_source(
|
30
|
+
cop,
|
31
|
+
"describe MyClass, '#foo' do; end",
|
32
|
+
'my_class/foo_spec.rb.rb'
|
33
|
+
)
|
34
|
+
expect(cop.offenses.size).to eq(1)
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'flags foo_specorb' do
|
38
|
+
inspect_source(
|
39
|
+
cop,
|
40
|
+
"describe MyClass, '#foo' do; end",
|
41
|
+
'my_class/foo_specorb'
|
42
|
+
)
|
43
|
+
expect(cop.offenses.size).to eq(1)
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'checks path even when metadata is included' do
|
47
|
+
inspect_source(
|
48
|
+
cop,
|
49
|
+
"describe MyClass, '#foo', blah: :blah do; end",
|
50
|
+
'wrong_class_foo_spec.rb'
|
51
|
+
)
|
52
|
+
expect(cop.offenses.size).to eq(1)
|
53
|
+
expect(cop.offenses.map(&:line).sort).to eq([1])
|
54
|
+
expect(cop.messages)
|
55
|
+
.to eq(['Spec path should end with `my_class*foo*_spec.rb`'])
|
56
|
+
end
|
57
|
+
|
31
58
|
it 'checks class spec paths' do
|
32
59
|
inspect_source(
|
33
60
|
cop,
|
@@ -112,8 +139,8 @@ describe RuboCop::Cop::RSpec::FilePath, :config do
|
|
112
139
|
it 'handles alphanumeric class names' do
|
113
140
|
inspect_source(
|
114
141
|
cop,
|
115
|
-
'describe
|
116
|
-
'
|
142
|
+
'describe IPv4AndIPv6 do; end',
|
143
|
+
'i_pv4_and_i_pv6_spec.rb'
|
117
144
|
)
|
118
145
|
expect(cop.offenses).to be_empty
|
119
146
|
end
|
@@ -181,39 +208,52 @@ describe RuboCop::Cop::RSpec::FilePath, :config do
|
|
181
208
|
expect(cop.offenses).to be_empty
|
182
209
|
end
|
183
210
|
|
184
|
-
it 'allows
|
211
|
+
it 'allows bang method' do
|
185
212
|
inspect_source(
|
186
213
|
cop,
|
187
|
-
"describe Some::Class, '#
|
188
|
-
'some/class/
|
214
|
+
"describe Some::Class, '#bang!' do; end",
|
215
|
+
'some/class/bang_spec.rb'
|
189
216
|
)
|
190
217
|
expect(cop.offenses).to be_empty
|
191
218
|
end
|
192
219
|
|
193
|
-
it 'allows flexibility with
|
220
|
+
it 'allows flexibility with predicates' do
|
194
221
|
inspect_source(
|
195
222
|
cop,
|
196
|
-
"describe
|
197
|
-
'
|
223
|
+
"describe Some::Class, '#thing?' do; end",
|
224
|
+
'some/class/thing_predicate_spec.rb'
|
198
225
|
)
|
199
226
|
expect(cop.offenses).to be_empty
|
200
227
|
end
|
201
228
|
|
202
|
-
it '
|
229
|
+
it 'allows flexibility with operators' do
|
203
230
|
inspect_source(
|
204
231
|
cop,
|
205
|
-
"describe
|
206
|
-
'
|
232
|
+
"describe MyLittleClass, '#<=>' do; end",
|
233
|
+
'my_little_class/spaceship_operator_spec.rb'
|
207
234
|
)
|
208
235
|
expect(cop.offenses).to be_empty
|
209
236
|
end
|
210
237
|
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
238
|
+
context 'when configured' do
|
239
|
+
let(:cop_config) { { 'CustomTransform' => { 'FooFoo' => 'foofoo' } } }
|
240
|
+
|
241
|
+
it 'respects custom module name transformation' do
|
242
|
+
inspect_source(
|
243
|
+
cop,
|
244
|
+
"describe FooFoo::Some::Class, '#bar' do; end",
|
245
|
+
'foofoo/some/class/bar_spec.rb'
|
246
|
+
)
|
247
|
+
expect(cop.offenses).to be_empty
|
248
|
+
end
|
249
|
+
|
250
|
+
it 'ignores routing specs' do
|
251
|
+
inspect_source(
|
252
|
+
cop,
|
253
|
+
'describe MyController, "#foo", type: :routing do; end',
|
254
|
+
'foofoo/some/class/bar_spec.rb'
|
255
|
+
)
|
256
|
+
expect(cop.offenses).to be_empty
|
257
|
+
end
|
218
258
|
end
|
219
259
|
end
|
@@ -1,5 +1,3 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
1
|
describe RuboCop::Cop::RSpec::Focus do
|
4
2
|
subject(:cop) { described_class.new }
|
5
3
|
|
@@ -12,7 +10,7 @@ describe RuboCop::Cop::RSpec::Focus do
|
|
12
10
|
inspect_source(
|
13
11
|
cop,
|
14
12
|
[
|
15
|
-
"#{block_type} 'test', focus: true do",
|
13
|
+
"#{block_type} 'test', meta: true, focus: true do",
|
16
14
|
'end'
|
17
15
|
]
|
18
16
|
)
|
@@ -48,6 +46,16 @@ describe RuboCop::Cop::RSpec::Focus do
|
|
48
46
|
end
|
49
47
|
end
|
50
48
|
|
49
|
+
it 'does not flag a method that is focused twice' do
|
50
|
+
inspect_source(cop, 'fit "foo", :focus do; end')
|
51
|
+
expect(cop.offenses.size).to be(1)
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'ignores non-rspec code with :focus blocks' do
|
55
|
+
inspect_source(cop, 'some_method "foo", focus: true do; end')
|
56
|
+
expect(cop.offenses).to be_empty
|
57
|
+
end
|
58
|
+
|
51
59
|
[
|
52
60
|
:fdescribe, :fcontext,
|
53
61
|
:focus, :fexample, :fit, :fspecify,
|
@@ -1,5 +1,3 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
1
|
describe RuboCop::Cop::RSpec::InstanceVariable do
|
4
2
|
subject(:cop) { described_class.new }
|
5
3
|
|
@@ -18,6 +16,19 @@ describe RuboCop::Cop::RSpec::InstanceVariable do
|
|
18
16
|
expect(cop.messages).to eq(['Use `let` instead of an instance variable'])
|
19
17
|
end
|
20
18
|
|
19
|
+
it 'ignores non-spec blocks' do
|
20
|
+
inspect_source(
|
21
|
+
cop,
|
22
|
+
[
|
23
|
+
'not_rspec do',
|
24
|
+
' before { @foo = [] }',
|
25
|
+
' it { expect(@foo).to be_empty }',
|
26
|
+
'end'
|
27
|
+
]
|
28
|
+
)
|
29
|
+
expect(cop.offenses).to be_empty
|
30
|
+
end
|
31
|
+
|
21
32
|
it 'finds an instance variable inside a shared example' do
|
22
33
|
inspect_source(
|
23
34
|
cop,
|
@@ -1,5 +1,3 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
1
|
describe RuboCop::Cop::RSpec::VerifiedDoubles, :config do
|
4
2
|
subject(:cop) { described_class.new(config) }
|
5
3
|
|
@@ -11,26 +9,33 @@ describe RuboCop::Cop::RSpec::VerifiedDoubles, :config do
|
|
11
9
|
.to eq(['Prefer using verifying doubles over normal doubles.'])
|
12
10
|
expect(cop.highlights).to eq(['double("Widget")'])
|
13
11
|
expect(cop.offenses.map(&:line).sort).to eq([2])
|
12
|
+
expect(cop.offenses.map(&:to_s).sort).to all(
|
13
|
+
eql('C: 2: 9: Prefer using verifying doubles over normal doubles.')
|
14
|
+
)
|
14
15
|
end
|
15
16
|
|
16
|
-
|
17
|
-
|
18
|
-
' foo = spy("Widget")',
|
19
|
-
'end'])
|
20
|
-
expect(cop.messages)
|
21
|
-
.to eq(['Prefer using verifying doubles over normal doubles.'])
|
22
|
-
expect(cop.highlights).to eq(['spy("Widget")'])
|
23
|
-
expect(cop.offenses.map(&:line).sort).to eq([2])
|
24
|
-
end
|
17
|
+
context 'when configuration does not specify IgnoreSymbolicNames' do
|
18
|
+
let(:cop_config) { Hash.new }
|
25
19
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
20
|
+
it 'find doubles whose name is a symbol' do
|
21
|
+
inspect_source(cop, ['it do',
|
22
|
+
' foo = double(:widget)',
|
23
|
+
'end'])
|
24
|
+
expect(cop.messages)
|
25
|
+
.to eq(['Prefer using verifying doubles over normal doubles.'])
|
26
|
+
expect(cop.highlights).to eq(['double(:widget)'])
|
27
|
+
expect(cop.offenses.map(&:line).sort).to eq([2])
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'finds a `spy` instead of an `instance_spy`' do
|
31
|
+
inspect_source(cop, ['it do',
|
32
|
+
' foo = spy("Widget")',
|
33
|
+
'end'])
|
34
|
+
expect(cop.messages)
|
35
|
+
.to eq(['Prefer using verifying doubles over normal doubles.'])
|
36
|
+
expect(cop.highlights).to eq(['spy("Widget")'])
|
37
|
+
expect(cop.offenses.map(&:line).sort).to eq([2])
|
38
|
+
end
|
34
39
|
end
|
35
40
|
|
36
41
|
context 'when configured to ignore symbolic names' do
|
@@ -42,6 +47,16 @@ describe RuboCop::Cop::RSpec::VerifiedDoubles, :config do
|
|
42
47
|
'end'])
|
43
48
|
expect(cop.messages).to be_empty
|
44
49
|
end
|
50
|
+
|
51
|
+
it 'still flags doubles whose name is a string' do
|
52
|
+
inspect_source(cop, ['it do',
|
53
|
+
' foo = double("widget")',
|
54
|
+
'end'])
|
55
|
+
|
56
|
+
expect(cop.messages.first).to eq(
|
57
|
+
'Prefer using verifying doubles over normal doubles.'
|
58
|
+
)
|
59
|
+
end
|
45
60
|
end
|
46
61
|
|
47
62
|
it 'ignores doubles without a name' do
|
@@ -50,4 +65,11 @@ describe RuboCop::Cop::RSpec::VerifiedDoubles, :config do
|
|
50
65
|
'end'])
|
51
66
|
expect(cop.messages).to be_empty
|
52
67
|
end
|
68
|
+
|
69
|
+
it 'ignores instance_doubles' do
|
70
|
+
inspect_source(cop, ['it do',
|
71
|
+
' foo = instance_double("Foo")',
|
72
|
+
'end'])
|
73
|
+
expect(cop.messages).to be_empty
|
74
|
+
end
|
53
75
|
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
describe RuboCop::RSpec::Util, '.one' do
|
2
|
+
let(:first) { instance_double(Object) }
|
3
|
+
let(:array) { instance_double(Array, one?: true, first: first) }
|
4
|
+
let(:client) { Class.new.extend(described_class) }
|
5
|
+
|
6
|
+
it 'returns first element' do
|
7
|
+
expect(client.one(array)).to be(first)
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'fails if the list is empty' do
|
11
|
+
expect { client.one([]) }
|
12
|
+
.to raise_error(described_class::SizeError)
|
13
|
+
.with_message('expected size to be exactly 1 but size was 0')
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'fails if the list has more than one element' do
|
17
|
+
expect { client.one([1, 2]) }
|
18
|
+
.to raise_error(described_class::SizeError)
|
19
|
+
.with_message('expected size to be exactly 1 but size was 2')
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
describe RuboCop::RSpec::Wording do
|
2
|
+
let(:replacements) do
|
3
|
+
{ 'have' => 'has', 'not' => 'does not' }
|
4
|
+
end
|
5
|
+
|
6
|
+
let(:ignores) do
|
7
|
+
%w(only really)
|
8
|
+
end
|
9
|
+
|
10
|
+
expected_rewrites =
|
11
|
+
{
|
12
|
+
'should return something' => 'returns something',
|
13
|
+
'should not return something' => 'does not return something',
|
14
|
+
'should do nothing' => 'does nothing',
|
15
|
+
'should have sweets' => 'has sweets',
|
16
|
+
'should worry about the future' => 'worries about the future',
|
17
|
+
'should pay for pizza' => 'pays for pizza',
|
18
|
+
'should obey my orders' => 'obeys my orders',
|
19
|
+
'should deploy the app' => 'deploys the app',
|
20
|
+
'should buy the product' => 'buys the product',
|
21
|
+
'should miss me' => 'misses me',
|
22
|
+
'should fax the document' => 'faxes the document',
|
23
|
+
'should amass debt' => 'amasses debt',
|
24
|
+
'should echo the input' => 'echoes the input',
|
25
|
+
'should alias the method' => 'aliases the method',
|
26
|
+
'should search the internet' => 'searches the internet',
|
27
|
+
'should wish me luck' => 'wishes me luck',
|
28
|
+
'should really only return one item' => 'really only returns one item',
|
29
|
+
"shouldn't return something" => 'does not return something'
|
30
|
+
}
|
31
|
+
|
32
|
+
expected_rewrites.each do |old, new|
|
33
|
+
it %(rewrites "#{old}" as "#{new}") do
|
34
|
+
rewrite =
|
35
|
+
described_class.new(
|
36
|
+
old,
|
37
|
+
replace: replacements,
|
38
|
+
ignore: ignores
|
39
|
+
).rewrite
|
40
|
+
|
41
|
+
expect(rewrite).to eql(new)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,14 +1,6 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
1
|
require 'rubocop'
|
4
2
|
|
5
|
-
|
6
|
-
|
7
|
-
unless File.directory?(rubocop_path)
|
8
|
-
raise "Can't run specs without a local RuboCop checkout. Look in the README."
|
9
|
-
end
|
10
|
-
|
11
|
-
Dir["#{rubocop_path}/spec/support/**/*.rb"].each { |f| require f }
|
3
|
+
require 'rubocop/rspec/support'
|
12
4
|
|
13
5
|
if ENV['CI']
|
14
6
|
require 'codeclimate-test-reporter'
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rubocop-rspec
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.5.
|
4
|
+
version: 1.5.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ian MacLeod
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2016-
|
12
|
+
date: 2016-08-01 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rubocop
|
@@ -17,14 +17,14 @@ dependencies:
|
|
17
17
|
requirements:
|
18
18
|
- - ">="
|
19
19
|
- !ruby/object:Gem::Version
|
20
|
-
version: 0.
|
20
|
+
version: 0.42.0
|
21
21
|
type: :runtime
|
22
22
|
prerelease: false
|
23
23
|
version_requirements: !ruby/object:Gem::Requirement
|
24
24
|
requirements:
|
25
25
|
- - ">="
|
26
26
|
- !ruby/object:Gem::Version
|
27
|
-
version: 0.
|
27
|
+
version: 0.42.0
|
28
28
|
- !ruby/object:Gem::Dependency
|
29
29
|
name: rake
|
30
30
|
requirement: !ruby/object:Gem::Requirement
|
@@ -100,7 +100,9 @@ files:
|
|
100
100
|
- lib/rubocop/cop/rspec/verified_doubles.rb
|
101
101
|
- lib/rubocop/rspec/inject.rb
|
102
102
|
- lib/rubocop/rspec/top_level_describe.rb
|
103
|
+
- lib/rubocop/rspec/util.rb
|
103
104
|
- lib/rubocop/rspec/version.rb
|
105
|
+
- lib/rubocop/rspec/wording.rb
|
104
106
|
- rubocop-rspec.gemspec
|
105
107
|
- spec/project_spec.rb
|
106
108
|
- spec/rubocop/cop/rspec/any_instance_spec.rb
|
@@ -115,6 +117,8 @@ files:
|
|
115
117
|
- spec/rubocop/cop/rspec/multiple_describes_spec.rb
|
116
118
|
- spec/rubocop/cop/rspec/not_to_not_spec.rb
|
117
119
|
- spec/rubocop/cop/rspec/verified_doubles_spec.rb
|
120
|
+
- spec/rubocop/rspec/util/one_spec.rb
|
121
|
+
- spec/rubocop/rspec/wording_spec.rb
|
118
122
|
- spec/spec_helper.rb
|
119
123
|
homepage: http://github.com/nevir/rubocop-rspec
|
120
124
|
licenses:
|
@@ -128,7 +132,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
128
132
|
requirements:
|
129
133
|
- - ">="
|
130
134
|
- !ruby/object:Gem::Version
|
131
|
-
version: 2.
|
135
|
+
version: 2.2.0
|
132
136
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
133
137
|
requirements:
|
134
138
|
- - ">="
|
@@ -154,4 +158,6 @@ test_files:
|
|
154
158
|
- spec/rubocop/cop/rspec/multiple_describes_spec.rb
|
155
159
|
- spec/rubocop/cop/rspec/not_to_not_spec.rb
|
156
160
|
- spec/rubocop/cop/rspec/verified_doubles_spec.rb
|
161
|
+
- spec/rubocop/rspec/util/one_spec.rb
|
162
|
+
- spec/rubocop/rspec/wording_spec.rb
|
157
163
|
- spec/spec_helper.rb
|