rubocop-rspec 1.0.1 → 1.1.0
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 +4 -0
- data/lib/rubocop/cop/rspec/described_class.rb +6 -0
- data/lib/rubocop/rspec/version.rb +1 -1
- data/spec/rubocop/cop/rspec/described_class_spec.rb +19 -16
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d78e6378d0979625180390c70a6e37d889a67652
|
4
|
+
data.tar.gz: 95a96f1a4def09e03681c8f76600a066556186a4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 24074653cb0280bbafea8676c58f3fddca8dea629d79c72ce26655fb8fb7a3440e9665ce6d231701d22f7a8375c36681dd8522ce8f49def8d8d5cbe2ad914b47
|
7
|
+
data.tar.gz: ae19016c5b9ae6385ecc7f56dbc9f5e97daba9c93eff6d0d3f061a35d5407f0c36b713f1adb81bba5db7b65b9bb5a7c3566614a20070fd9cae9c802005456479
|
data/CHANGELOG.md
CHANGED
@@ -33,6 +33,12 @@ module RuboCop
|
|
33
33
|
inspect_children(body, object)
|
34
34
|
end
|
35
35
|
|
36
|
+
def autocorrect(node)
|
37
|
+
@corrections << lambda do |corrector|
|
38
|
+
corrector.replace(node.loc.expression, 'described_class')
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
36
42
|
private
|
37
43
|
|
38
44
|
def inspect_children(node, object)
|
@@ -7,14 +7,15 @@ describe RuboCop::Cop::RSpec::DescribedClass do
|
|
7
7
|
|
8
8
|
it 'checks for the use of the described class' do
|
9
9
|
inspect_source(cop, ['describe MyClass do',
|
10
|
+
' include MyClass',
|
10
11
|
' subject { MyClass.do_something }',
|
11
12
|
' before { MyClass.do_something }',
|
12
13
|
'end'])
|
13
|
-
expect(cop.offenses.size).to eq(
|
14
|
-
expect(cop.offenses.map(&:line).sort).to eq([2, 3])
|
14
|
+
expect(cop.offenses.size).to eq(3)
|
15
|
+
expect(cop.offenses.map(&:line).sort).to eq([2, 3, 4])
|
15
16
|
expect(cop.messages)
|
16
|
-
.to eq(['Use `described_class` instead of `MyClass`'] *
|
17
|
-
expect(cop.highlights).to eq(['MyClass'] *
|
17
|
+
.to eq(['Use `described_class` instead of `MyClass`'] * 3)
|
18
|
+
expect(cop.highlights).to eq(['MyClass'] * 3)
|
18
19
|
end
|
19
20
|
|
20
21
|
it 'ignores described class as string' do
|
@@ -24,24 +25,13 @@ describe RuboCop::Cop::RSpec::DescribedClass do
|
|
24
25
|
expect(cop.offenses).to be_empty
|
25
26
|
end
|
26
27
|
|
27
|
-
it 'ignores
|
28
|
+
it 'ignores describe that do not referece to a class' do
|
28
29
|
inspect_source(cop, ['describe "MyClass" do',
|
29
30
|
' subject { "MyClass" }',
|
30
31
|
'end'])
|
31
32
|
expect(cop.offenses).to be_empty
|
32
33
|
end
|
33
34
|
|
34
|
-
it 'ignores if the scope is changing' do
|
35
|
-
inspect_source(cop, ['describe MyClass do',
|
36
|
-
' include MyClass',
|
37
|
-
'end'])
|
38
|
-
expect(cop.offenses.size).to eq(1)
|
39
|
-
expect(cop.offenses.map(&:line).sort).to eq([2])
|
40
|
-
expect(cop.messages)
|
41
|
-
.to eq(['Use `described_class` instead of `MyClass`'])
|
42
|
-
expect(cop.highlights).to eq(['MyClass'])
|
43
|
-
end
|
44
|
-
|
45
35
|
it 'ignores class if the scope is changing' do
|
46
36
|
inspect_source(cop, ['describe MyClass do',
|
47
37
|
' def method',
|
@@ -110,4 +100,17 @@ describe RuboCop::Cop::RSpec::DescribedClass do
|
|
110
100
|
.to eq(['Use `described_class` instead of `MyNamespace::MyClass`'])
|
111
101
|
expect(cop.highlights).to eq(['MyNamespace::MyClass'])
|
112
102
|
end
|
103
|
+
|
104
|
+
it 'autocorrects an offenses' do
|
105
|
+
new_source = autocorrect_source(cop, ['describe MyClass do',
|
106
|
+
' include MyClass',
|
107
|
+
' subject { MyClass.do_something }',
|
108
|
+
' before { MyClass.do_something }',
|
109
|
+
'end'])
|
110
|
+
expect(new_source).to eq(['describe MyClass do',
|
111
|
+
' include described_class',
|
112
|
+
' subject { described_class.do_something }',
|
113
|
+
' before { described_class.do_something }',
|
114
|
+
'end'].join("\n"))
|
115
|
+
end
|
113
116
|
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.0
|
4
|
+
version: 1.1.0
|
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-06-
|
12
|
+
date: 2014-06-25 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rubocop
|