ruby on rails - RSpec controller spec incorrectly failing when using custom exception handling from Railscast #53 -


i had asked question before , directed this question answer worked feature specs.

however, i'm still running spec failing activerecord::recordnotfound error when including in controller spec. example, items#new , items#create actions should require :list_id param. (i'd using nested route: lists/:list_id/items/new.) if no :list_id, activerecord::recordnotfound raised because can't load @list. custom exception handling causes redirect custom errors#404. however, have in controller spec:

# /spec/controllers/items_controller_spec.rb describe "list_id param missing"   { new: :get, create: :post }.each |action, method|     "redirects custom 404"       send(method, action)       # need here test ends @ custom 404 page.     end   end end  # /config/environments/test.rb config.consider_all_requests_local       = false config.action_controller.perform_caching = false 

in browser correctly redirects 404. test incorrectly fails:

 failure/error: send(method, action)  activerecord::recordnotfound:    couldn't find list without id 

as mentioned in other questions linked above, feature specs work fine, how can work controller specs? (rails 4 app)

update: controller code:

# /app/controllers/items_controller.rb before_action :set_list, only: [:new, :create]  def new   @item = @list.items.build end  private  def set_list   @list = current_user.lists.find(params[:list_id]) end 

controller spec different though. haven't implemented way doing(which can't tell whether it's correct or not). isolate test every single cases ie get, post requests. try , see if problem still persist?


Comments

Popular posts from this blog

user interface - How to replace the Python logo in a Tkinter-based Python GUI app? -

objective c - Greedy NSProgressIndicator Allocation -

how to set an OCR language in Google Drive -