Assigns in #ruby on Rails — How you can test instance variables in views and controllers
▻https://hackernoon.com/assigns-in-ruby-on-rails-how-you-can-test-instance-variables-in-views-an
Ruby on Rails has special helper methods that allow you to test instance variables in your app’s views and controllers. These are assign and assigns, which stores a hash of the instance variables you can access in your #rspec tests.This tutorial will guide you through how to write a simple controller and view with corresponding tests. These will cover assigning instance variables depending on whether certain conditions are met.How assign and assigns workController testsView testsLearn moreHow assign and assigns worksIf you want to set a controller or view’s instance variables in your RSpec test, then call assign either in a before block or at the start of an example group. The first argument is the name of the instance variable while the second is the value you want to assign to it.before do (...)
#assigns-in-ruby-on-rails #ruby-on-rails #test-instance-variables