rubocop-rspec 1.0.1 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b632d4031edbdbf3b9c5725b94b93c1869f93bbe
4
- data.tar.gz: 9647cd0ba4cddd8e6835199a18b9e872cfbac3fd
3
+ metadata.gz: d78e6378d0979625180390c70a6e37d889a67652
4
+ data.tar.gz: 95a96f1a4def09e03681c8f76600a066556186a4
5
5
  SHA512:
6
- metadata.gz: 8cf570910495f4e5676ff3919ded08af4eb8cc02ef1ae8d68a2a881b608ac059555951ec8474309d1a5045203eafde5729338b4c3283d2df2334eef7babb21e7
7
- data.tar.gz: af4516dd2e81af1063e0a76d934e51fed5bc6f187be0eea955096ac707d3a09cf28b555ef20e1c7a8beb047674b7177f233a1c086118acb97496e5a5190e9a9e
6
+ metadata.gz: 24074653cb0280bbafea8676c58f3fddca8dea629d79c72ce26655fb8fb7a3440e9665ce6d231701d22f7a8375c36681dd8522ce8f49def8d8d5cbe2ad914b47
7
+ data.tar.gz: ae19016c5b9ae6385ecc7f56dbc9f5e97daba9c93eff6d0d3f061a35d5407f0c36b713f1adb81bba5db7b65b9bb5a7c3566614a20070fd9cae9c802005456479
@@ -1,5 +1,9 @@
1
1
  # Change log
2
2
 
3
+ ## 1.1.0
4
+
5
+ * Add `autocorrect` to `RSpec::DescribedClass` cop. ([@geniou][])
6
+
3
7
  ## 1.0.1
4
8
 
5
9
  * Add `config` folder to gemspec. ([@pstengel][])
@@ -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)
@@ -4,7 +4,7 @@ module RuboCop
4
4
  module RSpec
5
5
  # Version information for the RSpec RuboCop plugin.
6
6
  module Version
7
- STRING = '1.0.1'
7
+ STRING = '1.1.0'
8
8
  end
9
9
  end
10
10
  end
@@ -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(2)
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`'] * 2)
17
- expect(cop.highlights).to eq(['MyClass'] * 2)
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 describes that do not referece to a class' do
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.1
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-16 00:00:00.000000000 Z
12
+ date: 2014-06-25 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rubocop