啊,所以我想通了!这些评论中概述了它: - https://github.com/nesquena/rabl/issues/37#issuecomment-6474467
- https://github.com/rspec/rspec-rails/issues/565#issuecomment-6474362
def self.call(template)
source = if template.source.empty?
File.read(template.identifier)
else # use source
template.source
end
%{ ::Rabl::Engine.new(#{source.inspect}).
render(self, assigns.merge(local_assigns)) }
end # call
rspec-rails 存根模板以获得空白源(而不是存根整个渲染过程,以便 rails 正确处理格式/mime-types/等),并且 rabl 处理程序看到空白源并决定读取文件系统。因此,无论是 rabl 还是 rspec-rails 都需要稍作调整才能使其正常工作。现在我已经修补了 rspec-rails:
class EmptyTemplatePathSetDecorator < ::ActionView::Resolver
attr_reader :original_path_set
def initialize(original_path_set)
@original_path_set = original_path_set
end
# @api private
def find_all(*args)
original_path_set.find_all(*args).collect do |template|
::ActionView::Template.new(
" ", # <======================== this is not "empty"
template.identifier,
template.handler,
{
:virtual_path => template.virtual_path,
:format => template.formats
}
)
end
end
end