Created
May 21, 2013 00:02
-
-
Save ootoovak/5616600 to your computer and use it in GitHub Desktop.
Helper methods to load as few files as possible to get tests to run. Some create require paths to load files and others to init required constants.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'fast_spec_helper' | |
require 'date' | |
require_model 'generate_required_daily_lists' | |
required_constants %w(Distributor PackingList DeliveryList) | |
---- OR ---- | |
require 'fast_spec_helper' | |
require_model 'exporter', sub_dir: 'sales_csv' | |
require_model 'delivery_exporter', sub_dir: 'sales_csv' | |
required_constants %w(DeliverySort DeliveryGenerator) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
APP_ROOT = '../..' | |
APP_MODEL_PATH = 'app/models' | |
LIB_MODEL_PATH = 'lib/models' | |
def defaults | |
{ app_path: APP_MODEL_PATH } | |
end | |
def require_model(name, opts = {}) | |
opts[:app_path] = LIB_MODEL_PATH if opts.delete(:lib) | |
require_resource(name, opts) | |
end | |
def require_resource(name, opts = {}) | |
opts = defaults.merge(opts) | |
require construct_path(name, opts) | |
end | |
def construct_path(name, opts = {}) | |
app_path_to_file = [ opts[:app_path] ] | |
app_path_to_file << opts[:sub_dir] if opts[:sub_dir] | |
app_path_to_file << name | |
app_path_to_file = app_path_to_file.join('/') + '.rb' | |
absolute_path(app_path_to_file) | |
end | |
def absolute_path(app_path_to_file) | |
File.expand_path("#{APP_ROOT}/#{app_path_to_file}", __FILE__) | |
end | |
def required_constants(class_names) | |
class_names.each do |class_name| | |
unless Object.const_defined?(class_name) | |
Object.const_set(class_name, Class.new) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment