1
我有幾個燈具文件已定義,並且它們通過fixtures :all
聲明加載。
如何獲取項目中所有燈具名稱的數組?無需通過搜索* .yml文件的測試/夾具文件夾。獲取項目中定義的所有燈具名稱列表
P.S.一個明顯的解決方案是定義這樣的方法:
def all_fixtures
@all_fixtures ||= Dir.entries("#{Rails.root}/test/fixtures")
.select { |filename| /.*\.yml/.match(filename) }
.map{ |filename| filename[0..-5].to_sym }
end
但我確定有更優雅的東西。