新增可輕鬆存取名為「檔案固定裝置」的範例檔案。 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) 連結
傳回名為 `fixture_name` 的檔案固定裝置 `Pathname`。
如果無法找到 `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