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

Top comments (0)