Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ruby-on-rails-3/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby 路线和测试路线的RSpec.rb_Ruby_Ruby On Rails 3_Rspec - Fatal编程技术网

Ruby 路线和测试路线的RSpec.rb

Ruby 路线和测试路线的RSpec.rb,ruby,ruby-on-rails-3,rspec,Ruby,Ruby On Rails 3,Rspec,我正试图为我的服装路线以及不存在的路线编写测试 对于下面的示例,我有两个问题: 它匹配我的控制器上不存在的操作,因此它并不真正匹配以查看我的控制器是否有这些操作,它只是匹配语法 不应该是可路由的不起作用,这可以追溯到上面的问题,即它没有检查我的控制器或routes.rb文件以查看路由是否应该存在 这一次通过了,一切都很好: it "should route to method1" do { :get => '/my_controller/method1' }.should route

我正试图为我的服装路线以及不存在的路线编写测试

对于下面的示例,我有两个问题:

  • 它匹配我的控制器上不存在的操作,因此它并不真正匹配以查看我的控制器是否有这些操作,它只是匹配语法
  • 不应该是可路由的
    不起作用,这可以追溯到上面的问题,即它没有检查我的控制器或
    routes.rb
    文件以查看路由是否应该存在
  • 这一次通过了,一切都很好:

    it "should route to method1" do
       { :get => '/my_controller/method1' }.should route_to(:controller => 'my_controller',
                                                         :action => 'method1')
    end
    
    这一个失败了,所以它甚至不检查我的控制器或路由文件中是否定义了方法zz

    it "should not route to zz" do
      { :get => '/my_controller/zz' }.should_not be_routable 
    end
    
    我得到的错误是:

    MyController routing zz should route to rescan
         Failure/Error: { :get => '/my_controller/zz' }.should_not be_routable
           expected {:get=>"/client_rescan/zz"} not to be routable, but it routes to {:controller=>"my_controller", :action=>"zz"}
    
     Failure/Error: { :post => '/my_controller' }.should_not be_routable
       expected {:post=>"/my_controller"} not to be routable, but it routes to {:controller=>"my_controller", :action=>"index"}
    
    所以它显然根本不看我的路由文件

    这是另一个例子,它不查看我的路由文件,在我的路由中,我有'resources:client_rescan,:only=>[:index]',当我执行
    rake routes
    时,它不会按预期显示delete,但测试不会查看这些:

    it "should not have route to delete" do
      { :delete => '/my_controller/1'}.should_not be_routable
    end
    
    我失败的原因如下。看起来它甚至没有看到删除功能:

     Failure/Error: { :delete => '/my_controller/1'}.should_not be_routable
       expected {:delete=>"/my_controller/1"} not to be routable, but it routes to {:controller=>"my_controller", :action=>"1"}
    
    另一个问题是我在测试中发布到索引的路径:

    it "should not have route to post" do
      { :post => '/my_controller' }.should_not be_routable
    end
    
    我遇到的失败是:

    MyController routing zz should route to rescan
         Failure/Error: { :get => '/my_controller/zz' }.should_not be_routable
           expected {:get=>"/client_rescan/zz"} not to be routable, but it routes to {:controller=>"my_controller", :action=>"zz"}
    
     Failure/Error: { :post => '/my_controller' }.should_not be_routable
       expected {:post=>"/my_controller"} not to be routable, but it routes to {:controller=>"my_controller", :action=>"index"}
    
    这是my routes.rb文件的内容

    require 'resque/server'
    require 'resque_scheduler'
    
    Cdc::Application.routes.draw do
    
      mount Resque::Server.new, :at => 'resque'
      Resque.schedule = YAML.load_file(File.join(File.dirname(__FILE__), 'resque_schedule.yml')) # load the schedule
    
      devise_for :users, :controllers => { :sessions => "sessions", :registrations => "registrations" }
    
    
    
      [:assessments, :security_assessments, :privacy_assessments].each do |assessment_type|
        resources assessment_type, :controller => :assessments do
          resources :rsz do
            post 'review', :on => :member
            get 'judgement', :on => :member
          end
    
          get :judgement, :on => :member
    
          resources :samples do
            get 'download', :on => :member
          end
    
          resources :asm_reviews do
            post :request_review, :on => :collection
          end
        end
      end
    
    
    
      resources :account_creator
      match "/images/captcha/*file_name" => "captcha#show"
    
      ## this is where my route is!! :)
    
      resources :my_controller, :only => [:index] do
        collection do
          get :rescan
          get :cancel
        end
      end
    
      match "alert_queue/words" => "alert_queue#words"
      resources :alert_queue
    
      match "calls_to_action/start/:id" => "calls_to_action#start", :id => /\d+/
      match "calls_to_action/close/:id" => "calls_to_action#close", :id => /\d+/
      match "calls_to_action/comment/:id" => "calls_to_action#comment", :id => /\d+/
      match "calls_to_action/multiclose" => "calls_to_action#multiclose"
      match "calls_to_action/multiscan" => "calls_to_action#multiscan"
    
      match "application_instances/multiclose" => "application_instances#multiclose"
      match "application_instances/multiscan" => "application_instances#multiscan"
    
      resources :code_categories do
        resources :code_families do
          resources :code_family_versions
        end
      end
    
      resources :code_policy_items
    
    
      resources :application_instances do
        collection do
          post :resque_statuses
        end
    
        resources :code_indices
        resources :application_analysis
    
        get "smali/:smali_path", :as => :smali, :on => :member, :action => :smali, :smali_path => /.*/
        member do
          get :file
          get :strings
          get :dump
          get :alerts
          get :correlations
          get :signers
          get :icon
          get :resque_status
          get :assets
          get :new_code_index
          get :class_list
          get :heuristic_hits
          get :engine_artifacts
          post :rescan
          post :attach_artifact
          post :engine_artifact, :action => :attach_engine_artifact
          resources :alerts
        end
    
        post "multiscan", :on => :collection, :action => :multiscan
        post "multiclose", :on => :collection, :action=> :multiclose
        post "engines/:engine_name/:engine_version/assertions/:cookie",
             :on => :member, :action => :register_assertion_set, :as => :register_assertion_set,
             :engine_name => /[^\/]+/, :engine_version => /[^\/]+/, :cookie => /[^\/]+/
        post "engines/:engine_name/:engine_version/network_data",
             :on => :member, :action => :register_network_data, :as => :register_network_data,
             :engine_name => /[^\/]+/, :engine_version => /[^\/]+/
    
        post "assets", :on => :member, :action => :register_asset_set, :as => :register_asset_set
      end
    
      # index gets the list of families, show gets the assertion types for that family
      resources :assertion_families
    
      resources :artifacts
    
      resources :dashboard do
        collection do
          get :last_app_instance
        end
      end
    
      match '/direct_downloads/' => 'direct_downloads#index'
    
      root :to => "stats#index"
      match '/' => 'stats#index'
      match 'explorer/query/:format' => 'explorer#query'
      match '/:controller(/:action(/:id))'
    end
    

    问题是这一行路由。rb:

    match '/:controller(/:action(/:id))'
    
    这是一条综合路线,将匹配例如/abc/xyz到控制器abc和动作xyz


    最好不要使用“捕获所有路由”,而是只公开您想要的功能。

    问题在于这一行路由。rb:

    match '/:controller(/:action(/:id))'
    
    这是一条综合路线,将匹配例如/abc/xyz到控制器abc和动作xyz


    最好不要使用catch-all-routes,只公开您想要的功能。

    最后一次测试是通过还是失败?如果失败,你会得到什么错误?对不起,我刚刚用错误更新了问题。所以非常想
    ,但它路由到{:controller=>“my_controller”,:action=>“1”
    @Meena对不起,但是你的评论“非常想,但它路由到”没有任何意义。你能重新阅读并更新它吗?@99miles很抱歉,我没有解释太多,因为我把响应作为qeustion主体的一部分,所以人们不必阅读评论。因此我得到的错误与上面相同,它是:`Failure/error:{:delete=>'/my_controller/1}。不应该是可路由的吗{:delete=>“/my_controller/1”}不可路由,但它路由到{:controller=>“my_controller”,:action=>“1”}`你能把routes.rb文件的内容和rake routes的输出一起发布吗?最后一次测试通过了还是失败了?如果失败了,你会得到什么错误?对不起,我刚刚用错误更新了这个问题。所以我非常想
    ,但它会路由到{:controller=>“my_controller”,:action=>“1”
    @Meena对不起,但是你的评论”所以很多人都在想,但它会转到“没有任何意义。你能重新阅读并更新它吗?@99miles很抱歉,我没有解释太多,因为我将响应作为qeustion主体的一部分,所以人们不必阅读注释。因此,我得到的错误与上面相同,它是:`Failure/error:{:delete=>'/my_controller/1'}。不应该是可路由的。预期{:delete=>“/my_controller/1”}不应该是可路由的,但它会路由到{:controller=>“my_controller”,:action=>“1”}`你能把routes.rb文件的内容和rake routes的输出一起发布吗?没问题,很乐意帮忙!:)给每一个用这个注定了未来开发者命运的承包商一个大拳头握手!没问题,很乐意帮忙!:)给每一个用这个注定了未来开发者命运的承包商一个大拳头握手!