ruby - How to test this ==> rspec + rails -


We all know that we have this code in the action of any basic controller

  Def can create that @product.save flash [: notice] = 'The product was successfully created.' Redirect_to (products_path) and Flash [: notice] = "The data has not been saved again" Render: Action => "New" End End  

How can we check this part of the code using RSPC

Any suggestions are available.

I am naive on RSPC, please answer me this question if this answer is very easy :)

adds some matchers to rspec that you notice, redirects, and & amp; Amp; C can be used for testing. This (untested) product_controller_spec.rb shows how you can use remarkable_rels to test your code snippet:

  Describe the product controller ("each") before "Window_cleaner ) "Make a product" do @ product.should_receive (: save) .and_return (right) post: set should set_the_flash: notice ,: to = & gt; 'The product was successfully created.' This product should be redirected to "failure to create a product" should be redirected to "do @ product.should_receive (save) .and_return (wrong) post: should set_the_flash: notice ,: to = & gt; Retry data not saved. Render_template: action = & gt; The end of the 'new' end end  

Notable-rail provided the above render_template, set_the_flash, and redirect_to matchers.


Comments