Commit 7189804f authored by Sanad Liaquat's avatar Sanad Liaquat

Merge branch 'deduplicate-rspec-matchers' into 'master'

Reduce duplication of QA custom matchers

See merge request gitlab-org/gitlab!52721
parents e0d6ba0c f07f48aa
# frozen_string_literal: true
module Matchers
module HaveAssignee
RSpec::Matchers.define :have_assignee do |assignee|
match do |page_object|
page_object.has_assignee?(assignee)
end
match_when_negated do |page_object|
page_object.has_no_assignee?(assignee)
end
end
end
end
# frozen_string_literal: true
module Matchers
module HaveChildPipeline
RSpec::Matchers.define :have_child_pipeline do
match do |page_object|
page_object.has_child_pipeline?
end
match_when_negated do |page_object|
page_object.has_no_child_pipeline?
end
end
end
end
# frozen_string_literal: true
module Matchers
module HaveContent
RSpec::Matchers.define :have_content do |content|
match do |page_object|
page_object.has_content?(content)
end
match_when_negated do |page_object|
page_object.has_no_content?(content)
end
end
end
end
# frozen_string_literal: true
module Matchers
module HaveDesign
RSpec::Matchers.define :have_design do |design|
match do |page_object|
page_object.has_design?(design)
end
match_when_negated do |page_object|
page_object.has_no_design?(design)
end
end
end
end
# frozen_string_literal: true
module Matchers
module HaveElement
RSpec::Matchers.define :have_element do |element, **kwargs|
match do |page_object|
page_object.has_element?(element, **kwargs)
end
match_when_negated do |page_object|
page_object.has_no_element?(element, **kwargs)
end
end
end
end
# frozen_string_literal: true
module Matchers
module HaveFile
RSpec::Matchers.define :have_file do |file|
match do |page_object|
page_object.has_file?(file)
end
match_when_negated do |page_object|
page_object.has_no_file?(file)
end
end
end
end
# frozen_string_literal: true
module Matchers
module HaveFileContent
RSpec::Matchers.define :have_file_content do |file_content, file_number|
match do |page_object|
page_object.has_file_content?(file_content, file_number)
end
match_when_negated do |page_object|
page_object.has_no_file_content?(file_content, file_number)
end
end
end
end
# frozen_string_literal: true
module Matchers
module HaveIssue
RSpec::Matchers.define :have_issue do |issue|
match do |page_object|
page_object.has_issue?(issue)
end
match_when_negated do |page_object|
page_object.has_no_issue?(issue)
end
end
end
end
# frozen_string_literal: true
module Matchers
module HaveJob
RSpec::Matchers.define :have_job do |job|
match do |page_object|
page_object.has_job?(job)
end
match_when_negated do |page_object|
page_object.has_no_job?(job)
end
end
end
end
# frozen_string_literal: true
module Matchers
PREDICATE_TARGETS = %w[
element
file_content
assignee
child_pipeline
content
design
file
issue
job
package
pipeline
related_issue_item
snippet_description
].each do |predicate|
RSpec::Matchers.define "have_#{predicate}" do |*args, **kwargs|
match do |page_object|
page_object.public_send("has_#{predicate}?", *args, **kwargs) # rubocop:disable GitlabSecurity/PublicSend
end
match_when_negated do |page_object|
page_object.public_send("has_no_#{predicate}?", *args, **kwargs) # rubocop:disable GitlabSecurity/PublicSend
end
end
end
end
# frozen_string_literal: true
module Matchers
module HavePackage
RSpec::Matchers.define :have_package do |package|
match do |page_object|
page_object.has_package?(package)
end
match_when_negated do |page_object|
page_object.has_no_package?(package)
end
end
end
end
# frozen_string_literal: true
module Matchers
module HavePipeline
RSpec::Matchers.define :have_pipeline do
match do |page_object|
page_object.has_pipeline?
end
match_when_negated do |page_object|
page_object.has_no_pipeline?
end
end
end
end
# frozen_string_literal: true
module Matchers
module HaveRelatedIssueItem
RSpec::Matchers.define :have_related_issue_item do
match do |page_object|
page_object.has_related_issue_item?
end
match_when_negated do |page_object|
page_object.has_no_related_issue_item?
end
end
end
end
# frozen_string_literal: true
module Matchers
module HaveSnippetDescription
RSpec::Matchers.define :have_snippet_description do |description|
match do |page_object|
page_object.has_snippet_description?(description)
end
match_when_negated do |page_object|
page_object.has_no_snippet_description?
end
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment