2014-11-30 17 views
16

używany w automatycznie generowanych testów:Jaki jest cel przypisania metody w testach Rails (MiniTest)?

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 

Szyny documentation nie ma żadnego opisu. Jaki jest cel tej metody i jak z niej korzystać?

Odpowiedz

24

Oznacza to, że kontroler zdefiniował zmienną instancji @item="something". Możesz pobrać zmienną instancji w swoim teście np.

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