Commit 920becb7 authored by Rémy Coutable's avatar Rémy Coutable

Merge branch 'backstage/gb/improve-fast-specs-helper' into 'master'

Improve fast specs helper to autoload the library

See merge request gitlab-org/gitlab-ce!18903
parents 2df09a40 7186f0de
...@@ -133,11 +133,24 @@ really fast since: ...@@ -133,11 +133,24 @@ really fast since:
- gitlab-shell and Gitaly setup are skipped - gitlab-shell and Gitaly setup are skipped
- Test repositories setup are skipped - Test repositories setup are skipped
Note that in some cases, you might have to add some `require_dependency 'foo'` `fast_spec_helper` also support autoloading classes that are located inside the
in your file under test since Rails autoloading is not available in these cases. `lib/` directory. It means that as long as your class / module is using only
code from the `lib/` directory you will not need to explicitly load any
This shouldn't be a problem since explicitely listing dependencies should be dependencies. `fast_spec_helper` also loads all ActiveSupport extensions,
considered a good practice anyway. including core extensions that are commonly used in the Rails environment.
Note that in some cases, you might still have to load some dependencies using
`require_dependency` when a code is using gems or a dependency is not located
in `lib/`.
For example, if you want to test your code that is calling the
`Gitlab::UntrustedRegexp` class, which under the hood uses `re2` library, you
should either add `require_dependency 're2'` to files in your library that
need `re2` gem, to make this requirement explicit, or you can add it to the
spec itself, but the former is preferred.
It takes around one second to load tests that are using `fast_spec_helper`
instead of 30+ seconds in case of a regular `spec_helper`.
### `let` variables ### `let` variables
......
...@@ -3,14 +3,8 @@ require 'bundler/setup' ...@@ -3,14 +3,8 @@ require 'bundler/setup'
ENV['GITLAB_ENV'] = 'test' ENV['GITLAB_ENV'] = 'test'
ENV['IN_MEMORY_APPLICATION_SETTINGS'] = 'true' ENV['IN_MEMORY_APPLICATION_SETTINGS'] = 'true'
unless Object.respond_to?(:require_dependency)
class Object
alias_method :require_dependency, :require
end
end
# Defines Settings and Gitlab.config which are at the center of the app
require_relative '../config/settings' require_relative '../config/settings'
require_relative '../lib/gitlab' unless defined?(Gitlab.config)
require_relative 'support/rspec' require_relative 'support/rspec'
require 'active_support/all'
ActiveSupport::Dependencies.autoload_paths << 'lib'
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment