Monday 15 April 2013

ruby on rails - Rspec Test Required parameters -


I am using factories and bucks for my test structure. I have a model on which its validates_presence_of verification contains an exam in the original format framework:

  Describe "with invalid paramet" "This is a newly created but unsafe type of disease. Provides @disease in "# trigger behavior occurs when invalid parameters are present. Although: (save). And_written (incorrect) Posted: Make: illness => {} Assigns (: disease). Be_a_new (disease) end of end   

Edit: diseases_controller.rb

  # POST / diseases # post / dishes.exml Can make DRF @ Dizzy = Disease. Answer (biog_prim) Reply-Respond | Format | If @set.safe format.html {redirect_to (@disease, notice = & gt; 'the disease was created successfully.'}} Format.xml {rendere: xml = & gt; @ Disease,: condition = & gt; : Created: Location = & gt; @deses} and format.html {Render: Action => "New"} format.xml {Render: xml = & gt; @ disease. Errors,: Status = & gt; : Unprocessable_entity} End End End Personal Def Disease: Params.require (Disease). Explicit (: name, omim_id,: description) end   

How does this test work with my application? Works. Instead of returning a new disease to the wrong post, it returns an error:

  missing the required parameter: illness   

Question # 1: I do not know What is being done with the rupee to see what the post is, in this case the response does not appear to be the object? Assigns print (: sickness) does not contain anything I previously sent an error message, which was sent to the right URL with empty data (which should be posted RSPAT) , But I do not know how PPC is getting back the post statement Question # 2: How do I check that reaction properly, which should be generated - get the error message by saying Literacy is missing a required parameter?

Edit: So my controller seems to indicate that it provides a new disease, but the test fails. If I try to present the missing parameter on the website, then it gives a flash notice that "name can not be empty". I'm not sure how to test in RSPC.

Edit # 2: The above code is included in the lower part of the controller as per the recommendations to use the disease_apadms strong_parameters gem

Thanks!

to answer Question 1 ("I do not know what's coming back with See "APC posts" to see) ... You can use the "put" statement within your digits (i.e. inside this block) for example, you can do something like You can try:

  "Describe" with invalid parameters "It provides @deses to a newly created but unsaved illness" # The poor behavior occurs when the invalid paramagazine has been submitted. Ay_instance.stub (: save) .and_return (false) post: create ,: disease = & gt; {} says: Assesses the disease (: disease). It should be _YU (disease) and end   

This is a valuable debugging tool. RSPC is running when the output will be in SS and FS in the terminal.

Question 2 For, I'm not sure what you want, but I do not know that you have given the disease as a disease I have been entrusted with pattern control spectacles in the following style (from which I have learned how to write controlling glasses) or to check it (or should).

Create a post example:

  Refer to "invalid attribute with" do not "hope to save new contact" {post: create, contact : Factory.Adits_For (: invalid_contact)} .to_not changes (contact, counting) it "reinstates new method" post: make, contact: factory.edits_forfor (: invalid_contact) response.should render_template: new end end ..   

You have a reason to better monitor the governing system. Can that I do not know about Don that case, please answer ignores my question and hope that my second answer is useful!

No comments:

Post a Comment