"visitors#comingsoon" resources :visitors Controller : class Vi-6ren">
gpt4 book ai didi

ruby-on-rails - 在 get 请求上使用 rspec 没有路由匹配

转载 作者:数据小太阳 更新时间:2023-10-29 08:51:38 25 4
gpt4 key购买 nike

我忘记了什么?

路线:

  get "/comingsoon" => "visitors#comingsoon"
resources :visitors

Controller :

class VisitorsController < ApplicationController
def comingsoon
@new_visitor = Visitor.new
end
end

规范:

require 'spec_helper'

describe VisitorsController do
describe "GET /comingsoon" do
it "should be happy" do
get "/comingsoon"
response.should be_success
end
end
end

结果如下:

✗ rspec spec/controllers/visitors_controller_spec.rb
F

Failures:

1) VisitorsController GET /comingsoon should be valid
Failure/Error: get "/comingsoon"
ActionController::RoutingError:
No route matches {:controller=>"visitors", :action=>"/comingsoon"}
# ./spec/controllers/visitors_controller_spec.rb:7:in `block (3 levels) in <top (required)>'

Finished in 0.14226 seconds
1 example, 1 failure

Failed examples:

rspec ./spec/controllers/visitors_controller_spec.rb:6 # VisitorsController GET /comingsoon should be valid

我忘记了什么?

最佳答案

在你的规范文件中替换 get "/comingsoon" 使用 get "comingsoon"

当您使用 rspec 指定 Controller 时,http 动词(get、post、put、delete)的操作数是 Controller 的操作而不是 url。

关于ruby-on-rails - 在 get 请求上使用 rspec 没有路由匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11378927/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com