Rails 7.1.alpha1 (main): controller specs crash because of ResolverDecorator != Resolver class hierarchy
Closed this issue · 2 comments
zealot128 commented
What Ruby, Rails and RSpec versions are you using?
Ruby version: 2.7, 3.0
Rails version: 7.1.alpha1 (git main branch)
RSpec version: core: 3.12.1,, rspec-rails 4.1.2
- rails-controller
Observed behaviour
After running controller tests, every controller test fails immediately with:
Failure/Error: raise TypeError, "#{path.inspect} is not a valid path: must be a String, Pathname, or Resolver"
TypeError:
#<RSpec::Rails::ViewRendering::EmptyTemplateResolver::ResolverDecorator:0x00007fee250ed038 @resolver=#<ActionView::FileSystemResolver:0x00007fee3763a740 @unbound_templates=#<Concurrent::Map:0x00007fee3763a718 entries=0 default_proc=nil>, @path_parser=#<ActionView::Resolver::PathParser:0x00007fee3763a6a0>, @path="/Users/.../app/views"
>> is not a valid path: must be a String, Pathname, or Resolver
# /Users/../bundler/gems/rails-3025eaa09154/actionview/lib/action_view/path_set.rb:74:in `block in typecast'
# /Users/../bundler/gems/rails-3025eaa09154/actionview/lib/action_view/path_set.rb:67:in `map'
# /Users/../bundler/gems/rails-3025eaa09154/actionview/lib/action_view/path_set.rb:67:in `typecast'
# /Users/../bundler/gems/rails-3025eaa09154/actionview/lib/action_view/path_set.rb:19:in `initialize'
# /Users/../bundler/gems/rails-3025eaa09154/actionview/lib/action_view/view_paths.rb:62:in `new'
# /Users/../bundler/gems/rails-3025eaa09154/actionview/lib/action_view/view_paths.rb:62:in `view_paths='
# /Users/../gems/rspec-rails-4.1.2/lib/rspec/rails/view_rendering.rb:153:in `block (2 levels) in <module:ViewRendering>'
# /Users/../gems/rspec-core-3.12.1/lib/rspec/core/example.rb:457:in `instance_exec'
# /Users/../gems/rspec-core-3.12.1/lib/rspec/core/example.rb:457:in `instance_exec'
# /Users/../gems/rspec-core-3.12.1/lib/rspec/core/hooks.rb:365:in `run'
After investigating, it seems to be that the ActionView::PathSet#typecast method seems to check for class ancestors ("Resolver"), but the RSpec::Rails::ViewRendering::EmptyTemplateResolver::ResolverDecorator
of rspec-rails does not fit that bill, so it crashes here.
I've found a workaround by monkey patching the typecast method, e.g. by pasting into spec_helper.rb and adding " RSpec::Rails::ViewRendering::EmptyTemplateResolver::ResolverDecorator" to the case-when clause:
module ControllerViewPatch
extend ActiveSupport::Concern
included do
def typecast(paths)
paths.map do |path|
case path
when Pathname, String
ActionView::PathRegistry.file_system_resolver(path.to_s)
when ActionView::Resolver, RSpec::Rails::ViewRendering::EmptyTemplateResolver::ResolverDecorator
path
else
raise TypeError, "#{path.inspect} is not a valid path: must be a String, Pathname, or Resolver"
end
end
end
end
end
require 'action_view/path_set'
ActionView::PathSet.include(ControllerViewPatch)