diff options
author | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2014-07-31 19:24:53 +0300 |
---|---|---|
committer | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2014-07-31 19:24:53 +0300 |
commit | b238b1544c391bbc60a7d38c30d98e05be786667 (patch) | |
tree | 8f94b6018882d2053000e719e671f7df46ae92e7 | |
parent | ee4643c732c3d91437e50d0c8486dbb8ea5b51b5 (diff) | |
download | gitlab-ce-b238b1544c391bbc60a7d38c30d98e05be786667.tar.gz |
Recreate tmp/tests on each test run
-rw-r--r-- | features/support/env.rb | 2 | ||||
-rw-r--r-- | spec/models/project_wiki_spec.rb | 49 | ||||
-rw-r--r-- | spec/models/wiki_page_spec.rb | 43 | ||||
-rw-r--r-- | spec/spec_helper.rb | 9 | ||||
-rw-r--r-- | spec/support/test_env.rb | 5 |
5 files changed, 52 insertions, 56 deletions
diff --git a/features/support/env.rb b/features/support/env.rb index 480cb361b67..22f28987fe3 100644 --- a/features/support/env.rb +++ b/features/support/env.rb @@ -47,7 +47,7 @@ Spinach.hooks.after_scenario do end Spinach.hooks.before_run do - TestEnv.init(mailer: false, init_repos: true, repos: false) + TestEnv.init(mailer: false) RSpec::Mocks::setup self include FactoryGirl::Syntax::Methods diff --git a/spec/models/project_wiki_spec.rb b/spec/models/project_wiki_spec.rb index f06a5cd4ecc..56ec83e3e7d 100644 --- a/spec/models/project_wiki_spec.rb +++ b/spec/models/project_wiki_spec.rb @@ -1,33 +1,14 @@ require "spec_helper" describe ProjectWiki do - - def remove_temp_repo(path) - FileUtils.rm_rf path - end - - def commit_details - commit = {name: user.name, email: user.email, message: "test commit"} - end - - def create_page(name, content) - subject.wiki.write_page(name, :markdown, content, commit_details) - end - - def destroy_page(page) - subject.wiki.delete_page(page, commit_details) - end - - let(:project) { create(:project) } + let(:project) { create(:empty_project) } let(:repository) { project.repository } let(:user) { project.owner } let(:gitlab_shell) { Gitlab::Shell.new } + let(:project_wiki) { ProjectWiki.new(project, user) } - subject { ProjectWiki.new(project, user) } - - before do - create_temp_repo(subject.send(:path_to_repo)) - end + subject { project_wiki } + before { project_wiki.wiki } describe "#path_with_namespace" do it "returns the project path with namespace with the .wiki extension" do @@ -242,4 +223,26 @@ describe ProjectWiki do end end + private + + def create_temp_repo(path) + FileUtils.mkdir_p path + system(*%W(git init --quiet --bare -- #{path})) + end + + def remove_temp_repo(path) + FileUtils.rm_rf path + end + + def commit_details + commit = {name: user.name, email: user.email, message: "test commit"} + end + + def create_page(name, content) + subject.wiki.write_page(name, :markdown, content, commit_details) + end + + def destroy_page(page) + subject.wiki.delete_page(page, commit_details) + end end diff --git a/spec/models/wiki_page_spec.rb b/spec/models/wiki_page_spec.rb index 005c513af3c..cb42822b9bb 100644 --- a/spec/models/wiki_page_spec.rb +++ b/spec/models/wiki_page_spec.rb @@ -1,35 +1,12 @@ require "spec_helper" describe WikiPage do - - def remove_temp_repo(path) - FileUtils.rm_rf path - end - - def commit_details - commit = {name: user.name, email: user.email, message: "test commit"} - end - - def create_page(name, content) - wiki.wiki.write_page(name, :markdown, content, commit_details) - end - - def destroy_page(title) - page = wiki.wiki.paged(title) - wiki.wiki.delete_page(page, commit_details) - end - - let(:project) { create(:project) } - let(:repository) { project.repository } + let(:project) { create(:empty_project) } let(:user) { project.owner } let(:wiki) { ProjectWiki.new(project, user) } subject { WikiPage.new(wiki) } - before do - create_temp_repo(wiki.send(:path_to_repo)) - end - describe "#initialize" do context "when initialized with an existing gollum page" do before do @@ -171,4 +148,22 @@ describe WikiPage do end end + private + + def remove_temp_repo(path) + FileUtils.rm_rf path + end + + def commit_details + commit = {name: user.name, email: user.email, message: "test commit"} + end + + def create_page(name, content) + wiki.wiki.write_page(name, :markdown, content, commit_details) + end + + def destroy_page(title) + page = wiki.wiki.paged(title) + wiki.wiki.delete_page(page, commit_details) + end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 2181238ae9f..6934cabadfa 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -38,14 +38,7 @@ RSpec.configure do |config| config.include TestEnv - # If you're not using ActiveRecord, or you'd prefer not to run each of your - # examples within a transaction, remove the following line or assign false - # instead of true. - config.before(:suite) do - TestEnv.init(init_repos: true, repos: false) - end - config.before(:each) do - TestEnv.setup_stubs + TestEnv.init end end diff --git a/spec/support/test_env.rb b/spec/support/test_env.rb index fc1a920822e..f46405f238b 100644 --- a/spec/support/test_env.rb +++ b/spec/support/test_env.rb @@ -16,6 +16,11 @@ module TestEnv # Setup GitLab shell for test instance setup_gitlab_shell + # Clean /tmp/tests + tmp_test_path = Rails.root.join('tmp', 'tests') + FileUtils.rm_r(tmp_test_path) + FileUtils.mkdir(tmp_test_path) + # Create repository for FactoryGirl.create(:project) setup_factory_repo end |