Files
react-native/scripts/cocoapods/__tests__/test_utils/FileMock.rb
T
Riccardo Cipolleschi 8a8c33aab9 Move fabric setup to a separate file (#33818)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/33818

This Diff moves the fabric setup from the `react_native_pods` script to its own `fabric` file.

It also introduces tests for the file and some test utilities.

## Changelog
[iOS][Changed] - Move fabric setup to its own file

Reviewed By: cortinico, dmitryrykun

Differential Revision: D36344911

fbshipit-source-id: 586186684be2c0080f247390f26145f2defa9e97
2022-05-18 02:57:35 -07:00

116 lines
2.8 KiB
Ruby
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# Copyright (c) Meta Platforms, Inc. and affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
class File
@@is_testing = false
@@exist_invocation_params = []
@@mocked_existing_files = []
@@delete_invocation_count = 0
@@deleted_files = []
@@open_files_with_mode = {}
@@open_invocation_count = 0
@@open_files = []
attr_reader :collected_write
attr_reader :fsync_invocation_count
def initialize()
@collected_write = []
@fsync_invocation_count = 0
end
# Monkey patched exists? method.
# It is used also by the test runner, so it can't start monkey patched
# To use this, invoke the `is_testing` method before starting your test.
# Remember to invoke `reset` after the test.
def self.exist?(path)
if !@@is_testing
return exists?(path)
end
@@exist_invocation_params.push(path)
return @@mocked_existing_files.include?(path)
end
def self.delete(path)
if !@@is_testing
delete(path)
return
end
@@delete_invocation_count += 1
@@deleted_files.push(path)
end
def self.delete_invocation_count
return @@delete_invocation_count
end
def self.deleted_files
return @@deleted_files
end
# Getter for the `exist_invocation_params` to check that the exist method
# is invoked the right number of times with the right parameters
def self.exist_invocation_params()
return @@exist_invocation_params
end
# Set the list of files the test must return as existing
def self.mocked_existing_files(files)
@@mocked_existing_files = files
end
# Turn on the mocking features of the File mock
def self.enable_testing_mode!()
@@is_testing = true
end
def self.open(path, mode, &block)
@@open_files_with_mode[path] = mode
@@open_invocation_count += 1
file = File.new()
@@open_files.push(file)
yield(file)
end
def self.open_files_with_mode
return @@open_files_with_mode
end
def self.open_invocation_count
return @@open_invocation_count
end
def self.open_files
return @@open_files
end
def write(text)
@collected_write.push(text.to_s)
end
def fsync()
@fsync_invocation_count += 1
end
# Resets all the settings for the File mock
def self.reset()
@@delete_invocation_count = 0
@@deleted_files = []
@@open_files = []
@@open_files_with_mode = {}
@@open_invocation_count = 0
@@mocked_existing_files = []
@@is_testing = false
@@exist_invocation_params = []
end
end