diff options
author | Rémy Coutable <remy@rymai.me> | 2018-03-29 12:49:08 +0300 |
---|---|---|
committer | Rémy Coutable <remy@rymai.me> | 2018-04-23 13:20:30 +0300 |
commit | d2aee809ed76ff2e7f57c820410b51898b3a226a (patch) | |
tree | f57280904793622f356d6092fd94d72992d014f3 | |
parent | 023d4f6f2f3d88d0966fe01e6ef921fd03a309fe (diff) |
Introduce spec/fast_spec_helper.rb to run spec files that don't rely on the whole Rails env
Signed-off-by: Rémy Coutable <remy@rymai.me>
-rw-r--r-- | config/initializers/2_app.rb | 2 | ||||
-rw-r--r-- | lib/gitlab/git.rb | 2 | ||||
-rw-r--r-- | rubocop/spec_helpers.rb | 2 | ||||
-rw-r--r-- | spec/fast_spec_helper.rb | 38 | ||||
-rw-r--r-- | spec/lib/gitlab_spec.rb | 4 |
5 files changed, 46 insertions, 2 deletions
diff --git a/config/initializers/2_app.rb b/config/initializers/2_app.rb index bd74f90e7d2..d6775d0a4ec 100644 --- a/config/initializers/2_app.rb +++ b/config/initializers/2_app.rb @@ -1,3 +1,5 @@ +require_dependency 'gitlab/popen' + module Gitlab def self.config Settings diff --git a/lib/gitlab/git.rb b/lib/gitlab/git.rb index c9abea90d21..e85e87a54af 100644 --- a/lib/gitlab/git.rb +++ b/lib/gitlab/git.rb @@ -1,3 +1,5 @@ +require_dependency 'gitlab/encoding_helper' + module Gitlab module Git # The ID of empty tree. diff --git a/rubocop/spec_helpers.rb b/rubocop/spec_helpers.rb index 6c0f0193b1a..9bf5f1e3b18 100644 --- a/rubocop/spec_helpers.rb +++ b/rubocop/spec_helpers.rb @@ -1,6 +1,6 @@ module RuboCop module SpecHelpers - SPEC_HELPERS = %w[spec_helper.rb rails_helper.rb].freeze + SPEC_HELPERS = %w[fast_spec_helper.rb rails_helper.rb spec_helper.rb].freeze # Returns true if the given node originated from the spec directory. def in_spec?(node) diff --git a/spec/fast_spec_helper.rb b/spec/fast_spec_helper.rb new file mode 100644 index 00000000000..32eb8db0fa5 --- /dev/null +++ b/spec/fast_spec_helper.rb @@ -0,0 +1,38 @@ +require 'bundler/setup' + +require 'settingslogic' + +ENV["RAILS_ENV"] = 'test' +ENV["IN_MEMORY_APPLICATION_SETTINGS"] = 'true' + +unless Kernel.respond_to?(:require_dependency) + module Kernel + alias_method :require_dependency, :require + end +end + +unless defined?(Rails) + module Rails + def self.root + Pathname.new(File.expand_path('')) + end + + # Copied from https://github.com/rails/rails/blob/v4.2.10/railties/lib/rails.rb#L59-L61 + def self.env + @_env ||= ActiveSupport::StringInquirer.new(ENV["RAILS_ENV"] || ENV["RACK_ENV"] || "development") + end + end +end + +# Settings is used in config/initializers/2_app.rb +class Settings < Settingslogic + source Rails.root.join('config/gitlab.yml') + namespace Rails.env +end + +# Defines Gitlab and Gitlab.config +unless defined?(Gitlab) && Gitlab.respond_to?(:config) + require_relative '../config/initializers/2_app' +end + +require_relative 'support/rspec' diff --git a/spec/lib/gitlab_spec.rb b/spec/lib/gitlab_spec.rb index bd443a5d9e7..e734c12f6dd 100644 --- a/spec/lib/gitlab_spec.rb +++ b/spec/lib/gitlab_spec.rb @@ -1,4 +1,6 @@ -require 'rails_helper' +require 'fast_spec_helper' + +require_dependency 'gitlab' describe Gitlab do describe '.com?' do |