Skip to content

Instantly share code, notes, and snippets.

@myronmarston
Forked from justinko/gist:1684051
Created January 26, 2012 19:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save myronmarston/1684632 to your computer and use it in GitHub Desktop.
Save myronmarston/1684632 to your computer and use it in GitHub Desktop.
Methods to aid in testing without loading the Rails environment
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