rubocop-rspec 1.2.0 → 1.2.1
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 +5 -0
- data/config/default.yml +4 -0
- data/lib/rubocop-rspec.rb +1 -0
- data/lib/rubocop/cop/rspec/example_wording.rb +2 -2
- data/lib/rubocop/cop/rspec/instance_variable.rb +2 -2
- data/lib/rubocop/cop/rspec/verified_doubles.rb +32 -0
- data/lib/rubocop/rspec/version.rb +1 -1
- data/spec/project_spec.rb +1 -3
- data/spec/rubocop/cop/rspec/describe_class_spec.rb +0 -2
- data/spec/rubocop/cop/rspec/describe_method_spec.rb +2 -4
- data/spec/rubocop/cop/rspec/described_class_spec.rb +0 -2
- data/spec/rubocop/cop/rspec/example_wording_spec.rb +2 -4
- data/spec/rubocop/cop/rspec/file_path_spec.rb +0 -2
- data/spec/rubocop/cop/rspec/instance_variable_spec.rb +2 -4
- data/spec/rubocop/cop/rspec/multiple_describes_spec.rb +0 -2
- data/spec/rubocop/cop/rspec/verified_doubles_spec.rb +15 -0
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 781c177bf195bc9ec0663b45b2312aa2a94f6da2
|
4
|
+
data.tar.gz: 44414a1e7ea2f3ee8ac707b8d6e5659e5789588b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f95537228be6ba9d25328bfcb375091ba5bcfc2bc58ba384c910e6f87fd367a5510dfec4f47cdf07a2e863794a614d657c22b7d744b94380db6e6a67e6f6f78c
|
7
|
+
data.tar.gz: 157e06d0dc76c034b8a2704dad0747d15cb59654412206957fa4c4365686adf8764544de0b8ad1ca6f21c7bc54d6e21b30a0e04526ec51636663d6b2f1dbe176
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,9 @@
|
|
1
1
|
# Change log
|
2
2
|
|
3
|
+
## 1.2.1
|
4
|
+
|
5
|
+
* Add `RSpec::VerifiedDoubles` cop. ([@andyw8][])
|
6
|
+
|
3
7
|
## 1.2.0
|
4
8
|
|
5
9
|
* Drop support of ruby `1.9.2`. ([@geniou][])
|
@@ -39,6 +43,7 @@
|
|
39
43
|
|
40
44
|
<!-- Contributors -->
|
41
45
|
|
46
|
+
[@andyw8]: https://github.com/andyw8
|
42
47
|
[@geniou]: https://github.com/geniou
|
43
48
|
[@nevir]: https://github.com/nevir
|
44
49
|
[@pstengel]: https://github.com/pstengel
|
data/config/default.yml
CHANGED
data/lib/rubocop-rspec.rb
CHANGED
@@ -20,7 +20,7 @@ module RuboCop
|
|
20
20
|
class ExampleWording < Cop
|
21
21
|
MSG = 'Do not use should when describing your tests.'
|
22
22
|
|
23
|
-
def on_block(node)
|
23
|
+
def on_block(node) # rubocop:disable Metrics/AbcSize
|
24
24
|
method, _, _ = *node
|
25
25
|
_, method_name, *args = *method
|
26
26
|
|
@@ -63,7 +63,7 @@ module RuboCop
|
|
63
63
|
|
64
64
|
# ends with o s x ch sh or ss
|
65
65
|
if %w(o s x]).include?(word[-1]) ||
|
66
|
-
|
66
|
+
%w(ch sh ss]).include?(word[-2..-1])
|
67
67
|
return "#{word}es"
|
68
68
|
end
|
69
69
|
|
@@ -10,13 +10,13 @@ module RuboCop
|
|
10
10
|
# # bad
|
11
11
|
# describe MyClass do
|
12
12
|
# before { @foo = [] }
|
13
|
-
# it { expect(@foo).to
|
13
|
+
# it { expect(@foo).to be_empty }
|
14
14
|
# end
|
15
15
|
#
|
16
16
|
# # good
|
17
17
|
# describe MyClass do
|
18
18
|
# let(:foo) { [] }
|
19
|
-
# it { expect(foo).to
|
19
|
+
# it { expect(foo).to be_empty }
|
20
20
|
# end
|
21
21
|
class InstanceVariable < Cop
|
22
22
|
MESSAGE = 'Use `let` instead of an instance variable'
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Cop
|
5
|
+
module RSpec
|
6
|
+
# Prefer using verifying doubles over normal doubles.
|
7
|
+
# see: https://relishapp.com/rspec/rspec-mocks/docs/verifying-doubles
|
8
|
+
#
|
9
|
+
# @example
|
10
|
+
# # bad
|
11
|
+
# it '...' do
|
12
|
+
# widget = double("Widget")
|
13
|
+
# end
|
14
|
+
#
|
15
|
+
# # good
|
16
|
+
# it '...' do
|
17
|
+
# widget = instance_double("Widget")
|
18
|
+
# end
|
19
|
+
class VerifiedDoubles < Cop
|
20
|
+
MSG = 'Prefer using verifying doubles over normal doubles.'
|
21
|
+
|
22
|
+
def on_send(node)
|
23
|
+
_receiver, method_name, *_args = *node
|
24
|
+
return unless method_name == :double
|
25
|
+
add_offense(node,
|
26
|
+
:expression,
|
27
|
+
format(MSG, node.loc.expression.source))
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
data/spec/project_spec.rb
CHANGED
@@ -1,7 +1,5 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
3
|
describe 'RuboCop Project' do # rubocop:disable RSpec/DescribeClass
|
6
4
|
describe 'default configuration file' do
|
7
5
|
let(:cop_names) do
|
@@ -9,7 +7,7 @@ describe 'RuboCop Project' do # rubocop:disable RSpec/DescribeClass
|
|
9
7
|
'rspec', '*.rb'))
|
10
8
|
.map do |file|
|
11
9
|
cop_name = File.basename(file, '.rb')
|
12
|
-
|
10
|
+
.gsub(/(^|_)(.)/) { Regexp.last_match(2).upcase }
|
13
11
|
|
14
12
|
"RSpec/#{cop_name}"
|
15
13
|
end
|
@@ -1,7 +1,5 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
3
|
describe RuboCop::Cop::RSpec::DescribeMethod do
|
6
4
|
subject(:cop) { described_class.new }
|
7
5
|
|
@@ -10,8 +8,8 @@ describe RuboCop::Cop::RSpec::DescribeMethod do
|
|
10
8
|
expect(cop.offenses.size).to eq(1)
|
11
9
|
expect(cop.offenses.map(&:line).sort).to eq([1])
|
12
10
|
expect(cop.messages)
|
13
|
-
|
14
|
-
|
11
|
+
.to eq(['The second argument to describe should be the method being ' \
|
12
|
+
"tested. '#instance' or '.class'"])
|
15
13
|
end
|
16
14
|
|
17
15
|
it 'skips methods starting with a . or #' do
|
@@ -1,13 +1,11 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
3
|
describe RuboCop::Cop::RSpec::ExampleWording, :config do
|
6
4
|
subject(:cop) { described_class.new(config) }
|
7
5
|
let(:cop_config) do
|
8
6
|
{
|
9
7
|
'CustomTransform' => { 'have' => 'has', 'not' => 'does not' },
|
10
|
-
'IgnoredWords' => %w(only
|
8
|
+
'IgnoredWords' => %w(only really)
|
11
9
|
}
|
12
10
|
end
|
13
11
|
|
@@ -44,7 +42,7 @@ describe RuboCop::Cop::RSpec::ExampleWording, :config do
|
|
44
42
|
'should worry about the future' => 'worries about the future',
|
45
43
|
'should pay for pizza' => 'pays for pizza',
|
46
44
|
'should miss me' => 'misses me',
|
47
|
-
'should
|
45
|
+
'should really only return one item' => 'really only returns one item'
|
48
46
|
}.each do |old, new|
|
49
47
|
it 'autocorrects an offenses' do
|
50
48
|
new_source = autocorrect_source(cop, ["it '#{old}' do", 'end'])
|
@@ -1,14 +1,12 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
3
|
describe RuboCop::Cop::RSpec::InstanceVariable do
|
6
4
|
subject(:cop) { described_class.new }
|
7
5
|
|
8
6
|
it 'finds an instance variable inside a describe' do
|
9
7
|
inspect_source(cop, ['describe MyClass do',
|
10
8
|
' before { @foo = [] }',
|
11
|
-
' it { expect(@foo).to
|
9
|
+
' it { expect(@foo).to be_empty }',
|
12
10
|
'end'])
|
13
11
|
expect(cop.offenses.size).to eq(1)
|
14
12
|
expect(cop.offenses.map(&:line).sort).to eq([3])
|
@@ -17,7 +15,7 @@ describe RuboCop::Cop::RSpec::InstanceVariable do
|
|
17
15
|
|
18
16
|
it 'finds an instance variable inside a shared example' do
|
19
17
|
inspect_source(cop, ["shared_examples 'shared example' do",
|
20
|
-
' it { expect(@foo).to
|
18
|
+
' it { expect(@foo).to be_empty }',
|
21
19
|
'end'])
|
22
20
|
expect(cop.offenses.size).to eq(1)
|
23
21
|
expect(cop.offenses.map(&:line).sort).to eq([2])
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
describe RuboCop::Cop::RSpec::VerifiedDoubles do
|
4
|
+
subject(:cop) { described_class.new }
|
5
|
+
|
6
|
+
it 'finds `double` instead of a verifying double' do
|
7
|
+
inspect_source(cop, ['it do',
|
8
|
+
' foo = double("Widget")',
|
9
|
+
'end'])
|
10
|
+
expect(cop.messages)
|
11
|
+
.to eq(['Prefer using verifying doubles over normal doubles.'])
|
12
|
+
expect(cop.highlights).to eq(['double("Widget")'])
|
13
|
+
expect(cop.offenses.map(&:line).sort).to eq([2])
|
14
|
+
end
|
15
|
+
end
|
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.2.
|
4
|
+
version: 1.2.1
|
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: 2014-
|
12
|
+
date: 2014-11-03 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rubocop
|
@@ -93,6 +93,7 @@ files:
|
|
93
93
|
- lib/rubocop/cop/rspec/file_path.rb
|
94
94
|
- lib/rubocop/cop/rspec/instance_variable.rb
|
95
95
|
- lib/rubocop/cop/rspec/multiple_describes.rb
|
96
|
+
- lib/rubocop/cop/rspec/verified_doubles.rb
|
96
97
|
- lib/rubocop/rspec/inject.rb
|
97
98
|
- lib/rubocop/rspec/top_level_describe.rb
|
98
99
|
- lib/rubocop/rspec/version.rb
|
@@ -105,6 +106,7 @@ files:
|
|
105
106
|
- spec/rubocop/cop/rspec/file_path_spec.rb
|
106
107
|
- spec/rubocop/cop/rspec/instance_variable_spec.rb
|
107
108
|
- spec/rubocop/cop/rspec/multiple_describes_spec.rb
|
109
|
+
- spec/rubocop/cop/rspec/verified_doubles_spec.rb
|
108
110
|
- spec/spec_helper.rb
|
109
111
|
homepage: http://github.com/nevir/rubocop-rspec
|
110
112
|
licenses:
|
@@ -139,5 +141,6 @@ test_files:
|
|
139
141
|
- spec/rubocop/cop/rspec/file_path_spec.rb
|
140
142
|
- spec/rubocop/cop/rspec/instance_variable_spec.rb
|
141
143
|
- spec/rubocop/cop/rspec/multiple_describes_spec.rb
|
144
|
+
- spec/rubocop/cop/rspec/verified_doubles_spec.rb
|
142
145
|
- spec/spec_helper.rb
|
143
146
|
has_rdoc:
|