Module: MockFS

Defined in:
lib/mockfs.rb

Defined Under Namespace

Modules: Adapter Classes: DirAdapter, FileAdapter, FileUtilsAdapter, MockFileSystem, Path

Constant Summary collapse

Version =
'0.1.6'
OriginalFileUtils =
FileUtils
OriginalDir =
Dir
OriginalFile =
File
@@mock =
false

Class Method Summary collapse

Class Method Details

.method_missing(symbol, *args) ⇒ Object

:nodoc:



101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/mockfs.rb', line 101

def self.method_missing( symbol, *args ) #:nodoc:
	class_name = nil
	if symbol.id2name =~ /^get_(.*)/
		result = self.send( $1, *args )
		warn "MockFS.#{ symbol.id2name } is deprecated, use #{ $1 } instead"
		result
	else
		klass = real_class_or_mock_class symbol
		if klass
			klass
		else
			@@mock ? mock_file_system.send( symbol, *args ) : super
		end
	end
end

.mock=(is_mock) ⇒ Object

Tell MockFS whether to offer interfaces to the real or mock file system. is_mock should be a Boolean.



119
# File 'lib/mockfs.rb', line 119

def self.mock= ( is_mock ); @@mock = is_mock; end

.mock?Boolean

Returns true or false depending on whether MockFS is using the mock file system.

Returns:

  • (Boolean)


122
# File 'lib/mockfs.rb', line 122

def self.mock?; @@mock; end

.mock_file_systemObject

If we’re in mock mode, this will return the MockFileSystem; otherwise it will raise a RuntimeError.



126
127
128
# File 'lib/mockfs.rb', line 126

def self.mock_file_system
	@@mock ? MockFileSystem.instance : ( raise RuntimeError )
end

.real_class_or_mock_class(symbol) ⇒ Object

:nodoc:



130
131
132
133
134
135
136
137
138
139
140
141
142
# File 'lib/mockfs.rb', line 130

def self.real_class_or_mock_class( symbol ) #:nodoc:
	class_name = symbol.id2name.capitalize
	class_name.gsub!( /_(\w)/ ) { |s| $1.capitalize }
	if %w( Dir File FileUtils ).include?( class_name )
		if @@mock
			Class.by_name( 'MockFS::' + class_name + 'Adapter' )
		else
			Class.by_name( class_name )
		end
	else
		nil
	end
end