Module: MediaWikiVagrant::SpecHelpers::MockEnvironment

Defined in:
tests/spec/support/mock_environment.rb

Instance Method Summary collapse

Instance Method Details

#mock_directory(path) ⇒ Object



4
5
6
7
8
# File 'tests/spec/support/mock_environment.rb', line 4

def mock_directory(path)
  raise 'you must explicitly enable fakefs before mocking files' unless FakeFS.activated?

  FakeFS::FileUtils.mkdir_p(path)
end

#mock_empty_files_in(dir, *paths) ⇒ Object



10
11
12
# File 'tests/spec/support/mock_environment.rb', line 10

def mock_empty_files_in(dir, *paths)
  mock_files_in(dir, paths.each.with_object({}) { |path, hash| hash[path] = '' })
end

#mock_file(path, content: "\n", mtime: nil) ⇒ Object



14
15
16
17
18
19
20
# File 'tests/spec/support/mock_environment.rb', line 14

def mock_file(path, content: "\n", mtime: nil)
  raise 'you must explicitly enable fakefs before mocking files' unless FakeFS.activated?

  mock_directory(File.dirname(path))
  FakeFS::File.write(path, content)
  FakeFS::File.utime(mtime, mtime, path) unless mtime.nil?
end

#mock_files(paths_and_content = {}) ⇒ Object



22
23
24
# File 'tests/spec/support/mock_environment.rb', line 22

def mock_files(paths_and_content = {})
  paths_and_content.each { |path, content| mock_file(path, content: content) }
end

#mock_files_in(dir, paths_and_content = {}) ⇒ Object



26
27
28
29
30
# File 'tests/spec/support/mock_environment.rb', line 26

def mock_files_in(dir, paths_and_content = {})
  dir = Pathname.new(dir)

  paths_and_content.each { |path, content| mock_file(dir.join(path), content: content) }
end