An experiment to see how the issue I described at https://github.com/thoughtbot/administrate/pull/1880#issuecomment-777665333 can be solved. I'll repeat here...
Some of our controller tests don't actually run Rails's test rendering code. Instead they capture the call to render
with a mock, extract the value of :locals
, and run expectations on that. As a result, nothing is actually rendered, and Rails tells us that the result was a :no_content
.
The capture is done with capture_view_locals
, which can be seen at https://github.com/thoughtbot/administrate/blob/e1ae45cf44a6b7fce13865175bb5e596ad448ba9/spec/support/controller_helpers.rb
To compound the problem, I don't think there is a standard way of achieving this. It's possible to test :locals
, but only in a very limited way, by comparing exact values. See:
This is a first attempt at fixing the situation. It's a "if you can't beat them, join them" approach, where I extend the helper to capture more than just :locals
.
Other options:
- Write this test differently, not relying on this helper.
- Move it to an integration test or something like that.
- Don't use locals, and instead use instance variables as it's conventional with Rails.
- Contribute to
rails-controller-testing
, and add a method that would help us here. - Other...?