【问题标题】:Rails / RSpec match a Rails match routeRails / RSpec 匹配 Rails 匹配路由
【发布时间】:2011-05-21 19:16:18
【问题描述】:

我在为我的某些路线编写规范时遇到了一些麻烦。我几乎在任何轨道匹配路线上都遇到了这个问题。代码如下:

在 routes.rb 中

match "/:id" => "home#order"

在 home_controller.rb 中

def order
  respond_to do |format|
    format.html { render :layout => 'order' }
  end
end

在 home_controller_spec.rb 中:

it "should render the order layout" do
  get :order
  response.layout.should == 'layouts/order'
end

rake 路线有:

/:id(.:format)                      {:controller=>"home", :action=>"order"}

但是,规范抛出了这个异常:

  1) HomeController when not signed in should render the order layout
     Failure/Error: get :order
     ActionController::RoutingError:
       No route matches {:controller=>"home", :action=>"order"}

我做错了什么?

【问题讨论】:

    标签: ruby-on-rails rspec routes


    【解决方案1】:

    我认为

    get :order
    

    仅当您使用命名路由时才有效。试试吧

    get "/1"
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-08-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-08-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多