Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
ebf50fc7
Commit
ebf50fc7
authored
Aug 28, 2019
by
GitLab Bot
Browse files
Options
Browse Files
Download
Plain Diff
Automatic merge of gitlab-org/gitlab-ce master
parents
9c1ff791
a58bf655
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
126 additions
and
0 deletions
+126
-0
.rubocop.yml
.rubocop.yml
+9
-0
rubocop/cop/rspec/be_success_matcher.rb
rubocop/cop/rspec/be_success_matcher.rb
+53
-0
rubocop/rubocop.rb
rubocop/rubocop.rb
+1
-0
spec/rubocop/cop/rspec/be_success_matcher_spec.rb
spec/rubocop/cop/rspec/be_success_matcher_spec.rb
+63
-0
No files found.
.rubocop.yml
View file @
ebf50fc7
...
...
@@ -268,3 +268,12 @@ RSpec/EnvAssignment:
-
'
ee/spec/**/rails_helper.rb'
-
'
spec/**/spec_helper.rb'
-
'
ee/spec/**/spec_helper.rb'
RSpec/BeSuccessMatcher
:
Enabled
:
true
Include
:
-
'
spec/controllers/**/*'
-
'
ee/spec/controllers/**/*'
-
'
spec/support/shared_examples/controllers/**/*'
-
'
ee/spec/support/shared_examples/controllers/**/*'
-
'
spec/support/controllers/**/*'
-
'
ee/spec/support/controllers/**/*'
rubocop/cop/rspec/be_success_matcher.rb
0 → 100644
View file @
ebf50fc7
# frozen_string_literal: true
module
RuboCop
module
Cop
module
RSpec
# This cop checks for `be_success` usage in controller specs
#
# @example
#
# # bad
# it "responds with success" do
# expect(response).to be_success
# end
#
# it { is_expected.to be_success }
#
# # good
# it "responds with success" do
# expect(response).to be_successful
# end
#
# it { is_expected.to be_successful }
#
class
BeSuccessMatcher
<
RuboCop
::
Cop
::
Cop
MESSAGE
=
'Do not use deprecated `success?` method, use `successful?` instead.'
def_node_search
:expect_to_be_success?
,
<<~
PATTERN
(send (send nil? :expect (send nil? ...)) {:to :not_to :to_not} (send nil? :be_success))
PATTERN
def_node_search
:is_expected_to_be_success?
,
<<~
PATTERN
(send (send nil? :is_expected) {:to :not_to :to_not} (send nil? :be_success))
PATTERN
def
be_success_usage?
(
node
)
expect_to_be_success?
(
node
)
||
is_expected_to_be_success?
(
node
)
end
def
on_send
(
node
)
return
unless
be_success_usage?
(
node
)
add_offense
(
node
,
location: :expression
,
message:
MESSAGE
)
end
def
autocorrect
(
node
)
lambda
do
|
corrector
|
corrector
.
insert_after
(
node
.
loc
.
expression
,
'ful'
)
end
end
end
end
end
end
rubocop/rubocop.rb
View file @
ebf50fc7
...
...
@@ -31,6 +31,7 @@ require_relative 'cop/migration/timestamps'
require_relative
'cop/migration/update_column_in_batches'
require_relative
'cop/migration/update_large_table'
require_relative
'cop/project_path_helper'
require_relative
'cop/rspec/be_success_matcher'
require_relative
'cop/rspec/env_assignment'
require_relative
'cop/rspec/factories_in_migration_specs'
require_relative
'cop/rspec/top_level_describe_path'
...
...
spec/rubocop/cop/rspec/be_success_matcher_spec.rb
0 → 100644
View file @
ebf50fc7
# frozen_string_literal: true
require
'spec_helper'
require_relative
'../../../../rubocop/cop/rspec/be_success_matcher'
describe
RuboCop
::
Cop
::
RSpec
::
BeSuccessMatcher
do
include
CopHelper
let
(
:source_file
)
{
'spec/foo_spec.rb'
}
subject
(
:cop
)
{
described_class
.
new
}
shared_examples
'cop'
do
|
good
:,
bad
:|
context
"using
#{
bad
}
call"
do
it
'registers an offense'
do
inspect_source
(
bad
,
source_file
)
expect
(
cop
.
offenses
.
size
).
to
eq
(
1
)
expect
(
cop
.
offenses
.
map
(
&
:line
)).
to
eq
([
1
])
expect
(
cop
.
highlights
).
to
eq
([
bad
])
end
it
"autocorrects it to `
#{
good
}
`"
do
autocorrected
=
autocorrect_source
(
bad
,
source_file
)
expect
(
autocorrected
).
to
eql
(
good
)
end
end
context
"using
#{
good
}
call"
do
it
'does not register an offense'
do
inspect_source
(
good
)
expect
(
cop
.
offenses
).
to
be_empty
end
end
end
include_examples
'cop'
,
bad:
'expect(response).to be_success'
,
good:
'expect(response).to be_successful'
include_examples
'cop'
,
bad:
'expect(response).to_not be_success'
,
good:
'expect(response).to_not be_successful'
include_examples
'cop'
,
bad:
'expect(response).not_to be_success'
,
good:
'expect(response).not_to be_successful'
include_examples
'cop'
,
bad:
'is_expected.to be_success'
,
good:
'is_expected.to be_successful'
include_examples
'cop'
,
bad:
'is_expected.to_not be_success'
,
good:
'is_expected.to_not be_successful'
include_examples
'cop'
,
bad:
'is_expected.not_to be_success'
,
good:
'is_expected.not_to be_successful'
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment