2013-05-13 3 views
2

내 ApplicationController의 동작을 테스트하려고하는데 오류가 계속 발생합니다. 다음은 내 사양은 다음과 같습니다응용 프로그램 컨트롤러에 대한 RSpec 테스트가 실패했습니다.

describe ApplicationController do 
    #Base class should be inferred 
    controller do 
    def not_found 
     raise ActiveRecord::RecordNotFound 
    end 
    end 

    # Routing 
    #---------------------------------------------------------------------------- 
    def with_error_routing 
    with_routing do |map| 
     map.draw do 
     get '/not_found' => "anonymous#not_found",  :as => :not_found 
     get '/home'  => "anonymous#home",   :as => :home 
     end 
     yield 
    end 
    end 

    describe "handling ActiveRecord::RecordNotFound" do 
    it "renders the 404 template", :failing => true do 
     with_error_routing do 
     @request.env['HTTPS'] = 'on' 
     get :not_found, :format => 'html' 
     response.should redirect_to(home_path) 
     end 
    end 
    end 
end 

내가 점점 계속 오류 메시지는 이것이다 : ActionController::RoutingError: No route matches {:controller=>"anonymous"}

다른 사람이이 문제에 직면 했습니까? 내 예제가 ApplicationController 테스트의 다른 예제와 일치하는 것 같습니다.

Failures: 

    1) ApplicationController handling ActiveRecord::RecordNotFound 
    Failure/Error: get :not_found 
    ActionController::RoutingError: 
     No route matches {:controller=>"anonymous", :action=>"not_found"} 
    # /home/bryce/.rvm/gems/ruby-1.9.3-p429/gems/actionpack-3.2.13/lib/action_dispatch/routing/route_set.rb:544:in `raise_routing_error' 
    # /home/bryce/.rvm/gems/ruby-1.9.3-p429/gems/actionpack-3.2.13/lib/action_dispatch/routing/route_set.rb:540:in `rescue in generate' 
    # /home/bryce/.rvm/gems/ruby-1.9.3-p429/gems/actionpack-3.2.13/lib/action_dispatch/routing/route_set.rb:532:in `generate' 
    # /home/bryce/.rvm/gems/ruby-1.9.3-p429/gems/actionpack-3.2.13/lib/action_dispatch/routing/route_set.rb:573:in `generate' 
    # /home/bryce/.rvm/gems/ruby-1.9.3-p429/gems/actionpack-3.2.13/lib/action_dispatch/routing/route_set.rb:598:in `url_for' 
    # /home/bryce/.rvm/gems/ruby-1.9.3-p429/gems/actionpack-3.2.13/lib/action_dispatch/routing/url_for.rb:148:in `url_for' 
    # /home/bryce/.rvm/gems/ruby-1.9.3-p429/gems/actionpack-3.2.13/lib/action_controller/metal/redirecting.rb:105:in `_compute_redirect_to_location' 
    # /home/bryce/.rvm/gems/ruby-1.9.3-p429/gems/actionpack-3.2.13/lib/action_controller/metal/redirecting.rb:74:in `redirect_to' 
    # /home/bryce/.rvm/gems/ruby-1.9.3-p429/gems/actionpack-3.2.13/lib/action_controller/metal/flash.rb:25:in `redirect_to' 
    # /home/bryce/.rvm/gems/ruby-1.9.3-p429/gems/actionpack-3.2.13/lib/action_controller/metal/instrumentation.rb:60:in `block in redirect_to' 
    # /home/bryce/.rvm/gems/ruby-1.9.3-p429/gems/activesupport-3.2.13/lib/active_support/notifications.rb:123:in `block in instrument' 
    # /home/bryce/.rvm/gems/ruby-1.9.3-p429/gems/activesupport-3.2.13/lib/active_support/notifications/instrumenter.rb:20:in `instrument' 
    # /home/bryce/.rvm/gems/ruby-1.9.3-p429/gems/activesupport-3.2.13/lib/active_support/notifications.rb:123:in `instrument' 
    # /home/bryce/.rvm/gems/ruby-1.9.3-p429/gems/actionpack-3.2.13/lib/action_controller/metal/instrumentation.rb:59:in `redirect_to' 
    # /home/bryce/.rvm/gems/ruby-1.9.3-p429/gems/gritter-1.0.3/lib/gritter/gflash.rb:8:in `redirect_to' 
    # /home/bryce/.rvm/gems/ruby-1.9.3-p429/gems/actionpack-3.2.13/lib/action_controller/metal/force_ssl.rb:33:in `block in force_ssl' 
    # /home/bryce/.rvm/gems/ruby-1.9.3-p429/gems/activesupport-3.2.13/lib/active_support/callbacks.rb:418:in `_run__1662327083837902210__process_action__2977905806469662832__callbacks' 
    # /home/bryce/.rvm/gems/ruby-1.9.3-p429/gems/activesupport-3.2.13/lib/active_support/callbacks.rb:405:in `__run_callback' 
    # /home/bryce/.rvm/gems/ruby-1.9.3-p429/gems/activesupport-3.2.13/lib/active_support/callbacks.rb:385:in `_run_process_action_callbacks' 
    # /home/bryce/.rvm/gems/ruby-1.9.3-p429/gems/activesupport-3.2.13/lib/active_support/callbacks.rb:81:in `run_callbacks' 
    # /home/bryce/.rvm/gems/ruby-1.9.3-p429/gems/actionpack-3.2.13/lib/abstract_controller/callbacks.rb:17:in `process_action' 
    # /home/bryce/.rvm/gems/ruby-1.9.3-p429/gems/actionpack-3.2.13/lib/action_controller/metal/rescue.rb:29:in `process_action' 
    # /home/bryce/.rvm/gems/ruby-1.9.3-p429/gems/actionpack-3.2.13/lib/action_controller/metal/instrumentation.rb:30:in `block in process_action' 
    # /home/bryce/.rvm/gems/ruby-1.9.3-p429/gems/activesupport-3.2.13/lib/active_support/notifications.rb:123:in `block in instrument' 
    # /home/bryce/.rvm/gems/ruby-1.9.3-p429/gems/activesupport-3.2.13/lib/active_support/notifications/instrumenter.rb:20:in `instrument' 
    # /home/bryce/.rvm/gems/ruby-1.9.3-p429/gems/activesupport-3.2.13/lib/active_support/notifications.rb:123:in `instrument' 
    # /home/bryce/.rvm/gems/ruby-1.9.3-p429/gems/actionpack-3.2.13/lib/action_controller/metal/instrumentation.rb:29:in `process_action' 
    # /home/bryce/.rvm/gems/ruby-1.9.3-p429/gems/actionpack-3.2.13/lib/action_controller/metal/params_wrapper.rb:207:in `process_action' 
    # /home/bryce/.rvm/gems/ruby-1.9.3-p429/gems/activerecord-3.2.13/lib/active_record/railties/controller_runtime.rb:18:in `process_action' 
    # /home/bryce/.rvm/gems/ruby-1.9.3-p429/gems/actionpack-3.2.13/lib/abstract_controller/base.rb:121:in `process' 
    # /home/bryce/.rvm/gems/ruby-1.9.3-p429/gems/actionpack-3.2.13/lib/abstract_controller/rendering.rb:45:in `process' 
    # /home/bryce/.rvm/gems/ruby-1.9.3-p429/gems/actionpack-3.2.13/lib/action_controller/metal/testing.rb:17:in `process_with_new_base_test' 
    # /home/bryce/.rvm/gems/ruby-1.9.3-p429/gems/actionpack-3.2.13/lib/action_controller/test_case.rb:475:in `process' 
    # /home/bryce/.rvm/gems/ruby-1.9.3-p429/gems/actionpack-3.2.13/lib/action_controller/test_case.rb:49:in `process' 
    # /home/bryce/.rvm/gems/ruby-1.9.3-p429/gems/devise-2.2.4/lib/devise/test_helpers.rb:19:in `block in process' 
    # /home/bryce/.rvm/gems/ruby-1.9.3-p429/gems/devise-2.2.4/lib/devise/test_helpers.rb:72:in `catch' 
    # /home/bryce/.rvm/gems/ruby-1.9.3-p429/gems/devise-2.2.4/lib/devise/test_helpers.rb:72:in `_catch_warden' 
    # /home/bryce/.rvm/gems/ruby-1.9.3-p429/gems/devise-2.2.4/lib/devise/test_helpers.rb:19:in `process' 
    # /home/bryce/.rvm/gems/ruby-1.9.3-p429/gems/actionpack-3.2.13/lib/action_controller/test_case.rb:392:in `get' 
    # ./spec/controllers/application_controller_spec.rb:19:in `block (2 levels) in <top (required)>' 
    # /home/bryce/.rvm/gems/ruby-1.9.3-p429/gems/rspec-core-2.13.1/lib/rspec/core/example.rb:114:in `instance_eval' 
    # /home/bryce/.rvm/gems/ruby-1.9.3-p429/gems/rspec-core-2.13.1/lib/rspec/core/example.rb:114:in `block in run' 
    # /home/bryce/.rvm/gems/ruby-1.9.3-p429/gems/rspec-rails-2.13.2/lib/rspec/rails/example/controller_example_group.rb:160:in `call' 
    # /home/bryce/.rvm/gems/ruby-1.9.3-p429/gems/rspec-rails-2.13.2/lib/rspec/rails/example/controller_example_group.rb:160:in `block (2 levels) in <module:ControllerExampleGroup>' 
    # /home/bryce/.rvm/gems/ruby-1.9.3-p429/gems/rspec-core-2.13.1/lib/rspec/core/extensions/instance_eval_with_args.rb:16:in `instance_exec' 
    # /home/bryce/.rvm/gems/ruby-1.9.3-p429/gems/rspec-core-2.13.1/lib/rspec/core/extensions/instance_eval_with_args.rb:16:in `instance_eval_with_args' 
    # /home/bryce/.rvm/gems/ruby-1.9.3-p429/gems/rspec-core-2.13.1/lib/rspec/core/example.rb:247:in `instance_eval_with_args' 
    # /home/bryce/.rvm/gems/ruby-1.9.3-p429/gems/rspec-core-2.13.1/lib/rspec/core/hooks.rb:87:in `block (2 levels) in run' 
    # /home/bryce/.rvm/gems/ruby-1.9.3-p429/gems/rspec-core-2.13.1/lib/rspec/core/hooks.rb:85:in `call' 
    # /home/bryce/.rvm/gems/ruby-1.9.3-p429/gems/rspec-core-2.13.1/lib/rspec/core/hooks.rb:85:in `run' 
    # /home/bryce/.rvm/gems/ruby-1.9.3-p429/gems/rspec-core-2.13.1/lib/rspec/core/hooks.rb:418:in `run_hook' 
    # /home/bryce/.rvm/gems/ruby-1.9.3-p429/gems/rspec-core-2.13.1/lib/rspec/core/example_group.rb:329:in `run_around_each_hooks' 
    # /home/bryce/.rvm/gems/ruby-1.9.3-p429/gems/rspec-core-2.13.1/lib/rspec/core/example.rb:256:in `with_around_each_hooks' 
    # /home/bryce/.rvm/gems/ruby-1.9.3-p429/gems/rspec-core-2.13.1/lib/rspec/core/example.rb:111:in `run' 
    # /home/bryce/.rvm/gems/ruby-1.9.3-p429/gems/rspec-core-2.13.1/lib/rspec/core/example_group.rb:390:in `block in run_examples' 
    # /home/bryce/.rvm/gems/ruby-1.9.3-p429/gems/rspec-core-2.13.1/lib/rspec/core/example_group.rb:386:in `map' 
    # /home/bryce/.rvm/gems/ruby-1.9.3-p429/gems/rspec-core-2.13.1/lib/rspec/core/example_group.rb:386:in `run_examples' 
    # /home/bryce/.rvm/gems/ruby-1.9.3-p429/gems/rspec-core-2.13.1/lib/rspec/core/example_group.rb:371:in `run' 
    # /home/bryce/.rvm/gems/ruby-1.9.3-p429/gems/rspec-core-2.13.1/lib/rspec/core/command_line.rb:28:in `block (2 levels) in run' 
    # /home/bryce/.rvm/gems/ruby-1.9.3-p429/gems/rspec-core-2.13.1/lib/rspec/core/command_line.rb:28:in `map' 
    # /home/bryce/.rvm/gems/ruby-1.9.3-p429/gems/rspec-core-2.13.1/lib/rspec/core/command_line.rb:28:in `block in run' 
    # /home/bryce/.rvm/gems/ruby-1.9.3-p429/gems/rspec-core-2.13.1/lib/rspec/core/reporter.rb:34:in `report' 
    # /home/bryce/.rvm/gems/ruby-1.9.3-p429/gems/rspec-core-2.13.1/lib/rspec/core/command_line.rb:25:in `run' 
    # /home/bryce/.rvm/gems/ruby-1.9.3-p429/gems/rspec-core-2.13.1/lib/rspec/core/runner.rb:80:in `run' 
    # /home/bryce/.rvm/gems/ruby-1.9.3-p429/gems/spring-0.0.8/lib/spring/commands.rb:110:in `call' 
    # /home/bryce/.rvm/gems/ruby-1.9.3-p429/gems/spring-0.0.8/lib/spring/application.rb:71:in `block in serve' 
    # /home/bryce/.rvm/gems/ruby-1.9.3-p429/gems/spring-0.0.8/lib/spring/application.rb:66:in `fork' 
    # /home/bryce/.rvm/gems/ruby-1.9.3-p429/gems/spring-0.0.8/lib/spring/application.rb:66:in `serve' 
    # /home/bryce/.rvm/gems/ruby-1.9.3-p429/gems/spring-0.0.8/lib/spring/application.rb:49:in `block in run' 
    # /home/bryce/.rvm/gems/ruby-1.9.3-p429/gems/spring-0.0.8/lib/spring/application.rb:43:in `loop' 
    # /home/bryce/.rvm/gems/ruby-1.9.3-p429/gems/spring-0.0.8/lib/spring/application.rb:43:in `run' 
    # /home/bryce/.rvm/gems/ruby-1.9.3-p429/gems/spring-0.0.8/lib/spring/application.rb:37:in `start' 
    # /home/bryce/.rvm/gems/ruby-1.9.3-p429/gems/spring-0.0.8/lib/spring/application_manager.rb:95:in `block in start_child' 
    # /home/bryce/.rvm/gems/ruby-1.9.3-p429/gems/spring-0.0.8/lib/spring/application_manager.rb:82:in `fork' 
    # /home/bryce/.rvm/gems/ruby-1.9.3-p429/gems/spring-0.0.8/lib/spring/application_manager.rb:82:in `start_child' 
    # /home/bryce/.rvm/gems/ruby-1.9.3-p429/gems/spring-0.0.8/lib/spring/application_manager.rb:27:in `start' 
    # /home/bryce/.rvm/gems/ruby-1.9.3-p429/gems/spring-0.0.8/lib/spring/application_manager.rb:54:in `block in with_child' 
    # /home/bryce/.rvm/gems/ruby-1.9.3-p429/gems/spring-0.0.8/lib/spring/application_manager.rb:21:in `synchronize' 
    # /home/bryce/.rvm/gems/ruby-1.9.3-p429/gems/spring-0.0.8/lib/spring/application_manager.rb:43:in `with_child' 
    # /home/bryce/.rvm/gems/ruby-1.9.3-p429/gems/spring-0.0.8/lib/spring/application_manager.rb:62:in `run' 
    # /home/bryce/.rvm/gems/ruby-1.9.3-p429/gems/spring-0.0.8/lib/spring/server.rb:47:in `serve' 
    # /home/bryce/.rvm/gems/ruby-1.9.3-p429/gems/spring-0.0.8/lib/spring/server.rb:35:in `block in boot' 
    # /home/bryce/.rvm/gems/ruby-1.9.3-p429/gems/spring-0.0.8/lib/spring/server.rb:35:in `loop' 
    # /home/bryce/.rvm/gems/ruby-1.9.3-p429/gems/spring-0.0.8/lib/spring/server.rb:35:in `boot' 
    # /home/bryce/.rvm/gems/ruby-1.9.3-p429/gems/spring-0.0.8/lib/spring/server.rb:15:in `boot' 
    # /home/bryce/.rvm/gems/ruby-1.9.3-p429/gems/spring-0.0.8/lib/spring/client/start.rb:13:in `call' 
    # /home/bryce/.rvm/gems/ruby-1.9.3-p429/gems/spring-0.0.8/lib/spring/client/command.rb:7:in `call' 
    # /home/bryce/.rvm/gems/ruby-1.9.3-p429/gems/spring-0.0.8/lib/spring/client.rb:23:in `run' 
    # /home/bryce/.rvm/gems/ruby-1.9.3-p429/gems/spring-0.0.8/bin/spring:4:in `<top (required)>' 
    # /home/bryce/.rvm/gems/ruby-1.9.3-p429/bin/spring:19:in `load' 
    # /home/bryce/.rvm/gems/ruby-1.9.3-p429/bin/spring:19:in `<main>' 
    # /home/bryce/.rvm/gems/ruby-1.9.3-p429/bin/ruby_noexec_wrapper:14:in `eval' 
    # /home/bryce/.rvm/gems/ruby-1.9.3-p429/bin/ruby_noexec_wrapper:14:in `<main>' 

Finished in 0.54729 seconds 
1 example, 1 failure 

추가와 ApplicationController 클래스 :

class ApplicationController < ActionController::Base 
    force_ssl 
    check_authorization :unless => :devise_controller? 

    respond_to :html 
    respond_to :js 
    respond_to :json, :xml, :except => [:edit, :update] 
    respond_to :atom, :csv, :rss, :only => :index 

    rescue_from ActiveRecord::RecordNotFound, :with => :respond_to_not_found 
    rescue_from CanCan::AccessDenied, :with => :respond_to_access_denied 

    # SECURITY - Protect Form IDs from forgery 
    #---------------------------------------------------------------------------- 
    protect_from_forgery 

    # Helpers 
    helper_method :current_user 
    def current_user 
    begin 
     return current_customer unless current_customer.nil? 
     return current_store unless current_store.nil? 
    rescue 
     return nil 
    end 
    end 

    private 
    def current_ability 
    Ability.new(current_user) 
    end 

    #---------------------------------------------------------------------------- 
    def respond_to_not_found 
    FlashSetter.new.set(flash, nil, nil, {:flash_key => :alert, :message_key => :msg_not_found}) 

    respond_to do |format| 
     format.html { redirect_to user_home_path } 
    end 
    end 

    #---------------------------------------------------------------------------- 
    def respond_to_access_denied 
    FlashSetter.new.set(flash, nil, nil, {:flash_key => :alert, :message_key => :msg_not_authorized}) 

    respond_to do |format| 
     format.html { redirect_to home_path } 
    end 
    end 
end 
+0

당신이 내가 복사 한 예외 – Subhas

답변

2

with_routing 블록은 익명 컨트롤러 정상 routes.draw을 사용하는 것보다 약간 다르게 작동하는 것 같다

다음은 역 추적입니다.

+0

의 전체 스택 추적을 게시하시기 바랍니다 수있는 SSL 강제 인용 오타 정확히 (물론, 나는에 따옴표 문제를 해결하는 것이 붙여 :

describe ApplicationController do controller do def not_found raise ActiveRecord::RecordNotFound end end it "handling ActiveRecord::RecordNotFound" do routes.draw { get "not_found" => "anonymous#not_found" } request.env['HTTPS'] = 'on' get :not_found response.should redirect_to(home_path) end end 

편집 : 아래는 작동합니다 귀하의 그것 ... 최종 성명),하지만 난 여전히 같은 오류가 발생합니다. – Bryce

+0

흠, 동일한 날 여기에 (견적을 수정 후), 당신은 예외의 스택 추적을 게시하시기 바랍니다 작동합니까? – Subhas

+0

원래 게시물에 백 트레이스를 추가했습니다. – Bryce

관련 문제