【问题标题】:No route matches when using Rack application with Rails and Rspc使用带有 Rails 和 Rspc 的 Rack 应用程序时没有路由匹配
【发布时间】:2015-07-13 18:19:03
【问题描述】:

自从在我的 Rails 代码中将一些代码移动到 Rack 应用程序后,我一直遇到控制器规范问题。当作为服务器运行时,路由可以完美运行,而不是通过 Rspec。

这是我的路线定义:

match ':username', to: Rack::CatchAllRouter.new, constraints: { format: 'html' }, via: [:get, :put, :patch]

以下代码是我的控制器规格:

describe UsersController do
  describe "#show" do
    subject { get :show, username: 'test-user' }
    it { is_expected.to be_successful }
    it { is_expected.to render_template('users/show') }
  end
end

我收到的错误如下:

No route matches {:action=>"show", :controller=>"users", :username=>"test-user"}

我不明白为什么这必须通过路由器,因为这应该只是测试控制器而不是通过整个请求设置。

我还可以通过请求规范和构建 URL 来实现这一点,而不是控制器规范。

【问题讨论】:

  • 您找到解决方案了吗?我也有同样的问题。

标签: ruby-on-rails ruby rspec routing rack


【解决方案1】:

可能您在路由中的参数与您在规范中发送的参数不匹配

【讨论】:

  • 参数匹配,当我使用 'users#show' 而不是机架应用程序时,它的路由很好
猜你喜欢
  • 1970-01-01
  • 2018-06-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多