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
f759aae3
Commit
f759aae3
authored
Jan 08, 2021
by
Albert Salim
Committed by
Markus Koller
Jan 08, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add RuboCop check for WebMock.disable_net_connect!
parent
486939a0
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
69 additions
and
0 deletions
+69
-0
.rubocop.yml
.rubocop.yml
+8
-0
rubocop/cop/rspec/web_mock_enable.rb
rubocop/cop/rspec/web_mock_enable.rb
+39
-0
spec/rubocop/cop/rspec/web_mock_enable_spec.rb
spec/rubocop/cop/rspec/web_mock_enable_spec.rb
+22
-0
No files found.
.rubocop.yml
View file @
f759aae3
...
...
@@ -326,6 +326,14 @@ RSpec/TimecopTravel:
-
'
ee/spec/**/*.rb'
-
'
qa/spec/**/*.rb'
RSpec/WebMockEnable
:
Enabled
:
true
Include
:
-
'
spec/**/*.rb'
-
'
ee/spec/**/*.rb'
Exclude
:
-
'
spec/support/webmock.rb'
Naming/PredicateName
:
Enabled
:
true
Exclude
:
...
...
rubocop/cop/rspec/web_mock_enable.rb
0 → 100644
View file @
f759aae3
# frozen_string_literal: true
module
RuboCop
module
Cop
module
RSpec
class
WebMockEnable
<
RuboCop
::
Cop
::
Cop
# This cop checks for `WebMock.disable_net_connect!` usage in specs and
# replaces it with `webmock_enable!`
#
# @example
#
# # bad
# WebMock.disable_net_connect!
# WebMock.disable_net_connect!(allow_localhost: true)
#
# # good
# webmock_enable!
MESSAGE
=
'Use webmock_enable! instead of calling WebMock.disable_net_connect! directly.'
def_node_matcher
:webmock_disable_net_connect?
,
<<~
PATTERN
(send (const nil? :WebMock) :disable_net_connect! ...)
PATTERN
def
on_send
(
node
)
if
webmock_disable_net_connect?
(
node
)
add_offense
(
node
,
location: :expression
,
message:
MESSAGE
)
end
end
def
autocorrect
(
node
)
lambda
do
|
corrector
|
corrector
.
replace
(
node
,
'webmock_enable!'
)
end
end
end
end
end
end
spec/rubocop/cop/rspec/web_mock_enable_spec.rb
0 → 100644
View file @
f759aae3
# frozen_string_literal: true
require
'fast_spec_helper'
require_relative
'../../../../rubocop/cop/rspec/web_mock_enable'
RSpec
.
describe
RuboCop
::
Cop
::
RSpec
::
WebMockEnable
do
subject
(
:cop
)
{
described_class
.
new
}
context
'when calling WebMock.disable_net_connect!'
do
it
'registers an offence and autocorrects it'
do
expect_offense
(
<<~
RUBY
)
WebMock.disable_net_connect!(allow_localhost: true)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Use webmock_enable! instead of calling WebMock.disable_net_connect! directly.
RUBY
expect_correction
(
<<~
RUBY
)
webmock_enable!
RUBY
end
end
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