rubocop-rspec 1.7.0 → 1.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +7 -0
- data/README.md +5 -4
- data/Rakefile +1 -4
- data/config/default.yml +63 -54
- data/lib/rubocop-rspec.rb +1 -0
- data/lib/rubocop/cop/rspec/be_eql.rb +4 -2
- data/lib/rubocop/cop/rspec/file_path.rb +33 -5
- data/lib/rubocop/cop/rspec/implicit_expect.rb +102 -0
- data/lib/rubocop/rspec/version.rb +1 -1
- data/rubocop-rspec.gemspec +8 -4
- data/spec/project/default_config_spec.rb +2 -2
- data/spec/rubocop/cop/rspec/be_eql_spec.rb +10 -9
- data/spec/rubocop/cop/rspec/described_class_spec.rb +11 -21
- data/spec/rubocop/cop/rspec/example_wording_spec.rb +9 -30
- data/spec/rubocop/cop/rspec/file_path_spec.rb +16 -3
- data/spec/rubocop/cop/rspec/hook_argument_spec.rb +6 -32
- data/spec/rubocop/cop/rspec/implicit_expect_spec.rb +101 -0
- data/spec/rubocop/cop/rspec/nested_groups_spec.rb +1 -1
- data/spec/rubocop/cop/rspec/not_to_not_spec.rb +6 -18
- data/spec/shared/autocorrect_behavior.rb +7 -0
- data/spec/shared/detects_style_behavior.rb +8 -0
- metadata +13 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6bfc346a6e12eab244a17f9fc8401bfb1c4c8d86
|
4
|
+
data.tar.gz: f0b9285af75fab2774940505d868ef097936d8ec
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ed95fbfc52c82a0f4c7674a675e805ca1649c8088734fc19c31d73c70eb2c15cee292d36579184ff2f61beb13492543d9cac5b19abb3190de23ebbfc168dd0a1
|
7
|
+
data.tar.gz: b225fca79ccc76547a283c140b2e5add1430c13dcb5bd3db74a0b68d7fa7a4546be8aa5d1ad9e67387969f9c72bd3ce8702e6255d7a048e542a9ff975ddfa596
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,13 @@
|
|
2
2
|
|
3
3
|
## Master (unreleased)
|
4
4
|
|
5
|
+
## 1.8.0 (2016-10-27)
|
6
|
+
|
7
|
+
* Optionally ignore method names in the `describe` argument when running the `FilePath` cop. ([@bquorning][])
|
8
|
+
* Fix regression in how `FilePath` converts alphanumeric class names into paths. ([@bquorning][])
|
9
|
+
* Add `ImplicitExpect` cop for enforcing `should` vs. `is_expected.to`. ([@backus][])
|
10
|
+
* Disable `MessageExpectation` cop in the default configuration. ([@bquorning][])
|
11
|
+
|
5
12
|
## 1.7.0 (2016-08-24)
|
6
13
|
|
7
14
|
* Add support for checking all example groups with `ExampleLength`. ([@backus][])
|
data/README.md
CHANGED
@@ -1,10 +1,11 @@
|
|
1
1
|
# RuboCop RSpec
|
2
2
|
|
3
|
+
[![Join the chat at https://gitter.im/rubocop-rspec/Lobby](https://badges.gitter.im/rubocop-rspec/Lobby.svg)](https://gitter.im/rubocop-rspec/Lobby)
|
3
4
|
[![Gem Version](https://badge.fury.io/rb/rubocop-rspec.svg)](https://rubygems.org/gems/rubocop-rspec)
|
4
|
-
[![Dependency Status](https://gemnasium.com/
|
5
|
-
[![Build Status](https://secure.travis-ci.org/
|
6
|
-
[![Coverage Status](https://codeclimate.com/github/
|
7
|
-
[![Code Climate](https://codeclimate.com/github/
|
5
|
+
[![Dependency Status](https://gemnasium.com/backus/rubocop-rspec.svg)](https://gemnasium.com/backus/rubocop-rspec)
|
6
|
+
[![Build Status](https://secure.travis-ci.org/backus/rubocop-rspec.svg?branch=master)](http://travis-ci.org/backus/rubocop-rspec)
|
7
|
+
[![Coverage Status](https://codeclimate.com/github/backus/rubocop-rspec/badges/coverage.svg)](https://codeclimate.com/github/backus/rubocop-rspec/coverage)
|
8
|
+
[![Code Climate](https://codeclimate.com/github/backus/rubocop-rspec/badges/gpa.svg)](https://codeclimate.com/github/backus/rubocop-rspec)
|
8
9
|
|
9
10
|
RSpec-specific analysis for your projects, as an extension to
|
10
11
|
[RuboCop](https://github.com/bbatsov/rubocop).
|
data/Rakefile
CHANGED
@@ -24,10 +24,7 @@ end
|
|
24
24
|
|
25
25
|
desc 'Run RuboCop over this gem'
|
26
26
|
task :internal_investigation do
|
27
|
-
require
|
28
|
-
|
29
|
-
result = RuboCop::CLI.new.run
|
30
|
-
abort('RuboCop failed!') unless result.zero?
|
27
|
+
sh('bundle exec rubocop --require rubocop-rspec')
|
31
28
|
end
|
32
29
|
|
33
30
|
desc 'Build config/default.yml'
|
data/config/default.yml
CHANGED
@@ -13,15 +13,6 @@ RSpec/BeEql:
|
|
13
13
|
Description: Check for expectations where `be(...)` can replace `eql(...)`.
|
14
14
|
Enabled: true
|
15
15
|
|
16
|
-
RSpec/HookArgument:
|
17
|
-
Description: Checks the arguments passed to `before`, `around`, and `after`.
|
18
|
-
Enabled: true
|
19
|
-
EnforcedStyle: implicit
|
20
|
-
SupportedStyles:
|
21
|
-
- implicit
|
22
|
-
- each
|
23
|
-
- example
|
24
|
-
|
25
16
|
RSpec/DescribeClass:
|
26
17
|
Description: Check that the first argument to the top level describe is a constant.
|
27
18
|
Enabled: true
|
@@ -35,6 +26,16 @@ RSpec/DescribeMethod:
|
|
35
26
|
Description: Checks that the second argument to `describe` specifies a method.
|
36
27
|
Enabled: true
|
37
28
|
|
29
|
+
RSpec/EmptyExampleGroup:
|
30
|
+
Description: Checks if an example group does not include any tests.
|
31
|
+
Enabled: true
|
32
|
+
CustomIncludeMethods: []
|
33
|
+
|
34
|
+
RSpec/ExampleLength:
|
35
|
+
Description: Checks for long examples.
|
36
|
+
Enabled: true
|
37
|
+
Max: 5
|
38
|
+
|
38
39
|
RSpec/ExampleWording:
|
39
40
|
Description: Checks that example descriptions do not start with "should".
|
40
41
|
Enabled: true
|
@@ -44,87 +45,95 @@ RSpec/ExampleWording:
|
|
44
45
|
not: does not
|
45
46
|
IgnoredWords: []
|
46
47
|
|
47
|
-
RSpec/EmptyExampleGroup:
|
48
|
-
Description: Checks if an example group does not include any tests.
|
49
|
-
Enabled: true
|
50
|
-
CustomIncludeMethods: []
|
51
|
-
|
52
48
|
RSpec/ExpectActual:
|
53
49
|
Description: Checks for `expect(...)` calls containing literal values.
|
54
50
|
Enabled: true
|
55
51
|
|
56
|
-
RSpec/
|
57
|
-
Description:
|
52
|
+
RSpec/FilePath:
|
53
|
+
Description: Checks that spec file paths are consistent with the test subject.
|
58
54
|
Enabled: true
|
55
|
+
CustomTransform:
|
56
|
+
RuboCop: rubocop
|
57
|
+
RSpec: rspec
|
58
|
+
IgnoreMethods: false
|
59
59
|
|
60
|
-
RSpec/
|
61
|
-
Description: Checks
|
60
|
+
RSpec/Focus:
|
61
|
+
Description: Checks if examples are focused.
|
62
62
|
Enabled: true
|
63
63
|
|
64
|
-
RSpec/
|
65
|
-
Description: Checks
|
64
|
+
RSpec/HookArgument:
|
65
|
+
Description: Checks the arguments passed to `before`, `around`, and `after`.
|
66
66
|
Enabled: true
|
67
|
-
|
67
|
+
EnforcedStyle: implicit
|
68
|
+
SupportedStyles:
|
69
|
+
- implicit
|
70
|
+
- each
|
71
|
+
- example
|
68
72
|
|
69
|
-
RSpec/
|
70
|
-
Description:
|
73
|
+
RSpec/ImplicitExpect:
|
74
|
+
Description: Check that a consistent implicit expectation style is used.
|
71
75
|
Enabled: true
|
72
|
-
|
76
|
+
EnforcedStyle: is_expected
|
77
|
+
SupportedStyles:
|
78
|
+
- is_expected
|
79
|
+
- should
|
73
80
|
|
74
81
|
RSpec/InstanceVariable:
|
75
82
|
Description: Checks for instance variable usage in specs.
|
76
83
|
AssignmentOnly: false
|
77
84
|
Enabled: true
|
78
85
|
|
79
|
-
RSpec/LetSetup:
|
80
|
-
Description: Checks unreferenced `let!` calls being used for test setup.
|
81
|
-
Enabled: true
|
82
|
-
|
83
86
|
RSpec/LeadingSubject:
|
84
87
|
Description: Checks for `subject` definitions that come after `let` definitions.
|
85
88
|
Enabled: true
|
86
89
|
|
87
|
-
RSpec/
|
88
|
-
Description: Checks
|
89
|
-
Enabled: true
|
90
|
-
CustomTransform:
|
91
|
-
RuboCop: rubocop
|
92
|
-
RSpec: rspec
|
93
|
-
|
94
|
-
RSpec/VerifiedDoubles:
|
95
|
-
Description: Prefer using verifying doubles over normal doubles.
|
96
|
-
Enabled: true
|
97
|
-
IgnoreSymbolicNames: false
|
98
|
-
|
99
|
-
RSpec/NotToNot:
|
100
|
-
Description: Checks for consistent method usage for negating expectations.
|
101
|
-
EnforcedStyle: not_to
|
102
|
-
SupportedStyles:
|
103
|
-
- not_to
|
104
|
-
- to_not
|
105
|
-
Enabled: true
|
106
|
-
|
107
|
-
RSpec/Focus:
|
108
|
-
Description: Checks if examples are focused.
|
90
|
+
RSpec/LetSetup:
|
91
|
+
Description: Checks unreferenced `let!` calls being used for test setup.
|
109
92
|
Enabled: true
|
110
93
|
|
111
|
-
RSpec/
|
112
|
-
Description:
|
94
|
+
RSpec/MessageChain:
|
95
|
+
Description: Check that chains of messages are not being stubbed.
|
113
96
|
Enabled: true
|
114
|
-
Max: 5
|
115
97
|
|
116
98
|
RSpec/MessageExpectation:
|
117
99
|
Description: Checks for consistent message expectation style.
|
118
|
-
Enabled:
|
100
|
+
Enabled: false
|
119
101
|
EnforcedStyle: allow
|
120
102
|
SupportedStyles:
|
121
103
|
- allow
|
122
104
|
- expect
|
123
105
|
|
106
|
+
RSpec/MultipleDescribes:
|
107
|
+
Description: Checks for multiple top level describes.
|
108
|
+
Enabled: true
|
109
|
+
|
110
|
+
RSpec/MultipleExpectations:
|
111
|
+
Description: Checks if examples contain too many `expect` calls.
|
112
|
+
Enabled: true
|
113
|
+
Max: 1
|
114
|
+
|
124
115
|
RSpec/NamedSubject:
|
125
116
|
Description: Checks for explicitly referenced test subjects.
|
126
117
|
Enabled: true
|
127
118
|
|
119
|
+
RSpec/NestedGroups:
|
120
|
+
Description: Checks for nested example groups.
|
121
|
+
Enabled: true
|
122
|
+
MaxNesting: 2
|
123
|
+
|
124
|
+
RSpec/NotToNot:
|
125
|
+
Description: Checks for consistent method usage for negating expectations.
|
126
|
+
EnforcedStyle: not_to
|
127
|
+
SupportedStyles:
|
128
|
+
- not_to
|
129
|
+
- to_not
|
130
|
+
Enabled: true
|
131
|
+
|
128
132
|
RSpec/SubjectStub:
|
129
133
|
Description: Checks for stubbed test subjects.
|
130
134
|
Enabled: true
|
135
|
+
|
136
|
+
RSpec/VerifiedDoubles:
|
137
|
+
Description: Prefer using verifying doubles over normal doubles.
|
138
|
+
Enabled: true
|
139
|
+
IgnoreSymbolicNames: false
|
data/lib/rubocop-rspec.rb
CHANGED
@@ -28,6 +28,7 @@ require 'rubocop/cop/rspec/expect_actual'
|
|
28
28
|
require 'rubocop/cop/rspec/file_path'
|
29
29
|
require 'rubocop/cop/rspec/focus'
|
30
30
|
require 'rubocop/cop/rspec/hook_argument'
|
31
|
+
require 'rubocop/cop/rspec/implicit_expect'
|
31
32
|
require 'rubocop/cop/rspec/instance_variable'
|
32
33
|
require 'rubocop/cop/rspec/leading_subject'
|
33
34
|
require 'rubocop/cop/rspec/let_setup'
|
@@ -4,7 +4,7 @@ module RuboCop
|
|
4
4
|
# Check for expectations where `be(...)` can replace `eql(...)`.
|
5
5
|
#
|
6
6
|
# The `be` matcher compares by identity while the `eql` matcher
|
7
|
-
# compares using `eql?`. Integers, floats, booleans, and
|
7
|
+
# compares using `eql?`. Integers, floats, booleans, symbols, and nil
|
8
8
|
# can be compared by identity and therefore the `be` matcher is
|
9
9
|
# preferable as it is a more strict test.
|
10
10
|
#
|
@@ -16,6 +16,7 @@ module RuboCop
|
|
16
16
|
# expect(foo).to eql(true)
|
17
17
|
# expect(foo).to eql(false)
|
18
18
|
# expect(foo).to eql(:bar)
|
19
|
+
# expect(foo).to eql(nil)
|
19
20
|
#
|
20
21
|
# # good
|
21
22
|
# expect(foo).to be(1)
|
@@ -23,6 +24,7 @@ module RuboCop
|
|
23
24
|
# expect(foo).to be(true)
|
24
25
|
# expect(foo).to be(false)
|
25
26
|
# expect(foo).to be(:bar)
|
27
|
+
# expect(foo).to be(nil)
|
26
28
|
#
|
27
29
|
# This cop only looks for instances of `expect(...).to eql(...)`. We
|
28
30
|
# do not check `to_not` or `not_to` since `!eql?` is more strict
|
@@ -38,7 +40,7 @@ module RuboCop
|
|
38
40
|
MSG = 'Prefer `be` over `eql`'.freeze
|
39
41
|
|
40
42
|
def_node_matcher :eql_type_with_identity, <<-PATTERN
|
41
|
-
(send _ :to $(send nil :eql {true false int float sym}))
|
43
|
+
(send _ :to $(send nil :eql {true false int float sym nil_type?}))
|
42
44
|
PATTERN
|
43
45
|
|
44
46
|
def on_send(node)
|
@@ -8,19 +8,43 @@ module RuboCop
|
|
8
8
|
# Checks the path of the spec file and enforces that it reflects the
|
9
9
|
# described class/module and its optionally called out method.
|
10
10
|
#
|
11
|
+
# With the configuration option `IgnoreMethods` the called out method will
|
12
|
+
# be ignored when determining the enforced path.
|
13
|
+
#
|
11
14
|
# With the configuration option `CustomTransform` modules or classes can
|
12
15
|
# be specified that should not as usual be transformed from CamelCase to
|
13
16
|
# snake_case (e.g. 'RuboCop' => 'rubocop' ).
|
14
17
|
#
|
15
18
|
# @example
|
16
|
-
#
|
19
|
+
# # bad
|
20
|
+
# whatever_spec.rb # describe MyClass
|
21
|
+
#
|
22
|
+
# # bad
|
23
|
+
# my_class_spec.rb # describe MyClass, '#method'
|
24
|
+
#
|
25
|
+
# # good
|
26
|
+
# my_class_spec.rb # describe MyClass
|
27
|
+
#
|
28
|
+
# # good
|
17
29
|
# my_class_method_spec.rb # describe MyClass, '#method'
|
30
|
+
#
|
31
|
+
# # good
|
32
|
+
# my_class/method_spec.rb # describe MyClass, '#method'
|
33
|
+
#
|
34
|
+
# @example when configuration is `IgnoreMethods: true`
|
35
|
+
# # bad
|
36
|
+
# whatever_spec.rb # describe MyClass
|
37
|
+
#
|
38
|
+
# # good
|
18
39
|
# my_class_spec.rb # describe MyClass
|
40
|
+
#
|
41
|
+
# # good
|
42
|
+
# my_class_spec.rb # describe MyClass, '#method'
|
43
|
+
#
|
19
44
|
class FilePath < Cop
|
20
45
|
include RuboCop::RSpec::SpecOnly, RuboCop::RSpec::TopLevelDescribe
|
21
46
|
|
22
47
|
MESSAGE = 'Spec path should end with `%s`'.freeze
|
23
|
-
METHOD_STRING_MATCHER = /^[\#\.].+/
|
24
48
|
ROUTING_PAIR = s(:pair, s(:sym, :type), s(:sym, :routing))
|
25
49
|
|
26
50
|
def on_top_level_describe(node, args)
|
@@ -46,7 +70,7 @@ module RuboCop
|
|
46
70
|
|
47
71
|
def matcher(object, method)
|
48
72
|
path = File.join(parts(object))
|
49
|
-
if method && method.type.equal?(:str)
|
73
|
+
if method && method.type.equal?(:str) && !ignore_methods?
|
50
74
|
path += '*' + method.str_content.gsub(/\W+/, '')
|
51
75
|
end
|
52
76
|
|
@@ -65,8 +89,8 @@ module RuboCop
|
|
65
89
|
|
66
90
|
def camel_to_underscore(string)
|
67
91
|
string
|
68
|
-
.gsub(/([^A-Z])([A-Z]+)/, '
|
69
|
-
.gsub(/([A-Z])([A-Z
|
92
|
+
.gsub(/([^A-Z])([A-Z]+)/, '\1_\2')
|
93
|
+
.gsub(/([A-Z])([A-Z][^A-Z\d]+)/, '\1_\2')
|
70
94
|
.downcase
|
71
95
|
end
|
72
96
|
|
@@ -74,6 +98,10 @@ module RuboCop
|
|
74
98
|
Regexp.new(glob.sub('.', '\\.').gsub('*', '.*') + '$')
|
75
99
|
end
|
76
100
|
|
101
|
+
def ignore_methods?
|
102
|
+
cop_config['IgnoreMethods']
|
103
|
+
end
|
104
|
+
|
77
105
|
def custom_transform
|
78
106
|
cop_config['CustomTransform'] || {}
|
79
107
|
end
|
@@ -0,0 +1,102 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Cop
|
5
|
+
module RSpec
|
6
|
+
# Check that a consistent implicit expectation style is used.
|
7
|
+
#
|
8
|
+
# This cop can be configured using the `EnforcedStyle` option
|
9
|
+
# and supports the `--auto-gen-config` flag.
|
10
|
+
#
|
11
|
+
# @example `EnforcedStyle: is_expected`
|
12
|
+
#
|
13
|
+
# # bad
|
14
|
+
# it { should be_truthy }
|
15
|
+
#
|
16
|
+
# # good
|
17
|
+
# it { is_expected.to be_truthy }
|
18
|
+
#
|
19
|
+
# @example `EnforcedStyle: should`
|
20
|
+
#
|
21
|
+
# # bad
|
22
|
+
# it { is_expected.to be_truthy }
|
23
|
+
#
|
24
|
+
# # good
|
25
|
+
# it { should be_truthy }
|
26
|
+
#
|
27
|
+
class ImplicitExpect < Cop
|
28
|
+
include RuboCop::RSpec::SpecOnly, ConfigurableEnforcedStyle
|
29
|
+
|
30
|
+
MSG = 'Prefer `%<good>s` over `%<bad>s`.'.freeze
|
31
|
+
|
32
|
+
def_node_matcher :implicit_expect, <<-PATTERN
|
33
|
+
{
|
34
|
+
(send nil ${:should :should_not} ...)
|
35
|
+
(send (send nil $:is_expected) {:to :to_not :not_to} ...)
|
36
|
+
}
|
37
|
+
PATTERN
|
38
|
+
|
39
|
+
alternatives = {
|
40
|
+
'is_expected.to' => 'should',
|
41
|
+
'is_expected.not_to' => 'should_not',
|
42
|
+
'is_expected.to_not' => 'should_not'
|
43
|
+
}
|
44
|
+
|
45
|
+
ENFORCED_REPLACEMENTS = alternatives.merge(alternatives.invert).freeze
|
46
|
+
|
47
|
+
def on_send(node)
|
48
|
+
return unless (source_range = offending_expect(node))
|
49
|
+
|
50
|
+
expectation_source = source_range.source
|
51
|
+
|
52
|
+
if expectation_source.start_with?(style.to_s)
|
53
|
+
correct_style_detected
|
54
|
+
else
|
55
|
+
opposite_style_detected
|
56
|
+
|
57
|
+
add_offense(node, source_range, offense_message(expectation_source))
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def autocorrect(node)
|
62
|
+
lambda do |corrector|
|
63
|
+
offense = offending_expect(node)
|
64
|
+
replacement = replacement_source(offense.source)
|
65
|
+
|
66
|
+
corrector.replace(offense, replacement)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
private
|
71
|
+
|
72
|
+
def offending_expect(node)
|
73
|
+
case implicit_expect(node)
|
74
|
+
when :is_expected
|
75
|
+
is_expected_range(node.loc)
|
76
|
+
when :should, :should_not
|
77
|
+
node.loc.selector
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
def is_expected_range(source_map) # rubocop:disable PredicateName
|
82
|
+
Parser::Source::Range.new(
|
83
|
+
source_map.expression.source_buffer,
|
84
|
+
source_map.expression.begin_pos,
|
85
|
+
source_map.selector.end_pos
|
86
|
+
)
|
87
|
+
end
|
88
|
+
|
89
|
+
def offense_message(offending_source)
|
90
|
+
MSG % {
|
91
|
+
good: replacement_source(offending_source),
|
92
|
+
bad: offending_source
|
93
|
+
}
|
94
|
+
end
|
95
|
+
|
96
|
+
def replacement_source(offending_source)
|
97
|
+
ENFORCED_REPLACEMENTS.fetch(offending_source)
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
data/rubocop-rspec.gemspec
CHANGED
@@ -10,14 +10,18 @@ Gem::Specification.new do |spec|
|
|
10
10
|
Code style checking for RSpec files.
|
11
11
|
A plugin for the RuboCop code style enforcing & linting tool.
|
12
12
|
end_description
|
13
|
-
spec.homepage = 'http://github.com/
|
14
|
-
spec.authors = ['Ian MacLeod', 'Nils Gemeinhardt']
|
15
|
-
spec.email = [
|
13
|
+
spec.homepage = 'http://github.com/backus/rubocop-rspec'
|
14
|
+
spec.authors = ['John Backus', 'Ian MacLeod', 'Nils Gemeinhardt']
|
15
|
+
spec.email = [
|
16
|
+
'johncbackus@gmail.com',
|
17
|
+
'ian@nevir.net',
|
18
|
+
'git@nilsgemeinhardt.de'
|
19
|
+
]
|
16
20
|
spec.licenses = ['MIT']
|
17
21
|
|
18
22
|
spec.version = RuboCop::RSpec::Version::STRING
|
19
23
|
spec.platform = Gem::Platform::RUBY
|
20
|
-
spec.required_ruby_version = '>= 2.
|
24
|
+
spec.required_ruby_version = '>= 2.1.0'
|
21
25
|
|
22
26
|
spec.require_paths = ['lib']
|
23
27
|
spec.files = Dir[
|
@@ -20,7 +20,7 @@ describe 'config/default.yml' do
|
|
20
20
|
|
21
21
|
def cop_configuration(config_key)
|
22
22
|
cop_names.map do |cop_name|
|
23
|
-
cop_config = default_config
|
23
|
+
cop_config = default_config[cop_name]
|
24
24
|
|
25
25
|
cop_config.fetch(config_key) do
|
26
26
|
raise "Expected #{cop_name} to have #{config_key} configuration key"
|
@@ -47,6 +47,6 @@ describe 'config/default.yml' do
|
|
47
47
|
end
|
48
48
|
|
49
49
|
it 'includes Enabled: true for every cop' do
|
50
|
-
expect(cop_configuration('Enabled')).to all(be(true))
|
50
|
+
expect(cop_configuration('Enabled')).to all(be(true).or(be(false)))
|
51
51
|
end
|
52
52
|
end
|
@@ -35,6 +35,13 @@ describe RuboCop::Cop::RSpec::BeEql do
|
|
35
35
|
RUBY
|
36
36
|
end
|
37
37
|
|
38
|
+
it 'registers an offense for `eql` when argument is nil' do
|
39
|
+
expect_violation(<<-RUBY)
|
40
|
+
it { expect(foo).to eql(nil) }
|
41
|
+
^^^ Prefer `be` over `eql`
|
42
|
+
RUBY
|
43
|
+
end
|
44
|
+
|
38
45
|
it 'does not register an offense for `eql` when argument is a string' do
|
39
46
|
expect_no_violations(<<-RUBY)
|
40
47
|
it { expect(foo).to eql('foo') }
|
@@ -47,13 +54,7 @@ describe RuboCop::Cop::RSpec::BeEql do
|
|
47
54
|
RUBY
|
48
55
|
end
|
49
56
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
cop,
|
54
|
-
['it { expect(foo).to eql(1) }'],
|
55
|
-
'spec/foo_spec.rb'
|
56
|
-
)
|
57
|
-
expect(corrected).to eq 'it { expect(foo).to be(1) }'
|
58
|
-
end
|
57
|
+
include_examples 'autocorrect',
|
58
|
+
'it { expect(foo).to eql(1) }',
|
59
|
+
'it { expect(foo).to be(1) }'
|
59
60
|
end
|
@@ -195,25 +195,15 @@ describe RuboCop::Cop::RSpec::DescribedClass, :config do
|
|
195
195
|
RUBY
|
196
196
|
end
|
197
197
|
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
expect(new_source).to eq(
|
210
|
-
[
|
211
|
-
'describe MyClass do',
|
212
|
-
' include described_class',
|
213
|
-
' subject { described_class.do_something }',
|
214
|
-
' before { described_class.do_something }',
|
215
|
-
'end'
|
216
|
-
].join("\n")
|
217
|
-
)
|
218
|
-
end
|
198
|
+
include_examples 'autocorrect',
|
199
|
+
'describe(Foo) { include Foo }',
|
200
|
+
'describe(Foo) { include described_class }'
|
201
|
+
|
202
|
+
include_examples 'autocorrect',
|
203
|
+
'describe(Foo) { subject { Foo.do_something } }',
|
204
|
+
'describe(Foo) { subject { described_class.do_something } }'
|
205
|
+
|
206
|
+
include_examples 'autocorrect',
|
207
|
+
'describe(Foo) { before { Foo.do_something } }',
|
208
|
+
'describe(Foo) { before { described_class.do_something } }'
|
219
209
|
end
|
@@ -44,39 +44,18 @@ describe RuboCop::Cop::RSpec::ExampleWording, :config do
|
|
44
44
|
RUBY
|
45
45
|
end
|
46
46
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
cop,
|
51
|
-
'it "should only have trait" do end',
|
52
|
-
'spec/foo_spec.rb'
|
53
|
-
)
|
54
|
-
|
55
|
-
expect(corrected).to eql('it "only has trait" do end')
|
56
|
-
end
|
47
|
+
include_examples 'autocorrect',
|
48
|
+
'it "should only have trait" do end',
|
49
|
+
'it "only has trait" do end'
|
57
50
|
end
|
58
51
|
|
59
52
|
context 'when configuration is empty' do
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
cop,
|
64
|
-
'it "should have trait" do end',
|
65
|
-
'spec/foo_spec.rb'
|
66
|
-
)
|
67
|
-
|
68
|
-
expect(corrected).to eql('it "haves trait" do end')
|
69
|
-
end
|
70
|
-
|
71
|
-
it 'only does not make an exception for the word "only"' do
|
72
|
-
corrected =
|
73
|
-
autocorrect_source(
|
74
|
-
cop,
|
75
|
-
'it "should only fail" do end',
|
76
|
-
'spec/foo_spec.rb'
|
77
|
-
)
|
53
|
+
include_examples 'autocorrect',
|
54
|
+
'it "should have trait" do end',
|
55
|
+
'it "haves trait" do end'
|
78
56
|
|
79
|
-
|
80
|
-
|
57
|
+
include_examples 'autocorrect',
|
58
|
+
'it "should only fail" do end',
|
59
|
+
'it "onlies fail" do end'
|
81
60
|
end
|
82
61
|
end
|
@@ -116,8 +116,8 @@ describe RuboCop::Cop::RSpec::FilePath, :config do
|
|
116
116
|
it 'handles alphanumeric class names' do
|
117
117
|
inspect_source(
|
118
118
|
cop,
|
119
|
-
'describe
|
120
|
-
'
|
119
|
+
'describe IPV4AndIPV6 do; end',
|
120
|
+
'ipv4_and_ipv6_spec.rb'
|
121
121
|
)
|
122
122
|
expect(cop.offenses).to be_empty
|
123
123
|
end
|
@@ -212,7 +212,7 @@ describe RuboCop::Cop::RSpec::FilePath, :config do
|
|
212
212
|
expect(cop.offenses).to be_empty
|
213
213
|
end
|
214
214
|
|
215
|
-
context 'when configured' do
|
215
|
+
context 'when configured with CustomTransform' do
|
216
216
|
let(:cop_config) { { 'CustomTransform' => { 'FooFoo' => 'foofoo' } } }
|
217
217
|
|
218
218
|
it 'respects custom module name transformation' do
|
@@ -233,4 +233,17 @@ describe RuboCop::Cop::RSpec::FilePath, :config do
|
|
233
233
|
expect(cop.offenses).to be_empty
|
234
234
|
end
|
235
235
|
end
|
236
|
+
|
237
|
+
context 'when configured with IgnoreMethods' do
|
238
|
+
let(:cop_config) { { 'IgnoreMethods' => true } }
|
239
|
+
|
240
|
+
it 'does not care about the described method' do
|
241
|
+
inspect_source(
|
242
|
+
cop,
|
243
|
+
"describe MyClass, '#look_here_a_method' do; end",
|
244
|
+
'my_class_spec.rb'
|
245
|
+
)
|
246
|
+
expect(cop.offenses).to be_empty
|
247
|
+
end
|
248
|
+
end
|
236
249
|
end
|
@@ -32,43 +32,17 @@ describe RuboCop::Cop::RSpec::HookArgument, :config do
|
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
35
|
-
shared_examples 'generated config' do |source, detected_style|
|
36
|
-
it 'generates a todo based on the detected style' do
|
37
|
-
inspect_source(cop, source, 'foo_spec.rb')
|
38
|
-
|
39
|
-
expect(cop.config_to_allow_offenses)
|
40
|
-
.to eq('EnforcedStyle' => detected_style)
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
35
|
shared_examples 'hook autocorrect' do |output|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
expect(corrected).to eql(output)
|
50
|
-
end
|
51
|
-
|
52
|
-
it 'autocorrects :example to EnforcedStyle' do
|
53
|
-
corrected =
|
54
|
-
autocorrect_source(cop, 'before(:example) { }', 'spec/foo_spec.rb')
|
55
|
-
|
56
|
-
expect(corrected).to eql(output)
|
57
|
-
end
|
58
|
-
|
59
|
-
it 'autocorrects :implicit to EnforcedStyle' do
|
60
|
-
corrected =
|
61
|
-
autocorrect_source(cop, 'before { }', 'spec/foo_spec.rb')
|
62
|
-
|
63
|
-
expect(corrected).to eql(output)
|
64
|
-
end
|
36
|
+
include_examples 'autocorrect', 'before(:each) { }', output
|
37
|
+
include_examples 'autocorrect', 'before(:example) { }', output
|
38
|
+
include_examples 'autocorrect', 'before { }', output
|
65
39
|
end
|
66
40
|
|
67
41
|
shared_examples 'an example hook' do
|
68
42
|
include_examples 'ignored hooks'
|
69
|
-
include_examples '
|
70
|
-
include_examples '
|
71
|
-
include_examples '
|
43
|
+
include_examples 'detects style', 'before(:each) { foo }', 'each'
|
44
|
+
include_examples 'detects style', 'before(:example) { foo }', 'example'
|
45
|
+
include_examples 'detects style', 'before { foo }', 'implicit'
|
72
46
|
end
|
73
47
|
|
74
48
|
context 'when EnforcedStyle is :implicit' do
|
@@ -0,0 +1,101 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
describe RuboCop::Cop::RSpec::ImplicitExpect, :config do
|
4
|
+
subject(:cop) { described_class.new(config) }
|
5
|
+
|
6
|
+
context 'when EnforcedStyle is is_expected' do
|
7
|
+
let(:cop_config) do
|
8
|
+
{ 'EnforcedStyle' => 'is_expected' }
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'flags it { should }' do
|
12
|
+
expect_violation(<<-RUBY)
|
13
|
+
it { should be_truthy }
|
14
|
+
^^^^^^ Prefer `is_expected.to` over `should`.
|
15
|
+
RUBY
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'flags it { should_not }' do
|
19
|
+
expect_violation(<<-RUBY)
|
20
|
+
it { should_not be_truthy }
|
21
|
+
^^^^^^^^^^ Prefer `is_expected.to_not` over `should_not`.
|
22
|
+
RUBY
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'approves of is_expected.to' do
|
26
|
+
expect_no_violations('it { is_expected.to be_truthy }')
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'approves of is_expected.to_not' do
|
30
|
+
expect_no_violations('it { is_expected.to_not be_truthy }')
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'approves of is_expected.to_not' do
|
34
|
+
expect_no_violations('it { is_expected.not_to be_truthy }')
|
35
|
+
end
|
36
|
+
|
37
|
+
include_examples 'detects style', 'it { should be_truthy }', 'should'
|
38
|
+
include_examples 'autocorrect',
|
39
|
+
'it { should be_truthy }',
|
40
|
+
'it { is_expected.to be_truthy }'
|
41
|
+
|
42
|
+
include_examples 'autocorrect',
|
43
|
+
'it { should_not be_truthy }',
|
44
|
+
'it { is_expected.to_not be_truthy }'
|
45
|
+
end
|
46
|
+
|
47
|
+
context 'when EnforcedStyle is should' do
|
48
|
+
let(:cop_config) do
|
49
|
+
{ 'EnforcedStyle' => 'should' }
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'flags it { is_expected.to }' do
|
53
|
+
expect_violation(<<-RUBY)
|
54
|
+
it { is_expected.to be_truthy }
|
55
|
+
^^^^^^^^^^^^^^ Prefer `should` over `is_expected.to`.
|
56
|
+
RUBY
|
57
|
+
end
|
58
|
+
|
59
|
+
it 'flags it { is_expected.to_not }' do
|
60
|
+
expect_violation(<<-RUBY)
|
61
|
+
it { is_expected.to_not be_truthy }
|
62
|
+
^^^^^^^^^^^^^^^^^^ Prefer `should_not` over `is_expected.to_not`.
|
63
|
+
RUBY
|
64
|
+
end
|
65
|
+
|
66
|
+
it 'flags it { is_expected.not_to }' do
|
67
|
+
expect_violation(<<-RUBY)
|
68
|
+
it { is_expected.not_to be_truthy }
|
69
|
+
^^^^^^^^^^^^^^^^^^ Prefer `should_not` over `is_expected.not_to`.
|
70
|
+
RUBY
|
71
|
+
end
|
72
|
+
|
73
|
+
it 'approves of should' do
|
74
|
+
expect_no_violations('it { should be_truthy }')
|
75
|
+
end
|
76
|
+
|
77
|
+
it 'approves of should_not' do
|
78
|
+
expect_no_violations('it { should_not be_truthy }')
|
79
|
+
end
|
80
|
+
|
81
|
+
include_examples 'detects style',
|
82
|
+
'it { is_expected.to be_truthy }',
|
83
|
+
'is_expected'
|
84
|
+
|
85
|
+
include_examples 'detects style',
|
86
|
+
'it { should be_truthy }',
|
87
|
+
'should'
|
88
|
+
|
89
|
+
include_examples 'autocorrect',
|
90
|
+
'it { is_expected.to be_truthy }',
|
91
|
+
'it { should be_truthy }'
|
92
|
+
|
93
|
+
include_examples 'autocorrect',
|
94
|
+
'it { is_expected.to_not be_truthy }',
|
95
|
+
'it { should_not be_truthy }'
|
96
|
+
|
97
|
+
include_examples 'autocorrect',
|
98
|
+
'it { is_expected.not_to be_truthy }',
|
99
|
+
'it { should_not be_truthy }'
|
100
|
+
end
|
101
|
+
end
|
@@ -35,7 +35,7 @@ describe RuboCop::Cop::RSpec::NestedGroups, :config do
|
|
35
35
|
RUBY
|
36
36
|
end
|
37
37
|
|
38
|
-
context 'when MaxNesting is configured as
|
38
|
+
context 'when MaxNesting is configured as 3' do
|
39
39
|
let(:cop_config) { { 'MaxNesting' => '3' } }
|
40
40
|
|
41
41
|
it 'only flags third level of nesting' do
|
@@ -17,15 +17,9 @@ describe RuboCop::Cop::RSpec::NotToNot, :config do
|
|
17
17
|
RUBY
|
18
18
|
end
|
19
19
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
cop,
|
24
|
-
['it { expect(0).to_not equal 1 }'],
|
25
|
-
'spec/foo_spec.rb'
|
26
|
-
)
|
27
|
-
expect(corrected).to eq 'it { expect(0).not_to equal 1 }'
|
28
|
-
end
|
20
|
+
include_examples 'autocorrect',
|
21
|
+
'it { expect(0).to_not equal 1 }',
|
22
|
+
'it { expect(0).not_to equal 1 }'
|
29
23
|
end
|
30
24
|
|
31
25
|
context 'when AcceptedMethod is `to_not`' do
|
@@ -44,14 +38,8 @@ describe RuboCop::Cop::RSpec::NotToNot, :config do
|
|
44
38
|
RUBY
|
45
39
|
end
|
46
40
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
cop,
|
51
|
-
['it { expect(0).not_to equal 1 }'],
|
52
|
-
'spec/foo_spec.rb'
|
53
|
-
)
|
54
|
-
expect(corrected).to eq 'it { expect(0).to_not equal 1 }'
|
55
|
-
end
|
41
|
+
include_examples 'autocorrect',
|
42
|
+
'it { expect(0).not_to equal 1 }',
|
43
|
+
'it { expect(0).to_not equal 1 }'
|
56
44
|
end
|
57
45
|
end
|
metadata
CHANGED
@@ -1,15 +1,16 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rubocop-rspec
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
+
- John Backus
|
7
8
|
- Ian MacLeod
|
8
9
|
- Nils Gemeinhardt
|
9
10
|
autorequire:
|
10
11
|
bindir: bin
|
11
12
|
cert_chain: []
|
12
|
-
date: 2016-
|
13
|
+
date: 2016-10-27 00:00:00.000000000 Z
|
13
14
|
dependencies:
|
14
15
|
- !ruby/object:Gem::Dependency
|
15
16
|
name: rubocop
|
@@ -127,6 +128,7 @@ description: |2
|
|
127
128
|
Code style checking for RSpec files.
|
128
129
|
A plugin for the RuboCop code style enforcing & linting tool.
|
129
130
|
email:
|
131
|
+
- johncbackus@gmail.com
|
130
132
|
- ian@nevir.net
|
131
133
|
- git@nilsgemeinhardt.de
|
132
134
|
executables: []
|
@@ -154,6 +156,7 @@ files:
|
|
154
156
|
- lib/rubocop/cop/rspec/file_path.rb
|
155
157
|
- lib/rubocop/cop/rspec/focus.rb
|
156
158
|
- lib/rubocop/cop/rspec/hook_argument.rb
|
159
|
+
- lib/rubocop/cop/rspec/implicit_expect.rb
|
157
160
|
- lib/rubocop/cop/rspec/instance_variable.rb
|
158
161
|
- lib/rubocop/cop/rspec/leading_subject.rb
|
159
162
|
- lib/rubocop/cop/rspec/let_setup.rb
|
@@ -194,6 +197,7 @@ files:
|
|
194
197
|
- spec/rubocop/cop/rspec/file_path_spec.rb
|
195
198
|
- spec/rubocop/cop/rspec/focus_spec.rb
|
196
199
|
- spec/rubocop/cop/rspec/hook_argument_spec.rb
|
200
|
+
- spec/rubocop/cop/rspec/implicit_expect_spec.rb
|
197
201
|
- spec/rubocop/cop/rspec/instance_variable_spec.rb
|
198
202
|
- spec/rubocop/cop/rspec/leading_subject_spec.rb
|
199
203
|
- spec/rubocop/cop/rspec/let_setup_spec.rb
|
@@ -212,10 +216,12 @@ files:
|
|
212
216
|
- spec/rubocop/rspec/spec_only_spec.rb
|
213
217
|
- spec/rubocop/rspec/util/one_spec.rb
|
214
218
|
- spec/rubocop/rspec/wording_spec.rb
|
219
|
+
- spec/shared/autocorrect_behavior.rb
|
220
|
+
- spec/shared/detects_style_behavior.rb
|
215
221
|
- spec/shared/rspec_only_cop_behavior.rb
|
216
222
|
- spec/spec_helper.rb
|
217
223
|
- spec/support/expect_violation.rb
|
218
|
-
homepage: http://github.com/
|
224
|
+
homepage: http://github.com/backus/rubocop-rspec
|
219
225
|
licenses:
|
220
226
|
- MIT
|
221
227
|
metadata: {}
|
@@ -227,7 +233,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
227
233
|
requirements:
|
228
234
|
- - ">="
|
229
235
|
- !ruby/object:Gem::Version
|
230
|
-
version: 2.
|
236
|
+
version: 2.1.0
|
231
237
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
232
238
|
requirements:
|
233
239
|
- - ">="
|
@@ -256,6 +262,7 @@ test_files:
|
|
256
262
|
- spec/rubocop/cop/rspec/file_path_spec.rb
|
257
263
|
- spec/rubocop/cop/rspec/focus_spec.rb
|
258
264
|
- spec/rubocop/cop/rspec/hook_argument_spec.rb
|
265
|
+
- spec/rubocop/cop/rspec/implicit_expect_spec.rb
|
259
266
|
- spec/rubocop/cop/rspec/instance_variable_spec.rb
|
260
267
|
- spec/rubocop/cop/rspec/leading_subject_spec.rb
|
261
268
|
- spec/rubocop/cop/rspec/let_setup_spec.rb
|
@@ -274,6 +281,8 @@ test_files:
|
|
274
281
|
- spec/rubocop/rspec/spec_only_spec.rb
|
275
282
|
- spec/rubocop/rspec/util/one_spec.rb
|
276
283
|
- spec/rubocop/rspec/wording_spec.rb
|
284
|
+
- spec/shared/autocorrect_behavior.rb
|
285
|
+
- spec/shared/detects_style_behavior.rb
|
277
286
|
- spec/shared/rspec_only_cop_behavior.rb
|
278
287
|
- spec/spec_helper.rb
|
279
288
|
- spec/support/expect_violation.rb
|