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
73b9cbf6
Commit
73b9cbf6
authored
Dec 22, 2017
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add domain specific language to define QA page elements
parent
cc677900
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
88 additions
and
0 deletions
+88
-0
qa/qa/page/base.rb
qa/qa/page/base.rb
+21
-0
qa/qa/page/element.rb
qa/qa/page/element.rb
+26
-0
qa/qa/page/view.rb
qa/qa/page/view.rb
+6
-0
qa/spec/page/base_spec.rb
qa/spec/page/base_spec.rb
+35
-0
No files found.
qa/qa/page/base.rb
View file @
73b9cbf6
...
...
@@ -5,6 +5,9 @@ module QA
class
Base
include
Capybara
::
DSL
include
Scenario
::
Actable
extend
SingleForwardable
def_delegators
:evaluator
,
:view
,
:views
def
refresh
visit
current_url
...
...
@@ -40,6 +43,24 @@ module QA
def
self
.
path
raise
NotImplementedError
end
def
self
.
evaluator
@evaluator
||=
Page
::
Base
::
DSL
.
new
end
class
DSL
attr_reader
:views
def
initialize
@views
=
[]
end
def
view
(
path
,
&
block
)
Page
::
Element
.
evaluate
(
&
block
).
tap
do
|
elements
|
@views
.
push
(
Page
::
View
.
new
(
path
,
elements
))
end
end
end
end
end
end
qa/qa/page/element.rb
View file @
73b9cbf6
module
QA
module
Page
class
Element
attr_reader
:name
def
initialize
(
name
,
pattern
)
@name
=
name
@pattern
=
pattern
end
def
self
.
evaluate
(
&
block
)
Page
::
Element
::
DSL
.
new
.
tap
do
|
evaluator
|
evaluator
.
instance_exec
(
&
block
)
return
evaluator
.
elements
end
end
class
DSL
attr_reader
:elements
def
initialize
@elements
=
[]
end
def
element
(
name
,
pattern
)
@elements
.
push
(
Page
::
Element
.
new
(
name
,
pattern
))
end
end
end
end
end
qa/qa/page/view.rb
View file @
73b9cbf6
module
QA
module
Page
class
View
attr_reader
:path
,
:elements
def
initialize
(
path
,
elements
)
@path
=
path
@elements
=
elements
end
end
end
end
qa/spec/page/base_spec.rb
0 → 100644
View file @
73b9cbf6
describe
QA
::
Page
::
Base
do
describe
'page helpers'
do
it
'exposes helpful page helpers'
do
expect
(
subject
).
to
respond_to
:refresh
,
:wait
,
:scroll_to
end
end
describe
'DSL for defining view partials'
,
'.view'
do
subject
do
Class
.
new
(
described_class
)
do
view
'path/to/some/view.html.haml'
do
element
:something
,
'string pattern'
element
:something_else
,
/regexp pattern/
end
view
'path/to/some/_partial.html.haml'
do
element
:something
,
'string pattern'
end
end
end
it
'makes it possible to define page views'
do
expect
(
subject
.
views
.
size
).
to
eq
2
expect
(
subject
.
views
).
to
all
(
be_an_instance_of
QA
::
Page
::
View
)
end
it
'populates views objects with data about elements'
do
subject
.
views
.
first
.
elements
.
tap
do
|
elements
|
expect
(
elements
.
size
).
to
eq
2
expect
(
elements
).
to
all
(
be_an_instance_of
QA
::
Page
::
Element
)
expect
(
elements
.
map
(
&
:name
)).
to
eq
[
:something
,
:something_else
]
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