Sha256: 0302b8ef22101011d69a89e08d2dec34f4bfde47f6263b1f71cdfd2bdd69e438
Contents?: true
Size: 964 Bytes
Versions: 4
Compression:
Stored size: 964 Bytes
Contents
# spec/spec_helper_lite.rb # Conditionally creates empty or "stub" modules only if # a) they are not already defined; and # b) they are not auto-loadable. # # From http://objectsonrails.com/#sec-7-1 # # @example Faking out ActiveModel # # ... # require_relative '../spec_helper_lite' # stub_module 'ActiveModel::Conversion' # stub_module 'ActiveModel::Naming' # require_relative '../../app/models/post' # # ... # def stub_module(full_name) # Uses #const_get to attempt to reference the given module. If the module is # defined, or if calling #const_get causes it to be auto-loaded, the method # does nothing more. But if #const_get fails to turn up the module, it defines # an anonymous empty module to act as a placeholder. full_name.to_s.split(/::/).inject(Object) do |context, name| begin context.const_get(name) rescue NameError context.const_set(name, Module.new) end end end # refute # does_not_allow
Version data entries
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
gorillib-0.6.0 | away/stub_module.rb |
gorillib-0.5.2 | away/stub_module.rb |
gorillib-0.4.0pre | lib/gorillib/utils/stub_module.rb |
gorillib-0.4.1pre | lib/gorillib/utils/stub_module.rb |