ruby on rails - Rspec Test Failing -


This low controller test is failing, and I do not know why:

  Do the "GET Index" before ("each") @outing = factorygall.cent_list (outgoing, 30) @user = factorial.credit (user) end it "should be successful": get index response.should be_success End end   

provides Rspec up (unbearable) error:

  failure / error: response.should be_success expected Success? To make the right return, it became false   

Here is the code for the real controller:

  DIF index if @Username @ outing = outgoing. (: User_id = & gt; @ user.id) @out ing_in vites = OutgoingGuide. ((User_id = & gt; @ user.id) and Flash [: warning] = "You must be logged in to see your outings!" Redirect_to root_path End End   

Does anyone know what is causing my test to fail? I think it may be conditional in the Outing Controller, but I do not know how a missing test will appear ...

You are confusing the example variable between two different classes - the controller is its class and the specification is its class. They do not share the state, you can try this simple example to get a better understanding ...

  DIF index / clear bad code, but to prove a point Username @ user = First if @ user @ outing = outing. ((User_id = & gt; @ user.id) @out ing_in vites = outgoing. There ((user_id = & gt; @ user.id) and flash [ : Warning] = "You have to log in to see your outings!" Redirect_to root_path End End   

I do not add the first user with the outing from FactoryGirl.create_list (: outgoing, 30) After you make the outing Users are creating, so your outgoing. Where will also fail.

It is important to understand that when you need to test the database database in your test stack, the data needs to be included in it. So if your controller inquires for a specific user-related outing, then your imagination needs to establish an environment such as the user will recover the controller (in this case, user.first Horrible line from my example)) It will also be outgoing with what the specification is expecting.

Comments