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
8ff44fcb
Commit
8ff44fcb
authored
Apr 18, 2018
by
Jacopo
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Uses the rubocop helpers expect_offense and expect_no_offenses
parent
b752ee4a
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
69 deletions
+18
-69
spec/rubocop/cop/avoid_break_from_strong_memoize_spec.rb
spec/rubocop/cop/avoid_break_from_strong_memoize_spec.rb
+7
-25
spec/rubocop/cop/avoid_return_from_blocks_spec.rb
spec/rubocop/cop/avoid_return_from_blocks_spec.rb
+11
-44
No files found.
spec/rubocop/cop/avoid_break_from_strong_memoize_spec.rb
View file @
8ff44fcb
...
...
@@ -9,60 +9,45 @@ describe RuboCop::Cop::AvoidBreakFromStrongMemoize do
subject
(
:cop
)
{
described_class
.
new
}
it
'flags violation for break inside strong_memoize'
do
source
=
<<~
RUBY
expect_offense
(
<<~
RUBY
)
strong_memoize(:result) do
break if something
^^^^^ Do not use break inside strong_memoize, use next instead.
do_an_heavy_calculation
end
RUBY
inspect_source
(
source
)
expect
(
cop
.
offenses
.
size
).
to
eq
(
1
)
offense
=
cop
.
offenses
.
first
expect
(
offense
.
line
).
to
eq
(
2
)
expect
(
cop
.
highlights
).
to
eq
([
'break'
])
expect
(
offense
.
message
).
to
eq
(
'Do not use break inside strong_memoize, use next instead.'
)
end
it
'flags violation for break inside strong_memoize nested blocks'
do
source
=
<<~
RUBY
expect_offense
(
<<~
RUBY
)
strong_memoize do
items.each do |item|
break item
^^^^^^^^^^ Do not use break inside strong_memoize, use next instead.
end
end
RUBY
inspect_source
(
source
)
expect
(
cop
.
offenses
.
size
).
to
eq
(
1
)
end
it
"doesn't flag violation for next inside strong_memoize"
do
source
=
<<~
RUBY
expect_no_offenses
(
<<~
RUBY
)
strong_memoize(:result) do
next if something
do_an_heavy_calculation
end
RUBY
inspect_source
(
source
)
expect
(
cop
.
offenses
).
to
be_empty
end
it
"doesn't flag violation for break inside blocks"
do
source
=
<<~
RUBY
expect_no_offenses
(
<<~
RUBY
)
call do
break if something
do_an_heavy_calculation
end
RUBY
inspect_source
(
source
)
expect
(
cop
.
offenses
).
to
be_empty
end
it
"doesn't call add_offense twice for nested blocks"
do
...
...
@@ -81,12 +66,9 @@ describe RuboCop::Cop::AvoidBreakFromStrongMemoize do
end
it
"doesn't check when block is empty"
do
source
=
<<~
RUBY
expect_no_offenses
(
<<~
RUBY
)
strong_memoize(:result) do
end
RUBY
inspect_source
(
source
)
expect
(
cop
.
offenses
).
to
be_empty
end
end
spec/rubocop/cop/avoid_return_from_blocks_spec.rb
View file @
8ff44fcb
...
...
@@ -9,20 +9,13 @@ describe RuboCop::Cop::AvoidReturnFromBlocks do
subject
(
:cop
)
{
described_class
.
new
}
it
'flags violation for return inside a block'
do
source
=
<<~
RUBY
expect_offense
(
<<~
RUBY
)
call do
do_something
return if something_else
^^^^^^ Do not return from a block, use next or break instead.
end
RUBY
inspect_source
(
source
)
expect
(
cop
.
offenses
.
size
).
to
eq
(
1
)
offense
=
cop
.
offenses
.
first
expect
(
offense
.
line
).
to
eq
(
3
)
expect
(
cop
.
highlights
).
to
eq
([
'return'
])
expect
(
offense
.
message
).
to
eq
(
'Do not return from a block, use next or break instead.'
)
end
it
"doesn't call add_offense twice for nested blocks"
do
...
...
@@ -40,36 +33,28 @@ describe RuboCop::Cop::AvoidReturnFromBlocks do
end
it
'flags violation for return inside included > def > block'
do
source
=
<<~
RUBY
expect_offense
(
<<~
RUBY
)
included do
def a_method
return if something
call do
return if something_else
^^^^^^ Do not return from a block, use next or break instead.
end
end
end
RUBY
inspect_source
(
source
)
expect
(
cop
.
offenses
.
size
).
to
eq
(
1
)
offense
=
cop
.
offenses
.
first
expect
(
offense
.
line
).
to
eq
(
6
)
end
shared_examples
'examples with whitelisted method'
do
|
whitelisted_method
|
it
"doesn't flag violation for return inside
#{
whitelisted_method
}
"
do
source
=
<<~
RUBY
expect_no_offenses
(
<<~
RUBY
)
items.
#{
whitelisted_method
}
do |item|
do_something
return if something_else
end
RUBY
inspect_source
(
source
)
expect
(
cop
.
offenses
).
to
be_empty
end
end
...
...
@@ -79,7 +64,7 @@ describe RuboCop::Cop::AvoidReturnFromBlocks do
shared_examples
'examples with def methods'
do
|
def_method
|
it
"doesn't flag violation for return inside
#{
def_method
}
"
do
source
=
<<~
RUBY
expect_no_offenses
(
<<~
RUBY
)
helpers do
#{
def_method
}
do
return if something
...
...
@@ -88,9 +73,6 @@ describe RuboCop::Cop::AvoidReturnFromBlocks do
end
end
RUBY
inspect_source
(
source
)
expect
(
cop
.
offenses
).
to
be_empty
end
end
...
...
@@ -99,19 +81,16 @@ describe RuboCop::Cop::AvoidReturnFromBlocks do
end
it
"doesn't flag violation for return inside a lambda"
do
source
=
<<~
RUBY
expect_no_offenses
(
<<~
RUBY
)
lambda do
do_something
return if something_else
end
RUBY
inspect_source
(
source
)
expect
(
cop
.
offenses
).
to
be_empty
end
it
"doesn't flag violation for return used inside a method definition"
do
source
=
<<~
RUBY
expect_no_offenses
(
<<~
RUBY
)
describe Klass do
def a_method
do_something
...
...
@@ -119,42 +98,30 @@ describe RuboCop::Cop::AvoidReturnFromBlocks do
end
end
RUBY
inspect_source
(
source
)
expect
(
cop
.
offenses
).
to
be_empty
end
it
"doesn't flag violation for next inside a block"
do
source
=
<<~
RUBY
expect_no_offenses
(
<<~
RUBY
)
call do
do_something
next if something_else
end
RUBY
inspect_source
(
source
)
expect
(
cop
.
offenses
).
to
be_empty
end
it
"doesn't flag violation for break inside a block"
do
source
=
<<~
RUBY
expect_no_offenses
(
<<~
RUBY
)
call do
do_something
break if something_else
end
RUBY
inspect_source
(
source
)
expect
(
cop
.
offenses
).
to
be_empty
end
it
"doesn't check when block is empty"
do
source
=
<<~
RUBY
expect_no_offenses
(
<<~
RUBY
)
call do
end
RUBY
inspect_source
(
source
)
expect
(
cop
.
offenses
).
to
be_empty
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