Module: FakeFS::Require::Load

Included in:
Kernel
Defined in:
lib/fakefs/require.rb

Instance Method Summary collapse

Instance Method Details

#fakefs_load(fn, wrap = false) ⇒ Object

Faked #load (see Kernel#load)

Raises:

  • (LoadError)

162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
# File 'lib/fakefs/require.rb', line 162

def fakefs_load fn, wrap = false
  fn = fn.to_s
  orig_fn = fn.dup
  
  fn = fn + ".rb" unless fn[-3..-1] == ".rb"
  path = FakeFS::Require.resolve fn
  
  if path
    File.open path, "r" do |f|
      if wrap
        Module.new.module_eval f.read, fn, 1
      else
        Object.class_eval f.read, fn, 1
      end
    end
    return true
  elsif FakeFS::Require.opts[:fallback]
    return fakefs_original_load orig_fn, wrap
  end
  
  raise LoadError, "no such file to load -- " + fn
end