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
8e5d5d3d
Commit
8e5d5d3d
authored
Dec 22, 2017
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use composite pattern to return page view errors
parent
39892f8d
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
64 additions
and
30 deletions
+64
-30
qa/qa/page/base.rb
qa/qa/page/base.rb
+2
-2
qa/qa/page/element.rb
qa/qa/page/element.rb
+6
-7
qa/qa/page/validator.rb
qa/qa/page/validator.rb
+0
-18
qa/qa/page/view.rb
qa/qa/page/view.rb
+2
-2
qa/spec/page/base_spec.rb
qa/spec/page/base_spec.rb
+16
-1
qa/spec/page/element_spec.rb
qa/spec/page/element_spec.rb
+34
-0
qa/spec/page/view_spec.rb
qa/spec/page/view_spec.rb
+4
-0
No files found.
qa/qa/page/base.rb
View file @
8e5d5d3d
...
...
@@ -48,8 +48,8 @@ module QA
@evaluator
||=
Page
::
Base
::
DSL
.
new
end
def
self
.
validator
Page
::
Validator
.
new
(
self
)
def
self
.
errors
@errors
||=
views
.
map
(
&
:errors
).
flatten
end
class
DSL
...
...
qa/qa/page/element.rb
View file @
8e5d5d3d
...
...
@@ -8,15 +8,14 @@ module QA
@pattern
=
pattern
end
def
expression?
@pattern
.
is_a?
(
Regexp
)
end
def
matches?
(
line
)
if
expression?
line
=~
pattern
case
@pattern
when
Regexp
!!
(
line
=~
@pattern
)
when
String
line
.
include?
(
@pattern
)
else
line
.
includes?
(
pattern
)
raise
ArgumentError
,
'Pattern should be either String or Regexp!'
end
end
end
...
...
qa/qa/page/validator.rb
deleted
100644 → 0
View file @
39892f8d
module
QA
module
Page
class
Validator
def
initialize
(
page
)
@page
=
page
@views
=
page
.
views
end
def
errors
@errors
||=
@views
.
map
do
|
view
|
end
end
def
message
end
end
end
end
qa/qa/page/view.rb
View file @
8e5d5d3d
...
...
@@ -15,8 +15,8 @@ module QA
def
errors
##
# Reduce required elements by streaming view
s
and making assertions on
# elements'
patterns
.
# Reduce required elements by streaming view and making assertions on
# elements'
existence
.
#
@missing
||=
@elements
.
dup
.
tap
do
|
elements
|
File
.
new
(
pathname
.
to_s
).
foreach
do
|
line
|
...
...
qa/spec/page/base_spec.rb
View file @
8e5d5d3d
...
...
@@ -5,7 +5,7 @@ describe QA::Page::Base do
end
end
describe
'
DSL for defining view partials'
,
'.view
'
do
describe
'
.view'
,
'DSL for defining view partials
'
do
subject
do
Class
.
new
(
described_class
)
do
view
'path/to/some/view.html.haml'
do
...
...
@@ -32,4 +32,19 @@ describe QA::Page::Base do
end
end
end
describe
'.errors'
do
let
(
:view
)
{
double
(
'view'
)
}
before
do
allow
(
described_class
).
to
receive
(
:views
)
.
and_return
([
view
])
allow
(
view
).
to
receive
(
:errors
).
and_return
([
'some error'
])
end
it
'iterates views composite and returns errors'
do
expect
(
described_class
.
errors
).
to
eq
[
'some error'
]
end
end
end
qa/spec/page/element_spec.rb
0 → 100644
View file @
8e5d5d3d
describe
QA
::
Page
::
Element
do
context
'when pattern is an expression'
do
subject
{
described_class
.
new
(
:something
,
/button 'Sign in'/
)
}
it
'is correctly matches against a string'
do
expect
(
subject
.
matches?
(
"button 'Sign in'"
)).
to
be
true
end
it
'does not match if string does not match against a pattern'
do
expect
(
subject
.
matches?
(
"button 'Sign out'"
)).
to
be
false
end
end
context
'when pattern is a string'
do
subject
{
described_class
.
new
(
:something
,
'button'
)
}
it
'is correctly matches against a string'
do
expect
(
subject
.
matches?
(
'some button in the view'
)).
to
be
true
end
it
'does not match if string does not match against a pattern'
do
expect
(
subject
.
matches?
(
'text_field :name'
)).
to
be
false
end
end
context
'when pattern is not supported'
do
subject
{
described_class
.
new
(
:something
,
[
/something/
])
}
it
'raises an error'
do
expect
{
subject
.
matches?
(
'some line'
)
}
.
to
raise_error
ArgumentError
end
end
end
qa/spec/page/view_spec.rb
View file @
8e5d5d3d
...
...
@@ -57,5 +57,9 @@ describe QA::Page::View do
.
to
match
%r(Missing element `.*` in `.*/some/file.html` view)
end
end
context
'when view partial has not been found'
do
pending
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