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
0d4d9a6a
Commit
0d4d9a6a
authored
May 31, 2017
by
Gabriel Mazetto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor and move things around to improve in YAGNI perspective
parent
d219f9a6
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
91 additions
and
102 deletions
+91
-102
lib/system_check/base_executor.rb
lib/system_check/base_executor.rb
+0
-24
lib/system_check/simple_executor.rb
lib/system_check/simple_executor.rb
+23
-1
spec/lib/system_check/base_executor_spec.rb
spec/lib/system_check/base_executor_spec.rb
+0
-53
spec/lib/system_check/simple_executor_spec.rb
spec/lib/system_check/simple_executor_spec.rb
+44
-0
spec/lib/system_check_spec.rb
spec/lib/system_check_spec.rb
+19
-23
spec/support/matchers/execute_check.rb
spec/support/matchers/execute_check.rb
+5
-1
No files found.
lib/system_check/base_executor.rb
deleted
100644 → 0
View file @
d219f9a6
module
SystemCheck
# @attr_reader [Array<BaseCheck>] checks classes of corresponding checks to be executed in the same order
# @attr_reader [String] component name of the component relative to the checks being executed
class
BaseExecutor
attr_reader
:checks
attr_reader
:component
# @param [String] component name of the component relative to the checks being executed
def
initialize
(
component
)
raise
ArgumentError
unless
component
.
is_a?
String
@component
=
component
@checks
=
Set
.
new
end
# Add a check to be executed
#
# @param [BaseCheck] check class
def
<<
(
check
)
raise
ArgumentError
unless
check
<
BaseCheck
@checks
<<
check
end
end
end
lib/system_check/simple_executor.rb
View file @
0d4d9a6a
...
@@ -4,7 +4,29 @@ module SystemCheck
...
@@ -4,7 +4,29 @@ module SystemCheck
#
#
# There is no concurrency level and the output is progressively
# There is no concurrency level and the output is progressively
# printed into the STDOUT
# printed into the STDOUT
class
SimpleExecutor
<
BaseExecutor
#
# @attr_reader [Array<BaseCheck>] checks classes of corresponding checks to be executed in the same order
# @attr_reader [String] component name of the component relative to the checks being executed
class
SimpleExecutor
attr_reader
:checks
attr_reader
:component
# @param [String] component name of the component relative to the checks being executed
def
initialize
(
component
)
raise
ArgumentError
unless
component
.
is_a?
String
@component
=
component
@checks
=
Set
.
new
end
# Add a check to be executed
#
# @param [BaseCheck] check class
def
<<
(
check
)
raise
ArgumentError
unless
check
<
BaseCheck
@checks
<<
check
end
# Executes defined checks in the specified order and outputs confirmation or error information
# Executes defined checks in the specified order and outputs confirmation or error information
def
execute
def
execute
start_checking
(
component
)
start_checking
(
component
)
...
...
spec/lib/system_check/base_executor_spec.rb
deleted
100644 → 0
View file @
d219f9a6
require
'spec_helper'
describe
SystemCheck
::
BaseExecutor
,
lib:
true
do
class
SimpleCheck
<
SystemCheck
::
BaseCheck
def
check?
true
end
end
class
OtherCheck
<
SystemCheck
::
BaseCheck
def
check?
false
end
end
subject
{
described_class
.
new
(
'Test'
)
}
describe
'#component'
do
it
'returns stored component name'
do
expect
(
subject
.
component
).
to
eq
(
'Test'
)
end
end
describe
'#checks'
do
before
do
subject
<<
SimpleCheck
end
it
'returns a set of classes'
do
expect
(
subject
.
checks
).
to
include
(
SimpleCheck
)
end
end
describe
'#<<'
do
before
do
subject
<<
SimpleCheck
end
it
'appends a new check to the Set'
do
subject
<<
OtherCheck
stored_checks
=
subject
.
checks
.
to_a
expect
(
stored_checks
.
first
).
to
eq
(
SimpleCheck
)
expect
(
stored_checks
.
last
).
to
eq
(
OtherCheck
)
end
it
'inserts unique itens only'
do
subject
<<
SimpleCheck
expect
(
subject
.
checks
.
size
).
to
eq
(
1
)
end
end
end
spec/lib/system_check/simple_executor_spec.rb
View file @
0d4d9a6a
...
@@ -75,6 +75,42 @@ describe SystemCheck::SimpleExecutor, lib: true do
...
@@ -75,6 +75,42 @@ describe SystemCheck::SimpleExecutor, lib: true do
end
end
end
end
describe
'#component'
do
it
'returns stored component name'
do
expect
(
subject
.
component
).
to
eq
(
'Test'
)
end
end
describe
'#checks'
do
before
do
subject
<<
SimpleCheck
end
it
'returns a set of classes'
do
expect
(
subject
.
checks
).
to
include
(
SimpleCheck
)
end
end
describe
'#<<'
do
before
do
subject
<<
SimpleCheck
end
it
'appends a new check to the Set'
do
subject
<<
OtherCheck
stored_checks
=
subject
.
checks
.
to_a
expect
(
stored_checks
.
first
).
to
eq
(
SimpleCheck
)
expect
(
stored_checks
.
last
).
to
eq
(
OtherCheck
)
end
it
'inserts unique itens only'
do
subject
<<
SimpleCheck
expect
(
subject
.
checks
.
size
).
to
eq
(
1
)
end
end
subject
{
described_class
.
new
(
'Test'
)
}
subject
{
described_class
.
new
(
'Test'
)
}
describe
'#execute'
do
describe
'#execute'
do
...
@@ -120,6 +156,7 @@ describe SystemCheck::SimpleExecutor, lib: true do
...
@@ -120,6 +156,7 @@ describe SystemCheck::SimpleExecutor, lib: true do
context
'when check implements #repair!'
do
context
'when check implements #repair!'
do
it
'executes #repair!'
do
it
'executes #repair!'
do
expect_any_instance_of
(
RepairCheck
).
to
receive
(
:repair!
)
expect_any_instance_of
(
RepairCheck
).
to
receive
(
:repair!
)
subject
.
run_check
(
RepairCheck
)
subject
.
run_check
(
RepairCheck
)
end
end
...
@@ -127,6 +164,7 @@ describe SystemCheck::SimpleExecutor, lib: true do
...
@@ -127,6 +164,7 @@ describe SystemCheck::SimpleExecutor, lib: true do
it
'does not execute #show_error'
do
it
'does not execute #show_error'
do
expect_any_instance_of
(
RepairCheck
).
to
receive
(
:repair!
).
and_call_original
expect_any_instance_of
(
RepairCheck
).
to
receive
(
:repair!
).
and_call_original
expect_any_instance_of
(
RepairCheck
).
not_to
receive
(
:show_error
)
expect_any_instance_of
(
RepairCheck
).
not_to
receive
(
:show_error
)
subject
.
run_check
(
RepairCheck
)
subject
.
run_check
(
RepairCheck
)
end
end
end
end
...
@@ -135,6 +173,7 @@ describe SystemCheck::SimpleExecutor, lib: true do
...
@@ -135,6 +173,7 @@ describe SystemCheck::SimpleExecutor, lib: true do
it
'does not execute #show_error'
do
it
'does not execute #show_error'
do
expect_any_instance_of
(
RepairCheck
).
to
receive
(
:repair!
)
{
false
}
expect_any_instance_of
(
RepairCheck
).
to
receive
(
:repair!
)
{
false
}
expect_any_instance_of
(
RepairCheck
).
to
receive
(
:show_error
)
expect_any_instance_of
(
RepairCheck
).
to
receive
(
:show_error
)
subject
.
run_check
(
RepairCheck
)
subject
.
run_check
(
RepairCheck
)
end
end
end
end
...
@@ -144,6 +183,7 @@ describe SystemCheck::SimpleExecutor, lib: true do
...
@@ -144,6 +183,7 @@ describe SystemCheck::SimpleExecutor, lib: true do
context
'when check implements skip?'
do
context
'when check implements skip?'
do
it
'executes #skip? method'
do
it
'executes #skip? method'
do
expect_any_instance_of
(
SkipCheck
).
to
receive
(
:skip?
).
and_call_original
expect_any_instance_of
(
SkipCheck
).
to
receive
(
:skip?
).
and_call_original
subject
.
run_check
(
SkipCheck
)
subject
.
run_check
(
SkipCheck
)
end
end
...
@@ -153,6 +193,7 @@ describe SystemCheck::SimpleExecutor, lib: true do
...
@@ -153,6 +193,7 @@ describe SystemCheck::SimpleExecutor, lib: true do
it
'does not execute #check when #skip? is true'
do
it
'does not execute #check when #skip? is true'
do
expect_any_instance_of
(
SkipCheck
).
not_to
receive
(
:check?
)
expect_any_instance_of
(
SkipCheck
).
not_to
receive
(
:check?
)
subject
.
run_check
(
SkipCheck
)
subject
.
run_check
(
SkipCheck
)
end
end
end
end
...
@@ -160,17 +201,20 @@ describe SystemCheck::SimpleExecutor, lib: true do
...
@@ -160,17 +201,20 @@ describe SystemCheck::SimpleExecutor, lib: true do
context
'when implements a #multi_check'
do
context
'when implements a #multi_check'
do
it
'executes #multi_check method'
do
it
'executes #multi_check method'
do
expect_any_instance_of
(
MultiCheck
).
to
receive
(
:multi_check
)
expect_any_instance_of
(
MultiCheck
).
to
receive
(
:multi_check
)
subject
.
run_check
(
MultiCheck
)
subject
.
run_check
(
MultiCheck
)
end
end
it
'does not execute #check method'
do
it
'does not execute #check method'
do
expect_any_instance_of
(
MultiCheck
).
not_to
receive
(
:check
)
expect_any_instance_of
(
MultiCheck
).
not_to
receive
(
:check
)
subject
.
run_check
(
MultiCheck
)
subject
.
run_check
(
MultiCheck
)
end
end
context
'when check implements #skip?'
do
context
'when check implements #skip?'
do
it
'executes #skip? method'
do
it
'executes #skip? method'
do
expect_any_instance_of
(
SkipMultiCheck
).
to
receive
(
:skip?
).
and_call_original
expect_any_instance_of
(
SkipMultiCheck
).
to
receive
(
:skip?
).
and_call_original
subject
.
run_check
(
SkipMultiCheck
)
subject
.
run_check
(
SkipMultiCheck
)
end
end
end
end
...
...
spec/lib/system_check_spec.rb
View file @
0d4d9a6a
...
@@ -2,39 +2,35 @@ require 'spec_helper'
...
@@ -2,39 +2,35 @@ require 'spec_helper'
require
'rake_helper'
require
'rake_helper'
describe
SystemCheck
,
lib:
true
do
describe
SystemCheck
,
lib:
true
do
subject
{
SystemCheck
}
class
SimpleCheck
<
SystemCheck
::
BaseCheck
def
check?
true
end
end
class
OtherCheck
<
SystemCheck
::
BaseCheck
def
check?
false
end
end
before
do
before
do
silence_output
silence_output
end
end
describe
'.run'
do
describe
'.run'
do
context
'custom matcher'
do
subject
{
SystemCheck
}
class
SimpleCheck
<
SystemCheck
::
BaseCheck
def
check?
true
end
end
class
OtherCheck
<
SystemCheck
::
BaseCheck
def
check?
false
end
end
subject
{
SystemCheck
}
it
'detects execution of SimpleCheck'
do
is_expected
.
to
execute_check
(
SimpleCheck
)
it
'detects execution of SimpleCheck'
do
subject
.
run
(
'Test'
,
[
SimpleCheck
])
is_expected
.
to
execute_check
(
SimpleCheck
)
end
SystemCheck
.
run
(
'Test'
,
[
SimpleCheck
])
end
it
'detects exclusion of OtherCheck in execution'
do
it
'detects exclusion of OtherCheck in execution'
do
is_expected
.
not_to
execute_check
(
OtherCheck
)
is_expected
.
not_to
execute_check
(
OtherCheck
)
SystemCheck
.
run
(
'Test'
,
[
SimpleCheck
])
subject
.
run
(
'Test'
,
[
SimpleCheck
])
end
end
end
end
end
end
end
spec/support/matchers/execute_check.rb
View file @
0d4d9a6a
...
@@ -14,6 +14,10 @@ RSpec::Matchers.define :execute_check do |expected|
...
@@ -14,6 +14,10 @@ RSpec::Matchers.define :execute_check do |expected|
end
end
failure_message
do
|
actual
|
failure_message
do
|
actual
|
return
'This matcher must be used with SystemCheck'
unless
actual
==
SystemCheck
'This matcher must be used with SystemCheck'
unless
actual
==
SystemCheck
end
failure_message_when_negated
do
|
actual
|
'This matcher must be used with SystemCheck'
unless
actual
==
SystemCheck
end
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