I’m beginning with Rails and currently I got stuck on integration testing of controllers.
I’m trying to validate that if certain values are provided by a user in a form, Active Record generates errors and these errors are passed to a view.
My problem is that I have no idea how to access controller assigned variables (for example – @user) inside integration tests. As I read in http://guides.rubyonrails.org/testing.html#what-to-include-in-your-functional-tests I can access variables such as @controller, @request, @response but I was also expecting that I can easily access variables assigned by controller.
Unfortunately things such as:
* @user
* @controller.user
don’t really work :-/
Rails Version < 5.0
You can access these variables using
assignsmethod with symbol of variable name as a perameter. In example:Gives you value of
@userfrom your controller.Rails Version > 5.0
In rails 5.0
assignsandassert_templatehas been_depracted, so in order to use it as before you need to add:to your Gemfile.
Original discussion why using
assignsis a bad idea.