【问题标题】:Rspec no route matchesRspec没有路由匹配
【发布时间】:2012-06-17 20:06:45
【问题描述】:

我在使用 rspec 时遇到以下错误:

1) LandingController landing#index returns http success
 Failure/Error: get :index
 ActionController::RoutingError:
   No route matches {:controller=>"landing"}
 # ./spec/controllers/landing_controller_spec.rb:7:in `block (3 levels) in <top (required)>'

这是测试

require 'spec_helper'

describe LandingController do

  describe "landing#index" do
    it "returns http success" do
      get :index
      response.should be_success
    end
  end

end

我将它安装为root :to =&gt; 'landing#index'。所有其他测试都通过了,只有这个测试失败了,有人可以帮我理解为什么吗?

为了完整起见,这是rake routes的输出

root                         /                                      landing#index
auth_google_oauth2_callback  /auth/google_oauth2/callback(.:format) sessions#create
                    signout  /signout(.:format)                     sessions#destroy
                  dashboard  /dashboard(.:format)                   dashboard#index

【问题讨论】:

    标签: ruby-on-rails ruby-on-rails-3 testing rspec rspec2


    【解决方案1】:

    如果您使用的是 Spork,如果您更新了路由,则可能需要重新启动服务器。

    【讨论】:

      【解决方案2】:

      您是否尝试使用get '/' 访问根页面?应该工作。

      【讨论】:

      • 是的,我试过了。它失败了ActionController::RoutingError: No route matches {:controller=&gt;"landing", :action=&gt;"/"}`
      猜你喜欢
      • 2014-09-27
      • 2019-05-25
      • 2017-04-02
      • 2018-03-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多