rails-controller-testing icon indicating copy to clipboard operation
rails-controller-testing copied to clipboard

"assigns" in integration test not working

Open mahemoff opened this issue 9 years ago • 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?

mahemoff avatar Oct 07 '16 00:10 mahemoff

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.

rafaelfranca avatar Oct 07 '16 19:10 rafaelfranca

Closed by https://github.com/rails/rails/commit/5dde413

rafaelfranca avatar Oct 07 '16 19:10 rafaelfranca

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.)

mahemoff avatar Oct 08 '16 09:10 mahemoff

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

rafaelfranca avatar Oct 21 '16 19:10 rafaelfranca

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

assigns here fails for me with the above error.

mahemoff avatar Oct 27 '16 16:10 mahemoff

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

Xosmond avatar Dec 16 '16 13:12 Xosmond