rubocop-rspec 1.16.0 → 1.17.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 -2
- data/config/default.yml +6 -1
- data/lib/rubocop-rspec.rb +2 -0
- data/lib/rubocop/cop/rspec/capybara/feature_methods.rb +67 -0
- data/lib/rubocop/cop/rspec/repeated_example.rb +1 -1
- data/lib/rubocop/rspec/capybara.rb +7 -0
- data/lib/rubocop/rspec/config_formatter.rb +3 -3
- data/lib/rubocop/rspec/hook.rb +1 -1
- data/lib/rubocop/rspec/version.rb +1 -1
- data/rubocop-rspec.gemspec +3 -5
- data/spec/project/default_config_spec.rb +2 -1
- data/spec/rubocop/cop/rspec/capybara/feature_methods_spec.rb +52 -0
- data/spec/rubocop/cop/rspec/expect_actual_spec.rb +0 -1
- data/spec/rubocop/cop/rspec/hook_argument_spec.rb +0 -2
- data/spec/rubocop/cop/rspec/it_behaves_like_spec.rb +0 -2
- data/spec/rubocop/cop/rspec/let_before_examples_spec.rb +1 -1
- data/spec/rubocop/cop/rspec/multiple_expectations_spec.rb +1 -1
- data/spec/rubocop/cop/rspec/multiple_subjects_spec.rb +1 -1
- data/spec/rubocop/cop/rspec/nested_groups_spec.rb +1 -1
- data/spec/rubocop/cop/rspec/overwriting_setup_spec.rb +1 -1
- data/spec/rubocop/cop/rspec/scattered_let_spec.rb +1 -1
- data/spec/shared/autocorrect_behavior.rb +1 -1
- data/spec/shared/detects_style_behavior.rb +1 -1
- metadata +8 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 920ff6aef932dcc189cf4a9b36a4da113414e514
|
4
|
+
data.tar.gz: 924b473a982bea7b74862f9d38c7adebd54b0d15
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 95f9ed3893655f17e5d78fbe03decd86deb93fab86db2599f2848795c035eeea9e4347df6b3700f3cc6e31599bd76e37ab4ab57477a9c17b9cf462c479bafb9a
|
7
|
+
data.tar.gz: ad2e034857001d8fd654008c96446fb48641dde3787a2ace21709005c2c185f8fa2a370a11e7dca03d42ccb428f1d110de574eaf286bf17447f92b8bc08dd2c5
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,11 @@
|
|
2
2
|
|
3
3
|
## Master (Unreleased)
|
4
4
|
|
5
|
+
## 1.17.0 (2017-09-14)
|
6
|
+
|
7
|
+
* Add `RSpec/Capybara` namespace including the first cop for feature specs: `Capybara/FeatureMethods`. ([@rspeicher][])
|
8
|
+
* Update to RuboCop 0.50.0. ([@bquorning][])
|
9
|
+
|
5
10
|
## 1.16.0 (2017-09-06)
|
6
11
|
|
7
12
|
* Add `RSpec/FactoryGirl` namespace including the first cop for factories: `FactoryGirl/DynamicAttributeDefinedStatically`. ([@jonatas][])
|
@@ -26,7 +31,7 @@
|
|
26
31
|
|
27
32
|
## 1.15.0 (2017-03-24)
|
28
33
|
|
29
|
-
* Add `RSpec/DescribeSymbol` cop. ([@
|
34
|
+
* Add `RSpec/DescribeSymbol` cop. ([@rspeicher][])
|
30
35
|
* Fix error when `RSpec/OverwritingSetup` and `RSpec/ScatteredLet` analyzed empty example groups. ([@backus][])
|
31
36
|
|
32
37
|
## 1.14.0 (2017-03-24)
|
@@ -233,7 +238,7 @@
|
|
233
238
|
[@redross]: https://github.com/redross
|
234
239
|
[@cfabianski]: https://github.com/cfabianski
|
235
240
|
[@dgollahon]: https://github.com/dgollahon
|
236
|
-
[@
|
241
|
+
[@rspeicher]: https://github.com/rspeicher
|
237
242
|
[@jonatas]: https://github.com/jonatas
|
238
243
|
[@pocke]: https://github.com/pocke
|
239
244
|
[@bmorrall]: https:/github.com/bmorrall
|
data/config/default.yml
CHANGED
@@ -325,7 +325,12 @@ RSpec/VoidExpect:
|
|
325
325
|
Enabled: true
|
326
326
|
StyleGuide: http://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/VoidExpect
|
327
327
|
|
328
|
+
Capybara/FeatureMethods:
|
329
|
+
Description: Checks for consistent method usage in feature specs.
|
330
|
+
Enabled: true
|
331
|
+
StyleGuide: http://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/Capybara/FeatureMethods
|
332
|
+
|
328
333
|
FactoryGirl/DynamicAttributeDefinedStatically:
|
329
334
|
Description: Prefer declaring dynamic attribute values in a block.
|
330
335
|
Enabled: true
|
331
|
-
StyleGuide: http://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/FactoryGirl/DynamicAttributeDefinedStatically
|
336
|
+
StyleGuide: http://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/FactoryGirl/DynamicAttributeDefinedStatically
|
data/lib/rubocop-rspec.rb
CHANGED
@@ -17,6 +17,7 @@ require 'rubocop/rspec/example'
|
|
17
17
|
require 'rubocop/rspec/hook'
|
18
18
|
require 'rubocop/cop/rspec/cop'
|
19
19
|
require 'rubocop/rspec/align_let_brace'
|
20
|
+
require 'rubocop/rspec/capybara'
|
20
21
|
require 'rubocop/rspec/factory_girl'
|
21
22
|
|
22
23
|
RuboCop::RSpec::Inject.defaults!
|
@@ -28,6 +29,7 @@ require 'rubocop/cop/rspec/any_instance'
|
|
28
29
|
require 'rubocop/cop/rspec/around_block'
|
29
30
|
require 'rubocop/cop/rspec/be_eql'
|
30
31
|
require 'rubocop/cop/rspec/before_after_all'
|
32
|
+
require 'rubocop/cop/rspec/capybara/feature_methods'
|
31
33
|
require 'rubocop/cop/rspec/describe_class'
|
32
34
|
require 'rubocop/cop/rspec/describe_method'
|
33
35
|
require 'rubocop/cop/rspec/describe_symbol'
|
@@ -0,0 +1,67 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Cop
|
5
|
+
module RSpec
|
6
|
+
module Capybara
|
7
|
+
# Checks for consistent method usage in feature specs.
|
8
|
+
#
|
9
|
+
# @example
|
10
|
+
# # bad
|
11
|
+
# feature 'User logs in' do
|
12
|
+
# given(:user) { User.new }
|
13
|
+
#
|
14
|
+
# background do
|
15
|
+
# visit new_session_path
|
16
|
+
# end
|
17
|
+
#
|
18
|
+
# scenario 'with OAuth' do
|
19
|
+
# # ...
|
20
|
+
# end
|
21
|
+
# end
|
22
|
+
#
|
23
|
+
# # good
|
24
|
+
# describe 'User logs in' do
|
25
|
+
# let(:user) { User.new }
|
26
|
+
#
|
27
|
+
# before do
|
28
|
+
# visit new_session_path
|
29
|
+
# end
|
30
|
+
#
|
31
|
+
# it 'with OAuth' do
|
32
|
+
# # ...
|
33
|
+
# end
|
34
|
+
# end
|
35
|
+
class FeatureMethods < Cop
|
36
|
+
MSG = 'Use `%s` instead of `%s`.'.freeze
|
37
|
+
|
38
|
+
# https://git.io/v7Kwr
|
39
|
+
MAP = {
|
40
|
+
background: :before,
|
41
|
+
scenario: :it,
|
42
|
+
xscenario: :xit,
|
43
|
+
given: :let,
|
44
|
+
given!: :let!,
|
45
|
+
feature: :describe
|
46
|
+
}.freeze
|
47
|
+
|
48
|
+
def_node_matcher :feature_method?, <<-PATTERN
|
49
|
+
(send {(const nil :RSpec) nil} ${:#{MAP.keys.join(' :')}} ...)
|
50
|
+
PATTERN
|
51
|
+
|
52
|
+
def on_send(node)
|
53
|
+
feature_method?(node) do |match|
|
54
|
+
add_offense(node, :selector, format(MSG, MAP[match], match))
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def autocorrect(node)
|
59
|
+
lambda do |corrector|
|
60
|
+
corrector.replace(node.loc.selector, MAP[node.method_name].to_s)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -4,8 +4,8 @@ module RuboCop
|
|
4
4
|
module RSpec
|
5
5
|
# Builds a YAML config file from two config hashes
|
6
6
|
class ConfigFormatter
|
7
|
-
NAMESPACES = /^(#{Regexp.union('RSpec', 'FactoryGirl')})/
|
8
|
-
STYLE_GUIDE_BASE_URL = 'http://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/'.freeze
|
7
|
+
NAMESPACES = /^(#{Regexp.union('RSpec', 'Capybara', 'FactoryGirl')})/
|
8
|
+
STYLE_GUIDE_BASE_URL = 'http://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/'.freeze
|
9
9
|
|
10
10
|
def initialize(config, descriptions)
|
11
11
|
@config = config
|
@@ -22,7 +22,7 @@ module RuboCop
|
|
22
22
|
cops.each_with_object(config.dup) do |cop, unified|
|
23
23
|
unified[cop] = config.fetch(cop)
|
24
24
|
.merge(descriptions.fetch(cop))
|
25
|
-
.merge('StyleGuide' => STYLE_GUIDE_BASE_URL + cop)
|
25
|
+
.merge('StyleGuide' => STYLE_GUIDE_BASE_URL + cop.sub('RSpec/', ''))
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
data/lib/rubocop/rspec/hook.rb
CHANGED
data/rubocop-rspec.gemspec
CHANGED
@@ -1,15 +1,13 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
1
|
$LOAD_PATH.unshift File.expand_path('../lib', __FILE__)
|
4
2
|
require 'rubocop/rspec/version'
|
5
3
|
|
6
4
|
Gem::Specification.new do |spec|
|
7
5
|
spec.name = 'rubocop-rspec'
|
8
6
|
spec.summary = 'Code style checking for RSpec files'
|
9
|
-
spec.description = <<-
|
7
|
+
spec.description = <<-DESCRIPTION
|
10
8
|
Code style checking for RSpec files.
|
11
9
|
A plugin for the RuboCop code style enforcing & linting tool.
|
12
|
-
|
10
|
+
DESCRIPTION
|
13
11
|
spec.homepage = 'http://github.com/backus/rubocop-rspec'
|
14
12
|
spec.authors = ['John Backus', 'Ian MacLeod', 'Nils Gemeinhardt']
|
15
13
|
spec.email = [
|
@@ -34,7 +32,7 @@ Gem::Specification.new do |spec|
|
|
34
32
|
spec.test_files = spec.files.grep(%r{^spec/})
|
35
33
|
spec.extra_rdoc_files = ['MIT-LICENSE.md', 'README.md']
|
36
34
|
|
37
|
-
spec.add_runtime_dependency 'rubocop', '>= 0.
|
35
|
+
spec.add_runtime_dependency 'rubocop', '>= 0.50.0'
|
38
36
|
|
39
37
|
spec.add_development_dependency 'rake'
|
40
38
|
spec.add_development_dependency 'rspec', '>= 3.4'
|
@@ -6,10 +6,11 @@ RSpec.describe 'config/default.yml' do
|
|
6
6
|
let(:cop_names) do
|
7
7
|
namespaces = {
|
8
8
|
'rspec' => 'RSpec',
|
9
|
+
'capybara' => 'Capybara',
|
9
10
|
'factory_girl' => 'FactoryGirl'
|
10
11
|
}
|
11
12
|
glob = SpecHelper::ROOT.join('lib', 'rubocop', 'cop',
|
12
|
-
'rspec', '{
|
13
|
+
'rspec', '{capybara/,,factory_girl/}*.rb')
|
13
14
|
cop_names =
|
14
15
|
Pathname.glob(glob).map do |file|
|
15
16
|
file_name = file.basename('.rb').to_s
|
@@ -0,0 +1,52 @@
|
|
1
|
+
RSpec.describe RuboCop::Cop::RSpec::Capybara::FeatureMethods do
|
2
|
+
subject(:cop) { described_class.new }
|
3
|
+
|
4
|
+
it 'flags violations for `background`' do
|
5
|
+
expect_offense(<<-RUBY)
|
6
|
+
background do; end
|
7
|
+
^^^^^^^^^^ Use `before` instead of `background`.
|
8
|
+
RUBY
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'flags violations for `scenario`' do
|
12
|
+
expect_offense(<<-RUBY)
|
13
|
+
scenario 'Foo' do; end
|
14
|
+
^^^^^^^^ Use `it` instead of `scenario`.
|
15
|
+
RUBY
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'flags violations for `xscenario`' do
|
19
|
+
expect_offense(<<-RUBY)
|
20
|
+
RSpec.xscenario 'Foo' do; end
|
21
|
+
^^^^^^^^^ Use `xit` instead of `xscenario`.
|
22
|
+
RUBY
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'flags violations for `given`' do
|
26
|
+
expect_offense(<<-RUBY)
|
27
|
+
given(:foo) { :foo }
|
28
|
+
^^^^^ Use `let` instead of `given`.
|
29
|
+
RUBY
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'flags violations for `given!`' do
|
33
|
+
expect_offense(<<-RUBY)
|
34
|
+
given!(:foo) { :foo }
|
35
|
+
^^^^^^ Use `let!` instead of `given!`.
|
36
|
+
RUBY
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'flags violations for `feature`' do
|
40
|
+
expect_offense(<<-RUBY)
|
41
|
+
RSpec.feature 'Foo' do; end
|
42
|
+
^^^^^^^ Use `describe` instead of `feature`.
|
43
|
+
RUBY
|
44
|
+
end
|
45
|
+
|
46
|
+
include_examples 'autocorrect', 'background { }', 'before { }'
|
47
|
+
include_examples 'autocorrect', 'scenario { }', 'it { }'
|
48
|
+
include_examples 'autocorrect', 'xscenario { }', 'xit { }'
|
49
|
+
include_examples 'autocorrect', 'given(:foo) { }', 'let(:foo) { }'
|
50
|
+
include_examples 'autocorrect', 'given!(:foo) { }', 'let!(:foo) { }'
|
51
|
+
include_examples 'autocorrect', 'RSpec.feature { }', 'RSpec.describe { }'
|
52
|
+
end
|
@@ -77,7 +77,7 @@ RSpec.describe RuboCop::Cop::RSpec::LetBeforeExamples do
|
|
77
77
|
end
|
78
78
|
|
79
79
|
it 'does not encounter an error when handling an empty describe' do
|
80
|
-
expect { inspect_source(
|
80
|
+
expect { inspect_source('RSpec.describe(User) do end', 'a_spec.rb') }
|
81
81
|
.not_to raise_error
|
82
82
|
end
|
83
83
|
end
|
@@ -163,7 +163,7 @@ RSpec.describe RuboCop::Cop::RSpec::MultipleExpectations, :config do
|
|
163
163
|
end
|
164
164
|
|
165
165
|
it 'generates a todo based on the worst violation' do
|
166
|
-
inspect_source(
|
166
|
+
inspect_source(<<-RUBY, 'spec/foo_spec.rb')
|
167
167
|
describe Foo do
|
168
168
|
it 'uses expect twice' do
|
169
169
|
expect(foo).to eq(bar)
|
@@ -29,7 +29,7 @@ RSpec.describe RuboCop::Cop::RSpec::MultipleSubjects do
|
|
29
29
|
end
|
30
30
|
RUBY
|
31
31
|
|
32
|
-
expect(autocorrect_source(
|
32
|
+
expect(autocorrect_source(source, 'example_spec.rb')).to eql(source)
|
33
33
|
end
|
34
34
|
|
35
35
|
it 'does not flag shared example groups' do
|
@@ -56,7 +56,7 @@ RSpec.describe RuboCop::Cop::RSpec::NestedGroups, :config do
|
|
56
56
|
let(:cop_config) { { 'MaxNesting' => '1' } }
|
57
57
|
|
58
58
|
it 'emits a deprecation warning' do
|
59
|
-
expect { inspect_source(
|
59
|
+
expect { inspect_source('describe(Foo) { }', 'foo_spec.rb') }
|
60
60
|
.to output(
|
61
61
|
'Configuration key `MaxNesting` for RSpec/NestedGroups is ' \
|
62
62
|
"deprecated in favor of `Max`. Please use that instead.\n"
|
@@ -45,7 +45,7 @@ RSpec.describe RuboCop::Cop::RSpec::OverwritingSetup do
|
|
45
45
|
end
|
46
46
|
|
47
47
|
it 'does not encounter an error when handling an empty describe' do
|
48
|
-
expect { inspect_source(
|
48
|
+
expect { inspect_source('RSpec.describe(User) do end', 'a_spec.rb') }
|
49
49
|
.not_to raise_error
|
50
50
|
end
|
51
51
|
end
|
@@ -25,7 +25,7 @@ RSpec.describe RuboCop::Cop::RSpec::ScatteredLet do
|
|
25
25
|
end
|
26
26
|
|
27
27
|
it 'does not encounter an error when handling an empty describe' do
|
28
|
-
expect { inspect_source(
|
28
|
+
expect { inspect_source('RSpec.describe(User) do end', 'a_spec.rb') }
|
29
29
|
.not_to raise_error
|
30
30
|
end
|
31
31
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
RSpec.shared_examples 'autocorrect' do |original, corrected|
|
2
2
|
it "autocorrects `#{original}` to `#{corrected}`" do
|
3
|
-
autocorrected = autocorrect_source(
|
3
|
+
autocorrected = autocorrect_source(original, 'spec/foo_spec.rb')
|
4
4
|
|
5
5
|
expect(autocorrected).to eql(corrected)
|
6
6
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
RSpec.shared_examples 'detects style' do |source, style, filename: 'x_spec.rb'|
|
2
2
|
it 'generates a todo based on the detected style' do
|
3
|
-
inspect_source(
|
3
|
+
inspect_source(source, filename)
|
4
4
|
|
5
5
|
expect(cop.config_to_allow_offenses).to eq('EnforcedStyle' => style)
|
6
6
|
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
|
+
version: 1.17.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- John Backus
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2017-09-
|
13
|
+
date: 2017-09-14 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rubocop
|
@@ -18,14 +18,14 @@ dependencies:
|
|
18
18
|
requirements:
|
19
19
|
- - ">="
|
20
20
|
- !ruby/object:Gem::Version
|
21
|
-
version: 0.
|
21
|
+
version: 0.50.0
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
24
|
version_requirements: !ruby/object:Gem::Requirement
|
25
25
|
requirements:
|
26
26
|
- - ">="
|
27
27
|
- !ruby/object:Gem::Version
|
28
|
-
version: 0.
|
28
|
+
version: 0.50.0
|
29
29
|
- !ruby/object:Gem::Dependency
|
30
30
|
name: rake
|
31
31
|
requirement: !ruby/object:Gem::Requirement
|
@@ -108,6 +108,7 @@ files:
|
|
108
108
|
- lib/rubocop/cop/rspec/around_block.rb
|
109
109
|
- lib/rubocop/cop/rspec/be_eql.rb
|
110
110
|
- lib/rubocop/cop/rspec/before_after_all.rb
|
111
|
+
- lib/rubocop/cop/rspec/capybara/feature_methods.rb
|
111
112
|
- lib/rubocop/cop/rspec/cop.rb
|
112
113
|
- lib/rubocop/cop/rspec/describe_class.rb
|
113
114
|
- lib/rubocop/cop/rspec/describe_method.rb
|
@@ -157,6 +158,7 @@ files:
|
|
157
158
|
- lib/rubocop/cop/rspec/void_expect.rb
|
158
159
|
- lib/rubocop/rspec.rb
|
159
160
|
- lib/rubocop/rspec/align_let_brace.rb
|
161
|
+
- lib/rubocop/rspec/capybara.rb
|
160
162
|
- lib/rubocop/rspec/concept.rb
|
161
163
|
- lib/rubocop/rspec/config_formatter.rb
|
162
164
|
- lib/rubocop/rspec/description_extractor.rb
|
@@ -181,6 +183,7 @@ files:
|
|
181
183
|
- spec/rubocop/cop/rspec/around_block_spec.rb
|
182
184
|
- spec/rubocop/cop/rspec/be_eql_spec.rb
|
183
185
|
- spec/rubocop/cop/rspec/before_after_all_spec.rb
|
186
|
+
- spec/rubocop/cop/rspec/capybara/feature_methods_spec.rb
|
184
187
|
- spec/rubocop/cop/rspec/cop_spec.rb
|
185
188
|
- spec/rubocop/cop/rspec/describe_class_spec.rb
|
186
189
|
- spec/rubocop/cop/rspec/describe_method_spec.rb
|
@@ -274,6 +277,7 @@ test_files:
|
|
274
277
|
- spec/rubocop/cop/rspec/around_block_spec.rb
|
275
278
|
- spec/rubocop/cop/rspec/be_eql_spec.rb
|
276
279
|
- spec/rubocop/cop/rspec/before_after_all_spec.rb
|
280
|
+
- spec/rubocop/cop/rspec/capybara/feature_methods_spec.rb
|
277
281
|
- spec/rubocop/cop/rspec/cop_spec.rb
|
278
282
|
- spec/rubocop/cop/rspec/describe_class_spec.rb
|
279
283
|
- spec/rubocop/cop/rspec/describe_method_spec.rb
|