What's the purpose of assigns method in Rails tests (MiniTest)?

minitest, ruby-on-rails

Solution

It means if a controller defined an instance variable `@item="something"`.

You can fetch an instance variable in your test with e.g.:

# It will check if the instance variable is a string.
assert_kind_of String, assigns(:item)

Problem

Used in automatically generated tests: ``` test "should create item" do login_user assert_difference('Item.count') do post :create, item: { creator: @item.creator, title: @item.title, user_id: @item.user_id, text: 'Hello, world!' } end assert_redirected_to(assigns(:item)) end ``` Rails documentation doesn't have any description. What's the purpose of this method and how to use it?

Original source