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)