-
-
Save leshill/1684107 to your computer and use it in GitHub Desktop.
Methods to aid in testing without loading the Rails environment
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
def stub_model(model_name) | |
stub_class model_name, ActiveRecord::Base | |
end | |
def stub_class(class_name, super_class = Object) | |
stub_module class_name, Class.new(super_class) | |
end | |
def stub_module(module_name, object = Module.new) | |
module_name = module_name.to_s.camelize | |
Object.const_get module_name | |
rescue NameError | |
Object.const_set module_name, object | |
end | |
def require_model(file_name, options = {}) | |
require "./app/models/#{file_name}" | |
if options[:factory] and not FactoryGirl.factories.registered?(file_name) | |
require "factories/#{file_name}_factory" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment