summaryrefslogtreecommitdiff
path: root/spec/support/matchers
diff options
context:
space:
mode:
Diffstat (limited to 'spec/support/matchers')
-rw-r--r--spec/support/matchers/access_matchers.rb36
-rw-r--r--spec/support/matchers/be_url.rb5
-rw-r--r--spec/support/matchers/have_issuable_counts.rb8
-rw-r--r--spec/support/matchers/is_within.rb9
-rw-r--r--spec/support/matchers/markdown_matchers.rb6
5 files changed, 41 insertions, 23 deletions
diff --git a/spec/support/matchers/access_matchers.rb b/spec/support/matchers/access_matchers.rb
index 0497e391860..ceddb656596 100644
--- a/spec/support/matchers/access_matchers.rb
+++ b/spec/support/matchers/access_matchers.rb
@@ -7,7 +7,7 @@ module AccessMatchers
extend RSpec::Matchers::DSL
include Warden::Test::Helpers
- def emulate_user(user)
+ def emulate_user(user, membership = nil)
case user
when :user
login_as(create(:user))
@@ -19,6 +19,19 @@ module AccessMatchers
login_as(create(:user, external: true))
when User
login_as(user)
+ when *Gitlab::Access.sym_options_with_owner.keys
+ raise ArgumentError, "cannot emulate #{user} without membership parent" unless membership
+
+ role = user
+
+ if role == :owner && membership.owner
+ user = membership.owner
+ else
+ user = create(:user)
+ membership.public_send(:"add_#{role}", user)
+ end
+
+ login_as(user)
else
raise ArgumentError, "cannot emulate user #{user}"
end
@@ -26,8 +39,7 @@ module AccessMatchers
def description_for(user, type)
if user.kind_of?(User)
- # User#inspect displays too much information for RSpec's description
- # messages
+ # User#inspect displays too much information for RSpec's descriptions
"be #{type} for the specified user"
else
"be #{type} for #{user}"
@@ -36,21 +48,31 @@ module AccessMatchers
matcher :be_allowed_for do |user|
match do |url|
- emulate_user(user)
- visit url
+ emulate_user(user, @membership)
+ visit(url)
+
status_code != 404 && current_path != new_user_session_path
end
+ chain :of do |membership|
+ @membership = membership
+ end
+
description { description_for(user, 'allowed') }
end
matcher :be_denied_for do |user|
match do |url|
- emulate_user(user)
- visit url
+ emulate_user(user, @membership)
+ visit(url)
+
status_code == 404 || current_path == new_user_session_path
end
+ chain :of do |membership|
+ @membership = membership
+ end
+
description { description_for(user, 'denied') }
end
end
diff --git a/spec/support/matchers/be_url.rb b/spec/support/matchers/be_url.rb
new file mode 100644
index 00000000000..f8096af1b22
--- /dev/null
+++ b/spec/support/matchers/be_url.rb
@@ -0,0 +1,5 @@
+RSpec::Matchers.define :be_url do |_|
+ match do |actual|
+ URI.parse(actual) rescue false
+ end
+end
diff --git a/spec/support/matchers/have_issuable_counts.rb b/spec/support/matchers/have_issuable_counts.rb
index 02605d6b70e..92cf3de5448 100644
--- a/spec/support/matchers/have_issuable_counts.rb
+++ b/spec/support/matchers/have_issuable_counts.rb
@@ -1,9 +1,9 @@
RSpec::Matchers.define :have_issuable_counts do |opts|
- match do |actual|
- expected_counts = opts.map do |state, count|
- "#{state.to_s.humanize} #{count}"
- end
+ expected_counts = opts.map do |state, count|
+ "#{state.to_s.humanize} #{count}"
+ end
+ match do |actual|
actual.within '.issues-state-filters' do
expected_counts.each do |expected_count|
expect(actual).to have_content(expected_count)
diff --git a/spec/support/matchers/is_within.rb b/spec/support/matchers/is_within.rb
deleted file mode 100644
index 0c35fc7e899..00000000000
--- a/spec/support/matchers/is_within.rb
+++ /dev/null
@@ -1,9 +0,0 @@
-# Extend shoulda-matchers
-module Shoulda::Matchers::ActiveModel
- class ValidateLengthOfMatcher
- # Shortcut for is_at_least and is_at_most
- def is_within(range)
- is_at_least(range.min) && is_at_most(range.max)
- end
- end
-end
diff --git a/spec/support/matchers/markdown_matchers.rb b/spec/support/matchers/markdown_matchers.rb
index 8c98b1f988c..97b8b342eb2 100644
--- a/spec/support/matchers/markdown_matchers.rb
+++ b/spec/support/matchers/markdown_matchers.rb
@@ -38,9 +38,9 @@ module MarkdownMatchers
set_default_markdown_messages
match do |actual|
- expect(actual).to have_selector('h1 a#gitlab-markdown')
- expect(actual).to have_selector('h2 a#markdown')
- expect(actual).to have_selector('h3 a#autolinkfilter')
+ expect(actual).to have_selector('h1 a#user-content-gitlab-markdown')
+ expect(actual).to have_selector('h2 a#user-content-markdown')
+ expect(actual).to have_selector('h3 a#user-content-autolinkfilter')
end
end