rubocop-rspec 1.4.1 → 1.5.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,70 @@
1
+ # encoding: utf-8
2
+
3
+ describe RuboCop::Cop::RSpec::Focus do
4
+ subject(:cop) { described_class.new }
5
+
6
+ [
7
+ :example_group, :describe, :context, :xdescribe, :xcontext,
8
+ :it, :example, :specify, :xit, :xexample, :xspecify,
9
+ :feature, :scenario, :xfeature, :xscenario
10
+ ].each do |block_type|
11
+ it "finds `#{block_type}` blocks with `focus: true`" do
12
+ inspect_source(
13
+ cop,
14
+ [
15
+ "#{block_type} 'test', focus: true do",
16
+ 'end'
17
+ ]
18
+ )
19
+ expect(cop.offenses.size).to eq(1)
20
+ expect(cop.offenses.map(&:line).sort).to eq([1])
21
+ expect(cop.messages).to eq(['Focused spec found.'])
22
+ expect(cop.highlights).to eq(['focus: true'])
23
+ end
24
+
25
+ it "finds `#{block_type}` blocks with `:focus`" do
26
+ inspect_source(
27
+ cop,
28
+ [
29
+ "#{block_type} 'test', :focus do",
30
+ 'end'
31
+ ]
32
+ )
33
+ expect(cop.offenses.size).to eq(1)
34
+ expect(cop.offenses.map(&:line).sort).to eq([1])
35
+ expect(cop.messages).to eq(['Focused spec found.'])
36
+ expect(cop.highlights).to eq([':focus'])
37
+ end
38
+
39
+ it 'detects no offense when spec is not focused' do
40
+ inspect_source(
41
+ cop,
42
+ [
43
+ "#{block_type} 'test' do",
44
+ 'end'
45
+ ]
46
+ )
47
+ expect(subject.messages).to be_empty
48
+ end
49
+ end
50
+
51
+ [
52
+ :fdescribe, :fcontext,
53
+ :focus, :fexample, :fit, :fspecify,
54
+ :ffeature, :fscenario
55
+ ].each do |block_type|
56
+ it "finds `#{block_type}` blocks" do
57
+ inspect_source(
58
+ cop,
59
+ [
60
+ "#{block_type} 'test' do",
61
+ 'end'
62
+ ]
63
+ )
64
+ expect(cop.offenses.size).to eq(1)
65
+ expect(cop.offenses.map(&:line).sort).to eq([1])
66
+ expect(cop.messages).to eq(['Focused spec found.'])
67
+ expect(cop.highlights).to eq(["#{block_type} 'test'"])
68
+ end
69
+ end
70
+ end
@@ -4,27 +4,36 @@ describe RuboCop::Cop::RSpec::InstanceVariable do
4
4
  subject(:cop) { described_class.new }
5
5
 
6
6
  it 'finds an instance variable inside a describe' do
7
- inspect_source(cop, ['describe MyClass do',
8
- ' before { @foo = [] }',
9
- ' it { expect(@foo).to be_empty }',
10
- 'end'])
7
+ inspect_source(
8
+ cop,
9
+ [
10
+ 'describe MyClass do',
11
+ ' before { @foo = [] }',
12
+ ' it { expect(@foo).to be_empty }',
13
+ 'end'
14
+ ]
15
+ )
11
16
  expect(cop.offenses.size).to eq(1)
12
17
  expect(cop.offenses.map(&:line).sort).to eq([3])
13
18
  expect(cop.messages).to eq(['Use `let` instead of an instance variable'])
14
19
  end
15
20
 
16
21
  it 'finds an instance variable inside a shared example' do
17
- inspect_source(cop, ["shared_examples 'shared example' do",
18
- ' it { expect(@foo).to be_empty }',
19
- 'end'])
22
+ inspect_source(
23
+ cop,
24
+ [
25
+ "shared_examples 'shared example' do",
26
+ ' it { expect(@foo).to be_empty }',
27
+ 'end'
28
+ ]
29
+ )
20
30
  expect(cop.offenses.size).to eq(1)
21
31
  expect(cop.offenses.map(&:line).sort).to eq([2])
22
32
  expect(cop.messages).to eq(['Use `let` instead of an instance variable'])
23
33
  end
24
34
 
25
35
  it 'ignores an instance variable without describe' do
26
- inspect_source(cop, ['@foo = []',
27
- '@foo.empty?'])
36
+ inspect_source(cop, ['@foo = []', '@foo.empty?'])
28
37
  expect(cop.offenses).to be_empty
29
38
  end
30
39
  end
@@ -4,8 +4,13 @@ describe RuboCop::Cop::RSpec::MultipleDescribes do
4
4
  subject(:cop) { described_class.new }
5
5
 
6
6
  it 'finds multiple top level describes with class and method' do
7
- inspect_source(cop, ["describe MyClass, '.do_something' do; end",
8
- "describe MyClass, '.do_something_else' do; end"])
7
+ inspect_source(
8
+ cop,
9
+ [
10
+ "describe MyClass, '.do_something' do; end",
11
+ "describe MyClass, '.do_something_else' do; end"
12
+ ]
13
+ )
9
14
  expect(cop.offenses.size).to eq(1)
10
15
  expect(cop.offenses.map(&:line).sort).to eq([1])
11
16
  expect(cop.messages).to eq(['Do not use multiple top level describes - ' \
@@ -13,8 +18,13 @@ describe RuboCop::Cop::RSpec::MultipleDescribes do
13
18
  end
14
19
 
15
20
  it 'finds multiple top level describes only with class' do
16
- inspect_source(cop, ['describe MyClass do; end',
17
- 'describe MyOtherClass do; end'])
21
+ inspect_source(
22
+ cop,
23
+ [
24
+ 'describe MyClass do; end',
25
+ 'describe MyOtherClass do; end'
26
+ ]
27
+ )
18
28
  expect(cop.offenses.size).to eq(1)
19
29
  expect(cop.offenses.map(&:line).sort).to eq([1])
20
30
  expect(cop.messages).to eq(['Do not use multiple top level describes - ' \
@@ -22,9 +32,14 @@ describe RuboCop::Cop::RSpec::MultipleDescribes do
22
32
  end
23
33
 
24
34
  it 'skips single top level describe' do
25
- inspect_source(cop, ["require 'spec_helper'",
26
- '',
27
- 'describe MyClass do; end'])
35
+ inspect_source(
36
+ cop,
37
+ [
38
+ "require 'spec_helper'",
39
+ '',
40
+ 'describe MyClass do; end'
41
+ ]
42
+ )
28
43
  expect(cop.offenses).to be_empty
29
44
  end
30
45
  end
@@ -3,13 +3,13 @@
3
3
  describe RuboCop::Cop::RSpec::NotToNot, :config do
4
4
  subject(:cop) { described_class.new(config) }
5
5
 
6
- context 'when AcceptedMethod is `not_to`' do
7
- let(:cop_config) { { 'AcceptedMethod' => 'not_to' } }
6
+ context 'when EnforcedStyle is `not_to`' do
7
+ let(:cop_config) { { 'EnforcedStyle' => 'not_to' } }
8
8
 
9
9
  it 'detects the `to_not` offense' do
10
10
  inspect_source(subject, 'it { expect(false).to_not be_true }')
11
11
 
12
- expect(subject.messages).to eq(['Use `not_to` instead of `to_not`'])
12
+ expect(subject.messages).to eq(['Prefer `not_to` over `to_not`'])
13
13
  expect(subject.highlights).to eq(['expect(false).to_not be_true'])
14
14
  expect(subject.offenses.map(&:line).sort).to eq([1])
15
15
  end
@@ -19,15 +19,20 @@ describe RuboCop::Cop::RSpec::NotToNot, :config do
19
19
 
20
20
  expect(subject.messages).to be_empty
21
21
  end
22
+
23
+ it 'auto-corrects `to_not` to `not_to`' do
24
+ corrected = autocorrect_source(cop, ['it { expect(0).to_not equal 1 }'])
25
+ expect(corrected).to eq 'it { expect(0).not_to equal 1 }'
26
+ end
22
27
  end
23
28
 
24
29
  context 'when AcceptedMethod is `to_not`' do
25
- let(:cop_config) { { 'AcceptedMethod' => 'to_not' } }
30
+ let(:cop_config) { { 'EnforcedStyle' => 'to_not' } }
26
31
 
27
32
  it 'detects the `not_to` offense' do
28
33
  inspect_source(subject, 'it { expect(false).not_to be_true }')
29
34
 
30
- expect(subject.messages).to eq(['Use `to_not` instead of `not_to`'])
35
+ expect(subject.messages).to eq(['Prefer `to_not` over `not_to`'])
31
36
  expect(subject.highlights).to eq(['expect(false).not_to be_true'])
32
37
  expect(subject.offenses.map(&:line).sort).to eq([1])
33
38
  end
@@ -37,5 +42,10 @@ describe RuboCop::Cop::RSpec::NotToNot, :config do
37
42
 
38
43
  expect(subject.messages).to be_empty
39
44
  end
45
+
46
+ it 'auto-corrects `not_to` to `to_not`' do
47
+ corrected = autocorrect_source(cop, ['it { expect(0).not_to equal 1 }'])
48
+ expect(corrected).to eq 'it { expect(0).to_not equal 1 }'
49
+ end
40
50
  end
41
51
  end
@@ -1,9 +1,9 @@
1
1
  # encoding: utf-8
2
2
 
3
- describe RuboCop::Cop::RSpec::VerifiedDoubles do
4
- subject(:cop) { described_class.new }
3
+ describe RuboCop::Cop::RSpec::VerifiedDoubles, :config do
4
+ subject(:cop) { described_class.new(config) }
5
5
 
6
- it 'finds `double` instead of a verifying double' do
6
+ it 'finds a `double` instead of an `instance_double`' do
7
7
  inspect_source(cop, ['it do',
8
8
  ' foo = double("Widget")',
9
9
  'end'])
@@ -12,4 +12,42 @@ describe RuboCop::Cop::RSpec::VerifiedDoubles do
12
12
  expect(cop.highlights).to eq(['double("Widget")'])
13
13
  expect(cop.offenses.map(&:line).sort).to eq([2])
14
14
  end
15
+
16
+ it 'finds a `spy` instead of an `instance_spy`' do
17
+ inspect_source(cop, ['it do',
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
25
+
26
+ it 'find doubles whose name is a symbol' do
27
+ inspect_source(cop, ['it do',
28
+ ' foo = double(:widget)',
29
+ 'end'])
30
+ expect(cop.messages)
31
+ .to eq(['Prefer using verifying doubles over normal doubles.'])
32
+ expect(cop.highlights).to eq(['double(:widget)'])
33
+ expect(cop.offenses.map(&:line).sort).to eq([2])
34
+ end
35
+
36
+ context 'when configured to ignore symbolic names' do
37
+ let(:cop_config) { { 'IgnoreSymbolicNames' => true } }
38
+
39
+ it 'ignores doubles whose name is a symbol' do
40
+ inspect_source(cop, ['it do',
41
+ ' foo = double(:widget)',
42
+ 'end'])
43
+ expect(cop.messages).to be_empty
44
+ end
45
+ end
46
+
47
+ it 'ignores doubles without a name' do
48
+ inspect_source(cop, ['it do',
49
+ ' foo = double',
50
+ 'end'])
51
+ expect(cop.messages).to be_empty
52
+ end
15
53
  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.4.1
4
+ version: 1.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ian MacLeod
@@ -9,22 +9,22 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-04-03 00:00:00.000000000 Z
12
+ date: 2016-05-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rubocop
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  requirements:
18
- - - '='
18
+ - - ">="
19
19
  - !ruby/object:Gem::Version
20
- version: 0.39.0
20
+ version: 0.40.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.39.0
27
+ version: 0.40.0
28
28
  - !ruby/object:Gem::Dependency
29
29
  name: rake
30
30
  requirement: !ruby/object:Gem::Requirement
@@ -90,8 +90,10 @@ files:
90
90
  - lib/rubocop/cop/rspec/describe_class.rb
91
91
  - lib/rubocop/cop/rspec/describe_method.rb
92
92
  - lib/rubocop/cop/rspec/described_class.rb
93
+ - lib/rubocop/cop/rspec/example_length.rb
93
94
  - lib/rubocop/cop/rspec/example_wording.rb
94
95
  - lib/rubocop/cop/rspec/file_path.rb
96
+ - lib/rubocop/cop/rspec/focus.rb
95
97
  - lib/rubocop/cop/rspec/instance_variable.rb
96
98
  - lib/rubocop/cop/rspec/multiple_describes.rb
97
99
  - lib/rubocop/cop/rspec/not_to_not.rb
@@ -105,8 +107,10 @@ files:
105
107
  - spec/rubocop/cop/rspec/describe_class_spec.rb
106
108
  - spec/rubocop/cop/rspec/describe_method_spec.rb
107
109
  - spec/rubocop/cop/rspec/described_class_spec.rb
110
+ - spec/rubocop/cop/rspec/example_length_spec.rb
108
111
  - spec/rubocop/cop/rspec/example_wording_spec.rb
109
112
  - spec/rubocop/cop/rspec/file_path_spec.rb
113
+ - spec/rubocop/cop/rspec/focus_spec.rb
110
114
  - spec/rubocop/cop/rspec/instance_variable_spec.rb
111
115
  - spec/rubocop/cop/rspec/multiple_describes_spec.rb
112
116
  - spec/rubocop/cop/rspec/not_to_not_spec.rb
@@ -142,8 +146,10 @@ test_files:
142
146
  - spec/rubocop/cop/rspec/describe_class_spec.rb
143
147
  - spec/rubocop/cop/rspec/describe_method_spec.rb
144
148
  - spec/rubocop/cop/rspec/described_class_spec.rb
149
+ - spec/rubocop/cop/rspec/example_length_spec.rb
145
150
  - spec/rubocop/cop/rspec/example_wording_spec.rb
146
151
  - spec/rubocop/cop/rspec/file_path_spec.rb
152
+ - spec/rubocop/cop/rspec/focus_spec.rb
147
153
  - spec/rubocop/cop/rspec/instance_variable_spec.rb
148
154
  - spec/rubocop/cop/rspec/multiple_describes_spec.rb
149
155
  - spec/rubocop/cop/rspec/not_to_not_spec.rb