DEV Community

loading...

[RSpec] What does assigns mean in RSpec?

n350071 profile image n350071🇯🇵 ・1 min read

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

pic
Editor guide