用于自动生成的测试:
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 文档 http://api.rubyonrails.org/classes/ActionDispatch/TestProcess.html#method-i-assigns没有任何描述。这个方法的目的是什么以及如何使用它?
这意味着如果控制器定义了实例变量@item="something"
.
您可以在测试中获取实例变量,例如:
# It will check if the instance variable is a string.
assert_kind_of String, assigns(:item)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)