gitlab-org--gitlab-foss/spec/support/test_env.rb

89 lines
2.0 KiB
Ruby
Raw Normal View History

2013-04-11 20:54:20 +00:00
require 'rspec/mocks'
module TestEnv
extend self
# Test environment
#
# all repositories and namespaces stored at
# RAILS_APP/tmp/test-git-base-path
#
# Next shell methods are stubbed and return true
# - mv_repository
# - remove_repository
# - add_key
# - remove_key
#
def init(opts = {})
2013-04-11 20:54:20 +00:00
RSpec::Mocks::setup(self)
# Disable observers to improve test speed
#
# You can enable it in whole test case where needed by next string:
#
# before(:each) { enable_observers }
#
disable_observers if opts[:observers] == false
2013-04-11 08:50:58 +00:00
# Disable mailer for spinach tests
disable_mailer if opts[:mailer] == false
# Use tmp dir for FS manipulations
repos_path = Rails.root.join('tmp', 'test-git-base-path')
Gitlab.config.gitlab_shell.stub(repos_path: repos_path)
2013-04-27 20:50:17 +00:00
Gitlab::Git::Repository.stub(repos_path: repos_path)
2013-04-01 14:27:44 +00:00
GollumWiki.any_instance.stub(:init_repo) do |path|
create_temp_repo(File.join(repos_path, "#{path}.git"))
end
Gitlab::Shell.any_instance.stub(
2013-04-01 14:27:44 +00:00
add_repository: true,
mv_repository: true,
remove_repository: true,
2013-06-26 16:13:29 +00:00
update_repository_head: true,
add_key: true,
remove_key: true
)
2013-04-01 15:35:29 +00:00
Gitlab::Satellite::Satellite.any_instance.stub(
exists?: true,
destroy: true,
create: true
)
MergeRequest.any_instance.stub(
check_if_can_be_merged: true
)
Repository.any_instance.stub(
size: 12.45
)
# Remove tmp/test-git-base-path
FileUtils.rm_rf Gitlab.config.gitlab_shell.repos_path
# Recreate tmp/test-git-base-path
FileUtils.mkdir_p Gitlab.config.gitlab_shell.repos_path
end
def create_temp_repo(path)
FileUtils.mkdir_p path
command = "git init --quiet --bare #{path};"
system(command)
end
def enable_observers
ActiveRecord::Base.observers.enable(:all)
end
def disable_observers
ActiveRecord::Base.observers.disable(:all)
end
2013-04-11 08:50:58 +00:00
def disable_mailer
2013-04-11 20:54:20 +00:00
NotificationService.any_instance.stub(mailer: double.as_null_object)
2013-04-11 08:50:58 +00:00
end
end