rails/rails-controller-testing

Support for nested matchers in `assert_template`

klondikemarlen opened this issue · 3 comments

I would expect

render(
  partial: 'path/to/partial', 
  locals: {
    arg1: 'value-for-arg1',
    arg2: 'value-for-arg2',
    arg3: 'value-for-arg3',
  },
)

expect(view).to render_template(
  partial: 'path/to/partial',
  locals: {
    arg1: 'value-for-arg1',
    arg2: 'value-for-arg2',
    arg3: anything,
  },
)

to work if arg1, and arg2 are correct.
Instead the code only seems to work when I also pass the correct value for arg3.

It seems like assert_template isn't accepting nested matchers?

Using rspec-rails so this is probably not the correct place to post.

assert(@_rendered_views.view_rendered?(view, options[:locals]), msg) could probably be something like

result = @_rendered_views.locals_for(view).any? do |actual_locals|
  expected_locals.all? { |key, value| value === actual_locals[key] }
end
assert(result, msg)

and it would take nested matchers. Though I'm not actually sure that nested matchers are MiniTest thing and not just an RSpec thing, so maybe its not a problem in this repo after all.