【问题标题】:error test routing with rspec使用 rspec 进行错误测试路由
【发布时间】:2012-07-14 11:07:11
【问题描述】:

我的config/routes.rb 中有这个资源

resources :users, :path => "u" do
 resources :boards, :controller => 'users/boards', :path => "collections"
end

在我的spec/routing/boards_routing_spec.rb 我有:

require "spec_helper"

describe Users::BoardsController do
  describe "routing" do

    it "routes to #index" do
      get("/u/:user_id/collections").should route_to("users/boards#index")
    end

  end
end

我得到下一个错误:

Failures:

  1) Users::BoardsController routing routes to #index
     Failure/Error: get("/u/:user_id/collections").should route_to("users/boards#index")
       The recognized options <{"action"=>"index", "controller"=>"users/boards", "user_id"=>":user_id"}> did not match <{"controller"=>"users/boards", "action"=>"index"}>, difference: <{"user_id"=>":user_id"}>.
       <{"controller"=>"users/boards", "action"=>"index"}> expected but was
       <{"action"=>"index", "controller"=>"users/boards", "user_id"=>":user_id"}>.
     # ./spec/routing/boards_routing_spec.rb:7:in `block (3 levels) in <top (required)>'

我正在为用户使用 Devise 2.0。

我该如何解决这个错误?

【问题讨论】:

    标签: ruby-on-rails unit-testing rspec tdd


    【解决方案1】:

    错误已修复:

    require "spec_helper"
    
    describe Users::BoardsController do
      describe "routing" do
    
        it "routes to #index" do
          get("/u/hyperrjas/collections").should route_to("users/boards#index", :user_id => "hyperrjas")
        end
    end
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-08-21
      • 2011-08-04
      • 1970-01-01
      • 2012-02-12
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多