新增對稱為檔案固定裝置的範例檔案的簡易存取。 File
固定裝置是儲存在 ActiveSupport::TestCase.file_fixture_path
中的常規檔案。
File
固定裝置表示為 Pathname
物件。這使得擷取特定資訊變得容易
file_fixture("example.txt").read # get the file's content
file_fixture("example.mp3").size # get the file size
方法
執行個體公開方法
file_fixture(fixture_name) 連結
傳回 Pathname
至名為 fixture_name
的固定裝置檔案。
如果找不到 fixture_name
,則會引發 ArgumentError
。
來源: 顯示 | 在 GitHub 上
# File activesupport/lib/active_support/testing/file_fixtures.rb, line 26 def file_fixture(fixture_name) path = Pathname.new(File.join(file_fixture_path, fixture_name)) if path.exist? path else msg = "the directory '%s' does not contain a file named '%s'" raise ArgumentError, msg % [file_fixture_path, fixture_name] end end