You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is about a view spec. While writing a test for a partial which uses a local variable I couldn't find a documented way on how to approach it. I tried:
render{},{variable_name: some_object}
but that resulted in local_assigns in the template to be an empty hash and thus the rendering failed.
Expected behaviour
Provide an easy way to pass local variables to a partial.
Theres actually a whole bunch of keys you can pass to Rails to render here, and you actually have to provide something, so but we can use the defaults which check the implicit template, and merge in the locals, which is what I've done in #2686
What Ruby, Rails and RSpec versions are you using?
Ruby version: ruby 3.0.4p208 (2022-04-12 revision 3fa771dded) [x86_64-darwin21]
Rails version: Rails 7.0.4.3
RSpec version: RSpec 3.12
Observed behaviour
This is about a view spec. While writing a test for a partial which uses a local variable I couldn't find a documented way on how to approach it. I tried:
but that resulted in
local_assigns
in the template to be an empty hash and thus the rendering failed.Expected behaviour
Provide an easy way to pass local variables to a partial.
Investigation / Suggested fix
The render method (defined as https://github.com/rspec/rspec-rails/blob/main/lib/rspec/rails/example/view_example_group.rb#LL66C8-L66C61):
render(options = {}, local_assigns = {}, &block)
only seems to passlocal_assigns
through in caseoptions
is not as Hash (i.e. a String). Otherwise the code will refer tooptions[:locals]
.Thus I'd suggest the following code for the
render
method to allow passinglocals
:Then it's possible to use
which looks nicer.
If that's acceptable, I can prepare a PR.
The text was updated successfully, but these errors were encountered: