2017-02-27 2 views
0

Erstens, ich bin neu in RSpec und relativ neu zu Rails, so dass ich immer noch viel herausfinden, wie diese Technologien im Vergleich zu meiner bisherigen Spracherfahrung arbeiten.RSpec include nicht gefunden Objekt

Das Problem, RSpec ist ein Test fehlgeschlagen und ich sehe nicht, was ich vermisse.

Der Test testet den GET-Index eines Controllers.

Der Test:

it "populates an array of profiles" do 
    profile = create(:profile) 
    get :index 
    expect(:profiles).to include(profile) 
end 

Das Ergebnis:

1) ProfilesController GET #index populates an array of profiles 
Failure/Error: expect(:profiles).to include(profile) 

    expected :profiles to include #<Profile id: 3, user_id: 2, name: "Kasandra Goldner", about: nil, country_code: nil, state_code: nil...15", avatar_file_name: nil, avatar_content_type: nil, avatar_file_size: nil, avatar_updated_at: nil>, but it does not respond to `include?` 
    Diff: 
    @@ -1,2 +1,2 @@ 
    -[#<Profile id: 3, user_id: 2, name: "Kasandra Goldner", about: nil, country_code: nil, state_code: nil, city: nil, created_at: "2017-02-27 03:42:15", updated_at: "2017-02-27 03:42:15", avatar_file_name: nil, avatar_content_type: nil, avatar_file_size: nil, avatar_updated_at: nil>] 
    +:profiles 

# ./spec/controllers/profiles_controller_spec.rb:15:in `block (3 levels) in <top (required)>' 

Danke.

Antwort

0

Versuchen :profiles in Abtretungs Einwickeln Beispiel var zu erhalten, die in der Steuerung festgelegt ist:

expect(assigns(:profiles)).to include(profile) 
+0

Dank Kris, die haben es geschafft! –

Verwandte Themen