Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2015-08-04 17:42:36 +0300
committerDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2015-08-04 17:42:36 +0300
commitb48b07044b919c07de34434aea7cdba13d7c38a6 (patch)
tree5a6d9d8de1048280a595825aa5f47464455ad670 /spec/support
parentc17f5d06aa4a55a8446928ea6b690ae8e09ce237 (diff)
parent326b827ce39f998ce75f58e9f649e6b50623f1aa (diff)
Merge branch 'master' into drop-satellites
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
Diffstat (limited to 'spec/support')
-rw-r--r--spec/support/markdown_feature.rb106
-rw-r--r--spec/support/matchers.rb66
-rw-r--r--spec/support/matchers/access_matchers.rb54
-rw-r--r--spec/support/matchers/include_module.rb13
-rw-r--r--spec/support/matchers/is_within.rb9
-rw-r--r--spec/support/matchers/markdown_matchers.rb156
-rw-r--r--spec/support/test_env.rb19
7 files changed, 353 insertions, 70 deletions
diff --git a/spec/support/markdown_feature.rb b/spec/support/markdown_feature.rb
new file mode 100644
index 00000000000..2a868aed73b
--- /dev/null
+++ b/spec/support/markdown_feature.rb
@@ -0,0 +1,106 @@
+# This is a helper class used by the GitLab Markdown feature spec
+#
+# Because the feature spec only cares about the output of the Markdown, and the
+# test setup and teardown and parsing is fairly expensive, we only want to do it
+# once. Unfortunately RSpec will not let you access `let`s in a `before(:all)`
+# block, so we fake it by encapsulating all the shared setup in this class.
+#
+# The class renders `spec/fixtures/markdown.md.erb` using ERB, allowing for
+# reference to the factory-created objects.
+class MarkdownFeature
+ include FactoryGirl::Syntax::Methods
+
+ def user
+ @user ||= create(:user)
+ end
+
+ def group
+ unless @group
+ @group = create(:group)
+ @group.add_user(user, Gitlab::Access::DEVELOPER)
+ end
+
+ @group
+ end
+
+ # Direct references ----------------------------------------------------------
+
+ def project
+ @project ||= create(:project)
+ end
+
+ def issue
+ @issue ||= create(:issue, project: project)
+ end
+
+ def merge_request
+ @merge_request ||= create(:merge_request, :simple, source_project: project)
+ end
+
+ def snippet
+ @snippet ||= create(:project_snippet, project: project)
+ end
+
+ def commit
+ @commit ||= project.commit
+ end
+
+ def commit_range
+ unless @commit_range
+ commit2 = project.commit('HEAD~3')
+ @commit_range = CommitRange.new("#{commit.id}...#{commit2.id}", project)
+ end
+
+ @commit_range
+ end
+
+ def simple_label
+ @simple_label ||= create(:label, name: 'gfm', project: project)
+ end
+
+ def label
+ @label ||= create(:label, name: 'awaiting feedback', project: project)
+ end
+
+ # Cross-references -----------------------------------------------------------
+
+ def xproject
+ unless @xproject
+ namespace = create(:namespace, name: 'cross-reference')
+ @xproject = create(:project, namespace: namespace)
+ @xproject.team << [user, :developer]
+ end
+
+ @xproject
+ end
+
+ def xissue
+ @xissue ||= create(:issue, project: xproject)
+ end
+
+ def xmerge_request
+ @xmerge_request ||= create(:merge_request, :simple, source_project: xproject)
+ end
+
+ def xsnippet
+ @xsnippet ||= create(:project_snippet, project: xproject)
+ end
+
+ def xcommit
+ @xcommit ||= xproject.commit
+ end
+
+ def xcommit_range
+ unless @xcommit_range
+ xcommit2 = xproject.commit('HEAD~2')
+ @xcommit_range = CommitRange.new("#{xcommit.id}...#{xcommit2.id}", xproject)
+ end
+
+ @xcommit_range
+ end
+
+ def raw_markdown
+ fixture = Rails.root.join('spec/fixtures/markdown.md.erb')
+ ERB.new(File.read(fixture)).result(binding)
+ end
+end
diff --git a/spec/support/matchers.rb b/spec/support/matchers.rb
deleted file mode 100644
index a2f853e3e70..00000000000
--- a/spec/support/matchers.rb
+++ /dev/null
@@ -1,66 +0,0 @@
-RSpec::Matchers.define :be_valid_commit do
- match do |actual|
- actual &&
- actual.id == ValidCommit::ID &&
- actual.message == ValidCommit::MESSAGE &&
- actual.author_name == ValidCommit::AUTHOR_FULL_NAME
- end
-end
-
-def emulate_user(user)
- user = case user
- when :user then create(:user)
- when :visitor then nil
- when :admin then create(:admin)
- else user
- end
- login_with(user) if user
-end
-
-RSpec::Matchers.define :be_allowed_for do |user|
- match do |url|
- emulate_user(user)
- visit url
- status_code != 404 && current_path != new_user_session_path
- end
-end
-
-RSpec::Matchers.define :be_denied_for do |user|
- match do |url|
- emulate_user(user)
- visit url
- status_code == 404 || current_path == new_user_session_path
- end
-end
-
-RSpec::Matchers.define :be_not_found_for do |user|
- match do |url|
- emulate_user(user)
- visit url
- status_code == 404
- end
-end
-
-RSpec::Matchers.define :include_module do |expected|
- match do
- described_class.included_modules.include?(expected)
- end
-
- description do
- "includes the #{expected} module"
- end
-
- failure_message do
- "expected #{described_class} to include the #{expected} module"
- end
-end
-
-# 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/access_matchers.rb b/spec/support/matchers/access_matchers.rb
new file mode 100644
index 00000000000..558e8b1612f
--- /dev/null
+++ b/spec/support/matchers/access_matchers.rb
@@ -0,0 +1,54 @@
+# AccessMatchers
+#
+# The custom matchers contained in this module are used to test a user's access
+# to a URL by emulating a specific user or type of user account, visiting the
+# URL, and then checking the response status code and resulting path.
+module AccessMatchers
+ extend RSpec::Matchers::DSL
+ include Warden::Test::Helpers
+
+ def emulate_user(user)
+ case user
+ when :user
+ login_as(create(:user))
+ when :visitor
+ logout
+ when :admin
+ login_as(create(:admin))
+ when User
+ login_as(user)
+ else
+ raise ArgumentError, "cannot emulate user #{user}"
+ end
+ end
+
+ def description_for(user, type)
+ if user.kind_of?(User)
+ # User#inspect displays too much information for RSpec's description
+ # messages
+ "be #{type} for supplied User"
+ else
+ "be #{type} for #{user}"
+ end
+ end
+
+ matcher :be_allowed_for do |user|
+ match do |url|
+ emulate_user(user)
+ visit url
+ status_code != 404 && current_path != new_user_session_path
+ end
+
+ description { description_for(user, 'allowed') }
+ end
+
+ matcher :be_denied_for do |user|
+ match do |url|
+ emulate_user(user)
+ visit url
+ status_code == 404 || current_path == new_user_session_path
+ end
+
+ description { description_for(user, 'denied') }
+ end
+end
diff --git a/spec/support/matchers/include_module.rb b/spec/support/matchers/include_module.rb
new file mode 100644
index 00000000000..0a78af1e90e
--- /dev/null
+++ b/spec/support/matchers/include_module.rb
@@ -0,0 +1,13 @@
+RSpec::Matchers.define :include_module do |expected|
+ match do
+ described_class.included_modules.include?(expected)
+ end
+
+ description do
+ "includes the #{expected} module"
+ end
+
+ failure_message do
+ "expected #{described_class} to include the #{expected} module"
+ end
+end
diff --git a/spec/support/matchers/is_within.rb b/spec/support/matchers/is_within.rb
new file mode 100644
index 00000000000..0c35fc7e899
--- /dev/null
+++ b/spec/support/matchers/is_within.rb
@@ -0,0 +1,9 @@
+# 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
new file mode 100644
index 00000000000..9df226c3af8
--- /dev/null
+++ b/spec/support/matchers/markdown_matchers.rb
@@ -0,0 +1,156 @@
+# MarkdownMatchers
+#
+# Custom matchers for our custom HTML::Pipeline filters. These are used to test
+# that specific filters are or are not used by our defined pipelines.
+#
+# Must be included manually.
+module MarkdownMatchers
+ extend RSpec::Matchers::DSL
+ include Capybara::Node::Matchers
+
+ # RelativeLinkFilter
+ matcher :parse_relative_links do
+ set_default_markdown_messages
+
+ match do |actual|
+ link = actual.at_css('a:contains("Relative Link")')
+ image = actual.at_css('img[alt="Relative Image"]')
+
+ expect(link['href']).to end_with('master/doc/README.md')
+ expect(image['src']).to end_with('master/app/assets/images/touch-icon-ipad.png')
+ end
+ end
+
+ # EmojiFilter
+ matcher :parse_emoji do
+ set_default_markdown_messages
+
+ match do |actual|
+ expect(actual).to have_selector('img.emoji', count: 10)
+ end
+ end
+
+ # TableOfContentsFilter
+ matcher :create_header_links do
+ 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')
+ end
+ end
+
+ # AutolinkFilter
+ matcher :create_autolinks do
+ def have_autolink(link)
+ have_link(link, href: link)
+ end
+
+ set_default_markdown_messages
+
+ match do |actual|
+ expect(actual).to have_autolink('http://about.gitlab.com/')
+ expect(actual).to have_autolink('https://google.com/')
+ expect(actual).to have_autolink('ftp://ftp.us.debian.org/debian/')
+ expect(actual).to have_autolink('smb://foo/bar/baz')
+ expect(actual).to have_autolink('irc://irc.freenode.net/git')
+ expect(actual).to have_autolink('http://localhost:3000')
+
+ %w(code a kbd).each do |elem|
+ expect(body).not_to have_selector("#{elem} a")
+ end
+ end
+ end
+
+ # UserReferenceFilter
+ matcher :reference_users do
+ set_default_markdown_messages
+
+ match do |actual|
+ expect(actual).to have_selector('a.gfm.gfm-project_member', count: 3)
+ end
+ end
+
+ # IssueReferenceFilter
+ matcher :reference_issues do
+ set_default_markdown_messages
+
+ match do |actual|
+ expect(actual).to have_selector('a.gfm.gfm-issue', count: 3)
+ end
+ end
+
+ # MergeRequestReferenceFilter
+ matcher :reference_merge_requests do
+ set_default_markdown_messages
+
+ match do |actual|
+ expect(actual).to have_selector('a.gfm.gfm-merge_request', count: 3)
+ expect(actual).to have_selector('em a.gfm-merge_request')
+ end
+ end
+
+ # SnippetReferenceFilter
+ matcher :reference_snippets do
+ set_default_markdown_messages
+
+ match do |actual|
+ expect(actual).to have_selector('a.gfm.gfm-snippet', count: 2)
+ end
+ end
+
+ # CommitRangeReferenceFilter
+ matcher :reference_commit_ranges do
+ set_default_markdown_messages
+
+ match do |actual|
+ expect(actual).to have_selector('a.gfm.gfm-commit_range', count: 2)
+ end
+ end
+
+ # CommitReferenceFilter
+ matcher :reference_commits do
+ set_default_markdown_messages
+
+ match do |actual|
+ expect(actual).to have_selector('a.gfm.gfm-commit', count: 2)
+ end
+ end
+
+ # LabelReferenceFilter
+ matcher :reference_labels do
+ set_default_markdown_messages
+
+ match do |actual|
+ expect(actual).to have_selector('a.gfm.gfm-label', count: 3)
+ end
+ end
+
+ # TaskListFilter
+ matcher :parse_task_lists do
+ set_default_markdown_messages
+
+ match do |actual|
+ expect(actual).to have_selector('ul.task-list', count: 2)
+ expect(actual).to have_selector('li.task-list-item', count: 7)
+ expect(actual).to have_selector('input[checked]', count: 3)
+ end
+ end
+end
+
+# Monkeypatch the matcher DSL so that we can reduce some noisy duplication for
+# setting the failure messages for these matchers
+module RSpec::Matchers::DSL::Macros
+ def set_default_markdown_messages
+ failure_message do
+ # expected to parse emoji, but didn't
+ "expected to #{description}, but didn't"
+ end
+
+ failure_message_when_negated do
+ # expected not to parse task lists, but did
+ "expected not to #{description}, but did"
+ end
+ end
+end
diff --git a/spec/support/test_env.rb b/spec/support/test_env.rb
index 8bdd6b43cdd..8dc687c3580 100644
--- a/spec/support/test_env.rb
+++ b/spec/support/test_env.rb
@@ -5,18 +5,24 @@ module TestEnv
# When developing the seed repository, comment out the branch you will modify.
BRANCH_SHA = {
+ 'empty-branch' => '7efb185',
'flatten-dir' => 'e56497b',
'feature' => '0b4bc9a',
'feature_conflict' => 'bb5206f',
'fix' => '12d65c8',
'improve/awesome' => '5937ac0',
'markdown' => '0ed8c6c',
- 'master' => '5937ac0'
+ 'master' => '5937ac0',
+ "'test'" => 'e56497b',
}
- FORKED_BRANCH_SHA = BRANCH_SHA.merge({
- 'add-submodule-version-bump' => '3f547c08'
- })
+ # gitlab-test-fork is a fork of gitlab-fork, but we don't necessarily
+ # need to keep all the branches in sync.
+ # We currently only need a subset of the branches
+ FORKED_BRANCH_SHA = {
+ 'add-submodule-version-bump' => '3f547c08',
+ 'master' => '5937ac0'
+ }
# Test environment
#
@@ -29,6 +35,7 @@ module TestEnv
clean_test_path
FileUtils.mkdir_p(repos_path)
+ FileUtils.mkdir_p(backup_path)
# Setup GitLab shell for test instance
setup_gitlab_shell
@@ -121,6 +128,10 @@ module TestEnv
Gitlab.config.gitlab_shell.repos_path
end
+ def backup_path
+ Gitlab.config.backup.path
+ end
+
def copy_forked_repo_with_submodules(project)
base_repo_path = File.expand_path(forked_repo_path_bare)
target_repo_path = File.expand_path(repos_path + "/#{project.namespace.path}/#{project.path}.git")