rails / rails-controller-testing

Brings back `assigns` and `assert_template` to your Rails tests
https://github.com/rails/rails-controller-testing
MIT License
303 stars 53 forks source link

"assigns" in integration test not working #28

Open mahemoff opened 8 years ago

mahemoff commented 8 years ago

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?

rafaelfranca commented 8 years ago

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 commented 8 years ago

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

mahemoff commented 8 years ago

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

rafaelfranca commented 7 years ago

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

mahemoff commented 7 years ago

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

assigns here fails for me with the above error.

Xosmond commented 7 years ago

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