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?
Rails文档没有任何描述。这个方法的目的是什么?如何使用它?
2 个解决方案
#1
24
It means if a controller defined an instance variable @item="something"
. You can fetch instance variable in your test with e.g.
它意味着如果控制器定义了一个实例变量@item="something"。你可以用例在你的测试中获取实例变量。
assert_kind_of String, assigns(:item) # will check if the instance variable is a string
#2
0
Be aware assigns
deprecated in Rails 5. And extracted to separate gem.
注意,在Rails 5中分配已被废弃。并提取分离宝石。
#1
24
It means if a controller defined an instance variable @item="something"
. You can fetch instance variable in your test with e.g.
它意味着如果控制器定义了一个实例变量@item="something"。你可以用例在你的测试中获取实例变量。
assert_kind_of String, assigns(:item) # will check if the instance variable is a string
#2
0
Be aware assigns
deprecated in Rails 5. And extracted to separate gem.
注意,在Rails 5中分配已被废弃。并提取分离宝石。