rails/rails-controller-testing

"assigns" in integration test not working

mahemoff opened this issue · 6 comments

This gem has restored assigns as expected for controller tests, but not for integration tests. e.g.:

UsersIntegrationTest <  ActionDispatch::IntegrationTest
  test "get user"  do
    assert_equal joe, assigns(:user)
    …
  end
end

yields

NoMethodError: assigns has been extracted to a gem. To continue using it,
    add `gem 'rails-controller-testing'` to your Gemfile.

I notice the integration test here doesn't include assigns, is it supported?

It should not. Integrations tests are not supposed to have the assigns method since they are integration tests and integrations tests should not be asserting the state of the controller object. I'll remove that message from integration test.

I'm a little surprised tbh. I realise assigns was never the main point of integration tests, but it was still supported right up until Rails 5, so this represents a (minor, though undocumented) break in back-compatibility for the upgrade. If the purpose of rails-controller-testing is to help make a smooth transition to Rails 5, and ultimately assigns is deprecated in controller tests anyway, I'd think it was in scope for integration tests too.

(I had some tests using it because they were migrated from controller tests at some point. Maybe I'm an outlier.)

I just found that the integration tests add it. Could you create an example application that reproduce this issue?

It is being defined here https://github.com/rails/rails-controller-testing/blob/master/lib/rails/controller/testing.rb#L18

Please see https://github.com/mahemoff/integration-assert.

assigns here fails for me with the above error.

Same here, assign its not working, im getting nil.