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
0
Merge Requests
0
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
Boxiang Sun
gitlab-ce
Commits
a3ab8aa3
Commit
a3ab8aa3
authored
Jan 11, 2018
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Populate QA factory product with data from a page
parent
d32a1517
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
37 additions
and
31 deletions
+37
-31
qa/qa/factory/base.rb
qa/qa/factory/base.rb
+3
-1
qa/qa/factory/product.rb
qa/qa/factory/product.rb
+8
-7
qa/spec/factory/base_spec.rb
qa/spec/factory/base_spec.rb
+24
-4
qa/spec/factory/product_spec.rb
qa/spec/factory/product_spec.rb
+2
-19
No files found.
qa/qa/factory/base.rb
View file @
a3ab8aa3
...
...
@@ -13,7 +13,7 @@ module QA
end
def
self
.
fabricate!
(
*
args
)
Factory
::
Product
.
populate!
(
new
)
do
|
factory
|
new
.
tap
do
|
factory
|
yield
factory
if
block_given?
dependencies
.
each
do
|
name
,
signature
|
...
...
@@ -21,6 +21,8 @@ module QA
end
factory
.
fabricate!
(
*
args
)
return
Factory
::
Product
.
populate!
(
self
)
end
end
...
...
qa/qa/factory/product.rb
View file @
a3ab8aa3
...
...
@@ -7,8 +7,7 @@ module QA
Attribute
=
Struct
.
new
(
:name
,
:block
)
def
initialize
(
factory
)
@factory
=
factory
def
initialize
@location
=
current_url
end
...
...
@@ -17,11 +16,13 @@ module QA
end
def
self
.
populate!
(
factory
)
raise
ArgumentError
unless
block_given?
yield
factory
new
(
factory
)
new
.
tap
do
|
product
|
factory
.
attributes
.
each_value
do
|
attribute
|
product
.
instance_exec
(
&
attribute
.
block
).
tap
do
|
value
|
product
.
define_singleton_method
(
attribute
.
name
)
{
value
}
end
end
end
end
end
end
...
...
qa/spec/factory/base_spec.rb
View file @
a3ab8aa3
describe
QA
::
Factory
::
Base
do
let
(
:factory
)
{
spy
(
'factory'
)
}
let
(
:product
)
{
spy
(
'product'
)
}
describe
'.fabricate!'
do
subject
{
Class
.
new
(
described_class
)
}
let
(
:factory
)
{
spy
(
'factory'
)
}
let
(
:product
)
{
spy
(
'product'
)
}
before
do
allow
(
QA
::
Factory
::
Product
).
to
receive
(
:new
).
and_return
(
product
)
...
...
@@ -89,14 +90,33 @@ describe QA::Factory::Base do
describe
'.product'
do
subject
do
Class
.
new
(
described_class
)
do
product
:token
do
|
factory
,
page
|
page
.
do_something!
product
:token
do
page
.
do_something_on_page!
'resulting value'
end
end
end
it
'appends new product attribute'
do
expect
(
subject
.
attributes
).
to
be_one
expect
(
subject
.
attributes
).
to
have_key
(
:token
)
end
describe
'populating fabrication product with data'
do
let
(
:page
)
{
spy
(
'page'
)
}
before
do
allow
(
subject
).
to
receive
(
:new
).
and_return
(
factory
)
allow
(
QA
::
Factory
::
Product
).
to
receive
(
:new
).
and_return
(
product
)
allow
(
product
).
to
receive
(
:page
).
and_return
(
page
)
end
it
'populates product after fabrication'
do
subject
.
fabricate!
expect
(
page
).
to
have_received
(
:do_something_on_page!
)
expect
(
product
.
token
).
to
eq
'resulting value'
end
end
end
end
qa/spec/factory/product_spec.rb
View file @
a3ab8aa3
...
...
@@ -3,19 +3,8 @@ describe QA::Factory::Product do
let
(
:product
)
{
spy
(
'product'
)
}
describe
'.populate!'
do
it
'instantiates and yields factory'
do
expect
(
described_class
).
to
receive
(
:new
).
with
(
factory
)
described_class
.
populate!
(
factory
)
do
|
instance
|
instance
.
something
=
'string'
end
expect
(
factory
).
to
have_received
(
:something
=
).
with
(
'string'
)
end
it
'returns a fabrication product'
do
expect
(
described_class
).
to
receive
(
:new
)
.
with
(
factory
).
and_return
(
product
)
expect
(
described_class
).
to
receive
(
:new
).
and_return
(
product
)
result
=
described_class
.
populate!
(
factory
)
do
|
instance
|
instance
.
something
=
'string'
...
...
@@ -23,11 +12,6 @@ describe QA::Factory::Product do
expect
(
result
).
to
be
product
end
it
'raises unless block given'
do
expect
{
described_class
.
populate!
(
factory
)
}
.
to
raise_error
ArgumentError
end
end
describe
'.visit!'
do
...
...
@@ -37,8 +21,7 @@ describe QA::Factory::Product do
allow_any_instance_of
(
described_class
)
.
to
receive
(
:visit
).
and_return
(
'visited some url'
)
expect
(
described_class
.
new
(
factory
).
visit!
)
.
to
eq
'visited some url'
expect
(
subject
.
visit!
).
to
eq
'visited some url'
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