From 54b04f1c5b6c486a67c654ee9987e5f5ec4501fd Mon Sep 17 00:00:00 2001
From: Douwe Maan <douwe@gitlab.com>
Date: Thu, 20 Aug 2015 12:41:47 -0700
Subject: [PATCH] Add fixture_file helper.

---
 spec/lib/gitlab/email/attachment_uploader_spec.rb   |  8 +-------
 spec/lib/gitlab/email/receiver_spec.rb              |  6 ------
 spec/lib/gitlab/email/reply_parser_spec.rb          |  6 ------
 spec/lib/gitlab/google_code_import/client_spec.rb   |  2 +-
 spec/lib/gitlab/google_code_import/importer_spec.rb |  2 +-
 spec/support/fixture_helpers.rb                     | 11 +++++++++++
 spec/support/markdown_feature.rb                    |  4 ++--
 spec/workers/email_receiver_worker_spec.rb          |  6 ------
 8 files changed, 16 insertions(+), 29 deletions(-)
 create mode 100644 spec/support/fixture_helpers.rb

diff --git a/spec/lib/gitlab/email/attachment_uploader_spec.rb b/spec/lib/gitlab/email/attachment_uploader_spec.rb
index b54ee8aa72a..e8208e15e29 100644
--- a/spec/lib/gitlab/email/attachment_uploader_spec.rb
+++ b/spec/lib/gitlab/email/attachment_uploader_spec.rb
@@ -1,18 +1,12 @@
 require "spec_helper"
 
 describe Gitlab::Email::AttachmentUploader do
-  def fixture_file(filename)
-    return '' if filename.blank?
-    file_path = File.expand_path(Rails.root + 'spec/fixtures/' + filename)
-    File.read(file_path)
-  end
-
   describe "#execute" do
     let(:project) { build(:project) }
     let(:message_raw) { fixture_file("emails/attachment.eml") }
     let(:message) { Mail::Message.new(message_raw) }
 
-    it "creates a post with an attachment" do
+    it "uploads all attachments and returns their links" do
       links = described_class.new(message).execute(project)
       link = links.first
 
diff --git a/spec/lib/gitlab/email/receiver_spec.rb b/spec/lib/gitlab/email/receiver_spec.rb
index 3d434aeaf91..a6f682a2711 100644
--- a/spec/lib/gitlab/email/receiver_spec.rb
+++ b/spec/lib/gitlab/email/receiver_spec.rb
@@ -1,12 +1,6 @@
 require "spec_helper"
 
 describe Gitlab::Email::Receiver do
-  def fixture_file(filename)
-    return '' if filename.blank?
-    file_path = File.expand_path(Rails.root + 'spec/fixtures/' + filename)
-    File.read(file_path)
-  end
-
   before do
     allow(Gitlab.config.reply_by_email).to receive(:enabled).and_return(true)
     allow(Gitlab.config.reply_by_email).to receive(:address).and_return("reply+%{reply_key}@appmail.adventuretime.ooo")
diff --git a/spec/lib/gitlab/email/reply_parser_spec.rb b/spec/lib/gitlab/email/reply_parser_spec.rb
index 32120d56cbc..c552e632ce2 100644
--- a/spec/lib/gitlab/email/reply_parser_spec.rb
+++ b/spec/lib/gitlab/email/reply_parser_spec.rb
@@ -2,12 +2,6 @@ require "spec_helper"
 
 # Inspired in great part by Discourse's Email::Receiver
 describe Gitlab::Email::ReplyParser do
-  def fixture_file(filename)
-    return '' if filename.blank?
-    file_path = File.expand_path(Rails.root + 'spec/fixtures/' + filename)
-    File.read(file_path)
-  end
-
   describe '#execute' do
     def test_parse_body(mail_string)
       described_class.new(Mail::Message.new(mail_string)).execute
diff --git a/spec/lib/gitlab/google_code_import/client_spec.rb b/spec/lib/gitlab/google_code_import/client_spec.rb
index 6aa4428f367..37985c062b4 100644
--- a/spec/lib/gitlab/google_code_import/client_spec.rb
+++ b/spec/lib/gitlab/google_code_import/client_spec.rb
@@ -1,7 +1,7 @@
 require "spec_helper"
 
 describe Gitlab::GoogleCodeImport::Client do
-  let(:raw_data) { JSON.parse(File.read(Rails.root.join("spec/fixtures/GoogleCodeProjectHosting.json"))) }
+  let(:raw_data) { JSON.parse(fixture_file("GoogleCodeProjectHosting.json")) }
   subject { described_class.new(raw_data) }
 
   describe "#valid?" do
diff --git a/spec/lib/gitlab/google_code_import/importer_spec.rb b/spec/lib/gitlab/google_code_import/importer_spec.rb
index f49cbb7f532..65ad7524cc2 100644
--- a/spec/lib/gitlab/google_code_import/importer_spec.rb
+++ b/spec/lib/gitlab/google_code_import/importer_spec.rb
@@ -2,7 +2,7 @@ require "spec_helper"
 
 describe Gitlab::GoogleCodeImport::Importer do
   let(:mapped_user) { create(:user, username: "thilo123") }
-  let(:raw_data) { JSON.parse(File.read(Rails.root.join("spec/fixtures/GoogleCodeProjectHosting.json"))) }
+  let(:raw_data) { JSON.parse(fixture_file("GoogleCodeProjectHosting.json")) }
   let(:client) { Gitlab::GoogleCodeImport::Client.new(raw_data) }
   let(:import_data) do
     {
diff --git a/spec/support/fixture_helpers.rb b/spec/support/fixture_helpers.rb
new file mode 100644
index 00000000000..a05c9d18002
--- /dev/null
+++ b/spec/support/fixture_helpers.rb
@@ -0,0 +1,11 @@
+module FixtureHelpers
+  def fixture_file(filename)
+    return '' if filename.blank?
+    file_path = File.expand_path(Rails.root.join('spec/fixtures/', filename))
+    File.read(file_path)
+  end
+end
+
+RSpec.configure do |config|
+  config.include FixtureHelpers
+end
diff --git a/spec/support/markdown_feature.rb b/spec/support/markdown_feature.rb
index c59df4e84d6..f8b2ce03e6c 100644
--- a/spec/support/markdown_feature.rb
+++ b/spec/support/markdown_feature.rb
@@ -100,7 +100,7 @@ class MarkdownFeature
   end
 
   def raw_markdown
-    fixture = Rails.root.join('spec/fixtures/markdown.md.erb')
-    ERB.new(File.read(fixture)).result(binding)
+    markdown = fixture_file('markdown.md.erb')
+    ERB.new(markdown).result(binding)
   end
 end
diff --git a/spec/workers/email_receiver_worker_spec.rb b/spec/workers/email_receiver_worker_spec.rb
index e0081904db2..e8f1bd2fa2f 100644
--- a/spec/workers/email_receiver_worker_spec.rb
+++ b/spec/workers/email_receiver_worker_spec.rb
@@ -1,12 +1,6 @@
 require "spec_helper"
 
 describe EmailReceiverWorker do
-  def fixture_file(filename)
-    return '' if filename.blank?
-    file_path = File.expand_path(Rails.root + 'spec/fixtures/' + filename)
-    File.read(file_path)
-  end
-
   let(:raw_message) { fixture_file('emails/valid_reply.eml') }
 
   context "when reply by email is enabled" do
-- 
GitLab