fakefs / fakefs

A fake filesystem. Use it in your tests.
MIT License
1.04k stars 188 forks source link

uninitialized constant FakeFS::File::WRONLY (NameError) when using with merb #4

Closed teamon closed 14 years ago

teamon commented 14 years ago

loading autotest/merb_rspec /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby -S spec -O spec/spec.opts spec/models/user_spec.rb spec/models/site_spec.rb spec/spec_custom_matchers.rb /Library/Ruby/Gems/1.8/gems/merb-core-1.0.12/lib/merb-core.rb:389:in log_stream': uninitialized constant FakeFS::File::WRONLY (NameError) from /Library/Ruby/Gems/1.8/gems/merb-core-1.0.12/lib/merb-core/bootloader.rb:223:inrun' from /Library/Ruby/Gems/1.8/gems/merb-core-1.0.12/lib/merb-core/bootloader.rb:99:in run' from /Library/Ruby/Gems/1.8/gems/merb-core-1.0.12/lib/merb-core/server.rb:172:inbootup' from /Library/Ruby/Gems/1.8/gems/merb-core-1.0.12/lib/merb-core/server.rb:42:in start' from /Library/Ruby/Gems/1.8/gems/merb-core-1.0.12/lib/merb-core.rb:170:instart' from /Library/Ruby/Gems/1.8/gems/merb-core-1.0.12/lib/merb-core.rb:183:in start_environment' from ./spec/models/../spec_helper.rb:16 from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:ingem_original_require' ... 7 levels... from /Library/Ruby/Gems/1.8/gems/rspec-1.2.6/lib/spec/runner/command_line.rb:9:in run' from /Library/Ruby/Gems/1.8/gems/rspec-1.2.6/bin/spec:4 from /opt/local/bin/spec:19:inload' from /opt/local/bin/spec:19

jmhodges commented 14 years ago

This is a larger issue that fakefs does not also mock out the non-module constants that File and FileUtils has. We'll have to be ever so slightly tricky because some of the constants are OS and possibly machine dependent.

File.constants.each do |c| 
  unless File.const_get(c).is_a?(Module)
    puts "#{c}: #{File.const_get(c).inspect}"
  end
end

Output on Mac OS X 10.5:

    NOCTTY: 131072
    Separator: "/"
    LOCK_EX: 2
    CREAT: 512
    RDONLY: 0
    FNM_DOTMATCH: 4
    PATH_SEPARATOR: ":"
    TRUNC: 1024
    SEEK_END: 2
    LOCK_SH: 1
    APPEND: 8
    FNM_PATHNAME: 2
    ALT_SEPARATOR: nil
    LOCK_NB: 4
    NONBLOCK: 4
    SEEK_CUR: 1
    RDWR: 2
    FNM_SYSCASE: 0
    SYNC: 128
    FNM_NOESCAPE: 1
    SEPARATOR: "/"
    LOCK_UN: 8
    EXCL: 2048
    SEEK_SET: 0
    WRONLY: 1
    FNM_CASEFOLD: 8
jmhodges commented 14 years ago

I have pushed up a quick 10 minute implementation (with tests) to jmhodges/fakefs/with_constants. It's a little wet, and I can imagine some people having an issue with it, but it does the job.

A cleaned up version would probably be nice, but this seems acceptable.

jmhodges commented 14 years ago

This is me trying to say I'd like a code review before I push it to defunkt's master.

jmhodges commented 14 years ago

Okay, so this was actually already fixed. My branch explicitly tested for File.const_defined?(WHATEVER) which was failing even though there was a self.const_missing already there.

So, fixed in 5b5961f8e28612c153e241fe2442abf5d0cf9943.