DEV Community

n350071πŸ‡―πŸ‡΅
n350071πŸ‡―πŸ‡΅

Posted on

[RSpec] What does assigns mean in RSpec?

πŸ€” Situation

describe 'InviteUserController', type: :controller do
  describe '#edit' do
    before { get :edit, token: user.token }
    it 'should have user_form' do
      # πŸ¦„ Here πŸ¦„
      expect(assigns(:user_form).class.name).to eq 'UserForm'
    end
  end
end

πŸ‘ Meaning

assigns relates to the instance variables created within a controller action (and assigned to the view).

So, You might have such like Controller.

class InviteUserController
  def edit
      # πŸ¦„ this @user_form πŸ¦„
    @user_form = UserForm.new(token: user_params[:token]) 
    render :edit
  end
end

πŸ”— Parent Note

Discussion (0)