rubocop-rspec 1.3.1 → 1.4.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 +16 -3
- data/Gemfile +1 -1
- data/README.md +7 -7
- data/config/default.yml +9 -0
- data/lib/rubocop-rspec.rb +2 -0
- data/lib/rubocop/cop/rspec/any_instance.rb +45 -0
- data/lib/rubocop/cop/rspec/describe_class.rb +2 -1
- data/lib/rubocop/cop/rspec/describe_method.rb +2 -1
- data/lib/rubocop/cop/rspec/described_class.rb +3 -2
- data/lib/rubocop/cop/rspec/example_wording.rb +7 -5
- data/lib/rubocop/cop/rspec/file_path.rb +4 -3
- data/lib/rubocop/cop/rspec/instance_variable.rb +3 -2
- data/lib/rubocop/cop/rspec/multiple_describes.rb +4 -2
- data/lib/rubocop/cop/rspec/not_to_not.rb +54 -0
- data/lib/rubocop/cop/rspec/verified_doubles.rb +2 -1
- data/lib/rubocop/rspec/top_level_describe.rb +1 -1
- data/lib/rubocop/rspec/version.rb +2 -1
- data/rubocop-rspec.gemspec +1 -1
- data/spec/project_spec.rb +1 -1
- data/spec/rubocop/cop/rspec/any_instance_spec.rb +35 -0
- data/spec/rubocop/cop/rspec/not_to_not_spec.rb +41 -0
- data/spec/spec_helper.rb +8 -1
- metadata +13 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e42d16b494c4c455836fe157ffa1c5dd6795b365
|
4
|
+
data.tar.gz: 6c22c6d00b2da712d5ec5cc7cd753455b3c41082
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: df831e003acfe23c307bfc42df8efffbd26034b786d2627a8e7d003c3ea1b2e1d4ba49455ad362ab5bfc7c601551f7b1faf02b51f8b0deef7d29737f2065bb83
|
7
|
+
data.tar.gz: 5d7f687e369bfd5cb7dc426bb466c3bd24c86541c99287a5e4f1d1a7862d14e07861417c73c89fd7d4ed006dad3644f717d72f0348a08a987f37ee54d08579f6
|
data/CHANGELOG.md
CHANGED
@@ -1,17 +1,26 @@
|
|
1
1
|
# Change log
|
2
2
|
|
3
|
-
|
3
|
+
## master (unreleased)
|
4
|
+
|
5
|
+
## 1.4.0 (15/02/2016)
|
6
|
+
|
7
|
+
* Update to rubocop 0.37.2. ([@nijikon][])
|
8
|
+
* Update ruby versions we test against. ([@nijikon][])
|
9
|
+
* Add `RSpec::NotToNot` cop. ([@miguelfteixeira][])
|
10
|
+
* Add `Rspec/AnyInstance` cop. ([@mlarraz][])
|
11
|
+
|
12
|
+
## 1.3.1
|
4
13
|
|
5
14
|
* Fix auto correction issue - syntax had changed in RuboCop v0.31. ([@bquorning][])
|
6
15
|
* Add RuboCop clone to vendor folder - see #39 for details. ([@bquorning][])
|
7
16
|
|
8
|
-
|
17
|
+
## 1.3.0
|
9
18
|
|
10
19
|
* Ignore non string arguments for FilePathCop - thanks to @deivid-rodriguez. ([@geniou][])
|
11
20
|
* Skip DescribeMethod cop for tagged specs. ([@deivid-rodriguez][])
|
12
21
|
* Skip DescribeClass cop for feature/request specs. ([@deivid-rodriguez][])
|
13
22
|
|
14
|
-
|
23
|
+
## 1.2.2
|
15
24
|
|
16
25
|
* Make `RSpec::ExampleWording` case insensitive. ([@geniou][])
|
17
26
|
|
@@ -62,5 +71,9 @@
|
|
62
71
|
[@bquorning]: https://github.com/bquorning
|
63
72
|
[@deivid-rodriguez]: https://github.com/deivid-rodriguez
|
64
73
|
[@geniou]: https://github.com/geniou
|
74
|
+
[@jawshooah]: https://github.com/jawshooah
|
65
75
|
[@nevir]: https://github.com/nevir
|
76
|
+
[@nijikon]: https://github.com/nijikon
|
66
77
|
[@pstengel]: https://github.com/pstengel
|
78
|
+
[@miguelfteixeira]: https://github.com/miguelfteixeira
|
79
|
+
[@mlarraz]: https://github.com/mlarraz
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
# RuboCop RSpec
|
2
2
|
|
3
|
-
[](https://rubygems.org/gems/rubocop-rspec)
|
4
|
+
[](https://gemnasium.com/nevir/rubocop-rspec)
|
5
|
+
[](http://travis-ci.org/nevir/rubocop-rspec)
|
6
|
+
[](https://codeclimate.com/github/nevir/rubocop-rspec/coverage)
|
7
|
+
[](https://codeclimate.com/github/nevir/rubocop-rspec)
|
8
8
|
|
9
9
|
RSpec-specific analysis for your projects, as an extension to
|
10
10
|
[RuboCop](https://github.com/bbatsov/rubocop).
|
@@ -32,7 +32,7 @@ ways to do this:
|
|
32
32
|
|
33
33
|
### RuboCop configuration file
|
34
34
|
|
35
|
-
Put this into
|
35
|
+
Put this into your `.rubocop.yml`.
|
36
36
|
|
37
37
|
```
|
38
38
|
require: rubocop-rspec
|
@@ -85,7 +85,7 @@ This means that in order to run the specs locally, you need a (shallow) clone
|
|
85
85
|
of the RuboCop repository:
|
86
86
|
|
87
87
|
```bash
|
88
|
-
git
|
88
|
+
git submodule update --init --depth 1 vendor/rubocop
|
89
89
|
```
|
90
90
|
|
91
91
|
## License
|
data/config/default.yml
CHANGED
@@ -1,3 +1,7 @@
|
|
1
|
+
RSpec/AnyInstance:
|
2
|
+
Description: 'Check that instances are not being stubbed globally'
|
3
|
+
Enabled: true
|
4
|
+
|
1
5
|
RSpec/DescribeClass:
|
2
6
|
Description: 'Check that the first argument to the top level describe is the tested class or module.'
|
3
7
|
Enabled: true
|
@@ -38,3 +42,8 @@ RSpec/FilePath:
|
|
38
42
|
RSpec/VerifiedDoubles:
|
39
43
|
Description: 'Prefer using verifying doubles over normal doubles.'
|
40
44
|
Enabled: false
|
45
|
+
|
46
|
+
RSpec/NotToNot:
|
47
|
+
Description: 'Enforces the usage of the same method on all negative message expectations.'
|
48
|
+
Enabled: true
|
49
|
+
AcceptedMethod: 'not_to'
|
data/lib/rubocop-rspec.rb
CHANGED
@@ -9,6 +9,7 @@ require 'rubocop/rspec/top_level_describe'
|
|
9
9
|
RuboCop::RSpec::Inject.defaults!
|
10
10
|
|
11
11
|
# cops
|
12
|
+
require 'rubocop/cop/rspec/any_instance'
|
12
13
|
require 'rubocop/cop/rspec/describe_class'
|
13
14
|
require 'rubocop/cop/rspec/describe_method'
|
14
15
|
require 'rubocop/cop/rspec/described_class'
|
@@ -16,4 +17,5 @@ require 'rubocop/cop/rspec/example_wording'
|
|
16
17
|
require 'rubocop/cop/rspec/file_path'
|
17
18
|
require 'rubocop/cop/rspec/instance_variable'
|
18
19
|
require 'rubocop/cop/rspec/multiple_describes'
|
20
|
+
require 'rubocop/cop/rspec/not_to_not'
|
19
21
|
require 'rubocop/cop/rspec/verified_doubles'
|
@@ -0,0 +1,45 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Cop
|
5
|
+
module RSpec
|
6
|
+
# Pefer instance doubles over stubbing any instance of a class
|
7
|
+
#
|
8
|
+
# @example
|
9
|
+
# # bad
|
10
|
+
# describe MyClass do
|
11
|
+
# before { allow_any_instance_of(MyClass).to receive(:foo) }
|
12
|
+
# end
|
13
|
+
#
|
14
|
+
# # good
|
15
|
+
# describe MyClass do
|
16
|
+
# let(:my_instance) { instance_double(MyClass) }
|
17
|
+
#
|
18
|
+
# before do
|
19
|
+
# allow(MyClass).to receive(:new).and_return(my_instance)
|
20
|
+
# allow(my_instance).to receive(:foo)
|
21
|
+
# end
|
22
|
+
# end
|
23
|
+
class AnyInstance < Cop
|
24
|
+
MESSAGE = 'Avoid stubbing using `%{method}`'.freeze
|
25
|
+
|
26
|
+
ANY_INSTANCE_METHODS = [
|
27
|
+
:any_instance,
|
28
|
+
:allow_any_instance_of,
|
29
|
+
:expect_any_instance_of
|
30
|
+
].freeze
|
31
|
+
|
32
|
+
def on_send(node)
|
33
|
+
_receiver, method_name, *_args = *node
|
34
|
+
return unless ANY_INSTANCE_METHODS.include?(method_name)
|
35
|
+
|
36
|
+
add_offense(node, :expression,
|
37
|
+
format(MESSAGE % { method: method_name },
|
38
|
+
node.loc.expression.source
|
39
|
+
)
|
40
|
+
)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -1,4 +1,5 @@
|
|
1
1
|
# encoding: utf-8
|
2
|
+
# frozen_string_literal: true
|
2
3
|
|
3
4
|
module RuboCop
|
4
5
|
module Cop
|
@@ -24,7 +25,7 @@ module RuboCop
|
|
24
25
|
FEATURE_PAIR = s(:pair, s(:sym, :type), s(:sym, :feature))
|
25
26
|
|
26
27
|
MESSAGE = 'The first argument to describe should be the class or ' \
|
27
|
-
'module being tested.'
|
28
|
+
'module being tested.'.freeze
|
28
29
|
|
29
30
|
def on_top_level_describe(_node, args)
|
30
31
|
return if args[0] && args[0].type == :const
|
@@ -1,4 +1,5 @@
|
|
1
1
|
# encoding: utf-8
|
2
|
+
# frozen_string_literal: true
|
2
3
|
|
3
4
|
module RuboCop
|
4
5
|
module Cop
|
@@ -21,7 +22,7 @@ module RuboCop
|
|
21
22
|
include RuboCop::RSpec::TopLevelDescribe
|
22
23
|
|
23
24
|
MESSAGE = 'The second argument to describe should be the method ' \
|
24
|
-
"being tested. '#instance' or '.class'"
|
25
|
+
"being tested. '#instance' or '.class'".freeze
|
25
26
|
METHOD_STRING_MATCHER = /^[\#\.].+/
|
26
27
|
|
27
28
|
def on_top_level_describe(_node, args)
|
@@ -1,4 +1,5 @@
|
|
1
1
|
# encoding: utf-8
|
2
|
+
# frozen_string_literal: true
|
2
3
|
|
3
4
|
module RuboCop
|
4
5
|
module Cop
|
@@ -20,7 +21,7 @@ module RuboCop
|
|
20
21
|
class DescribedClass < Cop
|
21
22
|
include RuboCop::RSpec::TopLevelDescribe
|
22
23
|
|
23
|
-
MESSAGE = 'Use `described_class` instead of `%s`'
|
24
|
+
MESSAGE = 'Use `described_class` instead of `%s`'.freeze
|
24
25
|
|
25
26
|
def on_block(node)
|
26
27
|
method, _args, body = *node
|
@@ -47,7 +48,7 @@ module RuboCop
|
|
47
48
|
|
48
49
|
node.children.each do |child|
|
49
50
|
if child == object
|
50
|
-
name =
|
51
|
+
name = object.loc.expression.source
|
51
52
|
add_offense(child, :expression, format(MESSAGE, name))
|
52
53
|
break
|
53
54
|
end
|
@@ -1,4 +1,5 @@
|
|
1
1
|
# encoding: utf-8
|
2
|
+
# frozen_string_literal: true
|
2
3
|
|
3
4
|
module RuboCop
|
4
5
|
module Cop
|
@@ -18,21 +19,22 @@ module RuboCop
|
|
18
19
|
# it 'finds nothing' do
|
19
20
|
# end
|
20
21
|
class ExampleWording < Cop
|
21
|
-
MSG = 'Do not use should when describing your tests.'
|
22
|
+
MSG = 'Do not use should when describing your tests.'.freeze
|
22
23
|
|
23
|
-
def on_block(node) # rubocop:disable Metrics/AbcSize
|
24
|
+
def on_block(node) # rubocop:disable Metrics/AbcSize,Metrics/MethodLength,Metrics/LineLength
|
24
25
|
method, = *node
|
25
26
|
_, method_name, *args = *method
|
26
27
|
|
27
28
|
return unless method_name == :it
|
28
29
|
|
29
|
-
arguments = *
|
30
|
+
arguments = *args.first
|
30
31
|
message = arguments.first.to_s
|
31
32
|
return unless message.downcase.start_with?('should')
|
32
33
|
|
33
34
|
arg1 = args.first.loc.expression
|
34
|
-
message = Parser::Source::Range
|
35
|
-
|
35
|
+
message = Parser::Source::Range.new(arg1.source_buffer,
|
36
|
+
arg1.begin_pos + 1,
|
37
|
+
arg1.end_pos - 1)
|
36
38
|
|
37
39
|
add_offense(message, message, MSG)
|
38
40
|
end
|
@@ -1,4 +1,5 @@
|
|
1
1
|
# encoding: utf-8
|
2
|
+
# frozen_string_literal: true
|
2
3
|
|
3
4
|
module RuboCop
|
4
5
|
module Cop
|
@@ -17,12 +18,12 @@ module RuboCop
|
|
17
18
|
class FilePath < Cop
|
18
19
|
include RuboCop::RSpec::TopLevelDescribe
|
19
20
|
|
20
|
-
MESSAGE = 'Spec path should end with `%s`'
|
21
|
+
MESSAGE = 'Spec path should end with `%s`'.freeze
|
21
22
|
METHOD_STRING_MATCHER = /^[\#\.].+/
|
22
23
|
|
23
24
|
def on_top_level_describe(node, args)
|
24
25
|
return unless single_top_level_describe?
|
25
|
-
object =
|
26
|
+
object = args.first.const_name
|
26
27
|
return unless object
|
27
28
|
|
28
29
|
path_matcher = matcher(object, args[1])
|
@@ -54,7 +55,7 @@ module RuboCop
|
|
54
55
|
|
55
56
|
def camel_to_underscore(string)
|
56
57
|
string.dup.tap do |result|
|
57
|
-
result.gsub!(/([^A-Z])([A-Z]+)/,
|
58
|
+
result.gsub!(/([^A-Z])([A-Z]+)/, '\\1_\\2')
|
58
59
|
result.gsub!(/([A-Z])([A-Z][^A-Z]+)/, '\\1_\\2')
|
59
60
|
result.downcase!
|
60
61
|
end
|
@@ -1,4 +1,5 @@
|
|
1
1
|
# encoding: utf-8
|
2
|
+
# frozen_string_literal: true
|
2
3
|
|
3
4
|
module RuboCop
|
4
5
|
module Cop
|
@@ -19,12 +20,12 @@ module RuboCop
|
|
19
20
|
# it { expect(foo).to be_empty }
|
20
21
|
# end
|
21
22
|
class InstanceVariable < Cop
|
22
|
-
MESSAGE = 'Use `let` instead of an instance variable'
|
23
|
+
MESSAGE = 'Use `let` instead of an instance variable'.freeze
|
23
24
|
EXAMPLE_GROUP_METHODS = [
|
24
25
|
:example_group, :describe, :context, :xdescribe, :xcontext,
|
25
26
|
:fdescribe, :fcontext, :shared_examples, :shared_context,
|
26
27
|
:share_examples_for, :shared_examples_for, :feature
|
27
|
-
]
|
28
|
+
].freeze
|
28
29
|
|
29
30
|
def on_block(node)
|
30
31
|
method, _args, _body = *node
|
@@ -1,4 +1,5 @@
|
|
1
1
|
# encoding: utf-8
|
2
|
+
# frozen_string_literal: true
|
2
3
|
|
3
4
|
module RuboCop
|
4
5
|
module Cop
|
@@ -23,13 +24,14 @@ module RuboCop
|
|
23
24
|
class MultipleDescribes < Cop
|
24
25
|
include RuboCop::RSpec::TopLevelDescribe
|
25
26
|
|
26
|
-
|
27
|
+
MSG = 'Do not use multiple top level describes - ' \
|
28
|
+
'try to nest them.'.freeze
|
27
29
|
|
28
30
|
def on_top_level_describe(node, _args)
|
29
31
|
return if single_top_level_describe?
|
30
32
|
return unless top_level_nodes.first == node
|
31
33
|
|
32
|
-
add_offense(node, :expression,
|
34
|
+
add_offense(node, :expression, MSG)
|
33
35
|
end
|
34
36
|
end
|
35
37
|
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Cop
|
5
|
+
module RSpec
|
6
|
+
# Enforces the usage of the same method on all negative message
|
7
|
+
# expectations.
|
8
|
+
#
|
9
|
+
# @example
|
10
|
+
# # bad
|
11
|
+
# it '...' do
|
12
|
+
# expect(false).to_not be_true
|
13
|
+
# end
|
14
|
+
#
|
15
|
+
# # good
|
16
|
+
# it '...' do
|
17
|
+
# expect(false).not_to be_true
|
18
|
+
# end
|
19
|
+
class NotToNot < Cop
|
20
|
+
ACCEPTED_METHODS = [:not_to, :to_not].freeze
|
21
|
+
|
22
|
+
def on_send(node)
|
23
|
+
_receiver, method_name, *_args = *node
|
24
|
+
|
25
|
+
if method_name == rejected_method
|
26
|
+
add_offense(node, :expression, offense_message)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def accepted_method
|
33
|
+
@accepted_method ||= begin
|
34
|
+
method = cop_config['AcceptedMethod'].to_sym
|
35
|
+
|
36
|
+
unless ACCEPTED_METHODS.include?(method)
|
37
|
+
raise "Invalid AcceptedMethod value: #{method}"
|
38
|
+
end
|
39
|
+
|
40
|
+
method
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def rejected_method
|
45
|
+
@rejected_method ||= (ACCEPTED_METHODS - [accepted_method]).first
|
46
|
+
end
|
47
|
+
|
48
|
+
def offense_message
|
49
|
+
"Use `#{accepted_method}` instead of `#{rejected_method}`"
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -1,4 +1,5 @@
|
|
1
1
|
# encoding: utf-8
|
2
|
+
# frozen_string_literal: true
|
2
3
|
|
3
4
|
module RuboCop
|
4
5
|
module Cop
|
@@ -17,7 +18,7 @@ module RuboCop
|
|
17
18
|
# widget = instance_double("Widget")
|
18
19
|
# end
|
19
20
|
class VerifiedDoubles < Cop
|
20
|
-
MSG = 'Prefer using verifying doubles over normal doubles.'
|
21
|
+
MSG = 'Prefer using verifying doubles over normal doubles.'.freeze
|
21
22
|
|
22
23
|
def on_send(node)
|
23
24
|
_receiver, method_name, *_args = *node
|
@@ -26,7 +26,7 @@ module RuboCop
|
|
26
26
|
nodes = describe_statement_children(root_node)
|
27
27
|
# If we have no top level describe statements, we need to check any
|
28
28
|
# blocks on the top level (e.g. after a require).
|
29
|
-
if nodes.
|
29
|
+
if nodes.empty?
|
30
30
|
nodes = node_children(root_node).map do |child|
|
31
31
|
describe_statement_children(child) if child.type == :block
|
32
32
|
end.flatten.compact
|
data/rubocop-rspec.gemspec
CHANGED
@@ -30,7 +30,7 @@ Gem::Specification.new do |spec|
|
|
30
30
|
spec.test_files = spec.files.grep(%r{^spec/})
|
31
31
|
spec.extra_rdoc_files = ['MIT-LICENSE.md', 'README.md']
|
32
32
|
|
33
|
-
spec.add_development_dependency('rubocop', '
|
33
|
+
spec.add_development_dependency('rubocop', '0.37.2')
|
34
34
|
spec.add_development_dependency('rake', '~> 10.1')
|
35
35
|
spec.add_development_dependency('rspec', '~> 3.0')
|
36
36
|
spec.add_development_dependency('simplecov', '~> 0.8')
|
data/spec/project_spec.rb
CHANGED
@@ -18,7 +18,7 @@ describe 'RuboCop Project' do # rubocop:disable RSpec/DescribeClass
|
|
18
18
|
end
|
19
19
|
|
20
20
|
it 'has configuration for all cops' do
|
21
|
-
expect(default_config.keys.sort).to eq(
|
21
|
+
expect(default_config.keys.sort).to eq(cop_names.sort)
|
22
22
|
end
|
23
23
|
|
24
24
|
it 'has a nicely formatted description for all cops' do
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
describe RuboCop::Cop::RSpec::AnyInstance do
|
4
|
+
subject(:cop) { described_class.new }
|
5
|
+
|
6
|
+
it 'finds `allow_any_instance_of` instead of an instance double' do
|
7
|
+
inspect_source(cop, ['before do',
|
8
|
+
' allow_any_instance_of(Object).to receive(:foo)',
|
9
|
+
'end'])
|
10
|
+
expect(cop.messages)
|
11
|
+
.to eq(['Avoid stubbing using `allow_any_instance_of`'])
|
12
|
+
expect(cop.highlights).to eq(['allow_any_instance_of(Object)'])
|
13
|
+
expect(cop.offenses.map(&:line).sort).to eq([2])
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'finds `expect_any_instance_of` instead of an instance double' do
|
17
|
+
inspect_source(cop, ['before do',
|
18
|
+
' expect_any_instance_of(Object).to receive(:foo)',
|
19
|
+
'end'])
|
20
|
+
expect(cop.messages)
|
21
|
+
.to eq(['Avoid stubbing using `expect_any_instance_of`'])
|
22
|
+
expect(cop.highlights).to eq(['expect_any_instance_of(Object)'])
|
23
|
+
expect(cop.offenses.map(&:line).sort).to eq([2])
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'finds old `any_instance` syntax instead of an instance double' do
|
27
|
+
inspect_source(cop, ['before do',
|
28
|
+
' Object.any_instance.should_receive(:foo)',
|
29
|
+
'end'])
|
30
|
+
expect(cop.messages)
|
31
|
+
.to eq(['Avoid stubbing using `any_instance`'])
|
32
|
+
expect(cop.highlights).to eq(['Object.any_instance'])
|
33
|
+
expect(cop.offenses.map(&:line).sort).to eq([2])
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
describe RuboCop::Cop::RSpec::NotToNot, :config do
|
4
|
+
subject(:cop) { described_class.new(config) }
|
5
|
+
|
6
|
+
context 'when AcceptedMethod is `not_to`' do
|
7
|
+
let(:cop_config) { { 'AcceptedMethod' => 'not_to' } }
|
8
|
+
|
9
|
+
it 'detects the `to_not` offense' do
|
10
|
+
inspect_source(subject, 'it { expect(false).to_not be_true }')
|
11
|
+
|
12
|
+
expect(subject.messages).to eq(['Use `not_to` instead of `to_not`'])
|
13
|
+
expect(subject.highlights).to eq(['expect(false).to_not be_true'])
|
14
|
+
expect(subject.offenses.map(&:line).sort).to eq([1])
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'detects no offense when using `not_to`' do
|
18
|
+
inspect_source(subject, 'it { expect(false).not_to be_true }')
|
19
|
+
|
20
|
+
expect(subject.messages).to be_empty
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
context 'when AcceptedMethod is `to_not`' do
|
25
|
+
let(:cop_config) { { 'AcceptedMethod' => 'to_not' } }
|
26
|
+
|
27
|
+
it 'detects the `not_to` offense' do
|
28
|
+
inspect_source(subject, 'it { expect(false).not_to be_true }')
|
29
|
+
|
30
|
+
expect(subject.messages).to eq(['Use `to_not` instead of `not_to`'])
|
31
|
+
expect(subject.highlights).to eq(['expect(false).not_to be_true'])
|
32
|
+
expect(subject.offenses.map(&:line).sort).to eq([1])
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'detects no offense when using `to_not`' do
|
36
|
+
inspect_source(subject, 'it { expect(false).to_not be_true }')
|
37
|
+
|
38
|
+
expect(subject.messages).to be_empty
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -3,11 +3,18 @@
|
|
3
3
|
require 'rubocop'
|
4
4
|
|
5
5
|
rubocop_path = File.join(File.dirname(__FILE__), '../vendor/rubocop')
|
6
|
+
|
6
7
|
unless File.directory?(rubocop_path)
|
7
|
-
|
8
|
+
raise "Can't run specs without a local RuboCop checkout. Look in the README."
|
8
9
|
end
|
10
|
+
|
9
11
|
Dir["#{rubocop_path}/spec/support/**/*.rb"].each { |f| require f }
|
10
12
|
|
13
|
+
if ENV['CI']
|
14
|
+
require 'codeclimate-test-reporter'
|
15
|
+
CodeClimate::TestReporter.start
|
16
|
+
end
|
17
|
+
|
11
18
|
RSpec.configure do |config|
|
12
19
|
config.order = :random
|
13
20
|
|
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
|
+
version: 1.4.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:
|
12
|
+
date: 2016-02-15 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:
|
20
|
+
version: 0.37.2
|
21
21
|
type: :development
|
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:
|
27
|
+
version: 0.37.2
|
28
28
|
- !ruby/object:Gem::Dependency
|
29
29
|
name: rake
|
30
30
|
requirement: !ruby/object:Gem::Requirement
|
@@ -86,6 +86,7 @@ files:
|
|
86
86
|
- Rakefile
|
87
87
|
- config/default.yml
|
88
88
|
- lib/rubocop-rspec.rb
|
89
|
+
- lib/rubocop/cop/rspec/any_instance.rb
|
89
90
|
- lib/rubocop/cop/rspec/describe_class.rb
|
90
91
|
- lib/rubocop/cop/rspec/describe_method.rb
|
91
92
|
- lib/rubocop/cop/rspec/described_class.rb
|
@@ -93,12 +94,14 @@ files:
|
|
93
94
|
- lib/rubocop/cop/rspec/file_path.rb
|
94
95
|
- lib/rubocop/cop/rspec/instance_variable.rb
|
95
96
|
- lib/rubocop/cop/rspec/multiple_describes.rb
|
97
|
+
- lib/rubocop/cop/rspec/not_to_not.rb
|
96
98
|
- lib/rubocop/cop/rspec/verified_doubles.rb
|
97
99
|
- lib/rubocop/rspec/inject.rb
|
98
100
|
- lib/rubocop/rspec/top_level_describe.rb
|
99
101
|
- lib/rubocop/rspec/version.rb
|
100
102
|
- rubocop-rspec.gemspec
|
101
103
|
- spec/project_spec.rb
|
104
|
+
- spec/rubocop/cop/rspec/any_instance_spec.rb
|
102
105
|
- spec/rubocop/cop/rspec/describe_class_spec.rb
|
103
106
|
- spec/rubocop/cop/rspec/describe_method_spec.rb
|
104
107
|
- spec/rubocop/cop/rspec/described_class_spec.rb
|
@@ -106,6 +109,7 @@ files:
|
|
106
109
|
- spec/rubocop/cop/rspec/file_path_spec.rb
|
107
110
|
- spec/rubocop/cop/rspec/instance_variable_spec.rb
|
108
111
|
- spec/rubocop/cop/rspec/multiple_describes_spec.rb
|
112
|
+
- spec/rubocop/cop/rspec/not_to_not_spec.rb
|
109
113
|
- spec/rubocop/cop/rspec/verified_doubles_spec.rb
|
110
114
|
- spec/spec_helper.rb
|
111
115
|
homepage: http://github.com/nevir/rubocop-rspec
|
@@ -128,12 +132,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
128
132
|
version: '0'
|
129
133
|
requirements: []
|
130
134
|
rubyforge_project:
|
131
|
-
rubygems_version: 2.
|
135
|
+
rubygems_version: 2.5.1
|
132
136
|
signing_key:
|
133
137
|
specification_version: 4
|
134
138
|
summary: Code style checking for RSpec files
|
135
139
|
test_files:
|
136
140
|
- spec/project_spec.rb
|
141
|
+
- spec/rubocop/cop/rspec/any_instance_spec.rb
|
137
142
|
- spec/rubocop/cop/rspec/describe_class_spec.rb
|
138
143
|
- spec/rubocop/cop/rspec/describe_method_spec.rb
|
139
144
|
- spec/rubocop/cop/rspec/described_class_spec.rb
|
@@ -141,6 +146,6 @@ test_files:
|
|
141
146
|
- spec/rubocop/cop/rspec/file_path_spec.rb
|
142
147
|
- spec/rubocop/cop/rspec/instance_variable_spec.rb
|
143
148
|
- spec/rubocop/cop/rspec/multiple_describes_spec.rb
|
149
|
+
- spec/rubocop/cop/rspec/not_to_not_spec.rb
|
144
150
|
- spec/rubocop/cop/rspec/verified_doubles_spec.rb
|
145
151
|
- spec/spec_helper.rb
|
146
|
-
has_rdoc:
|