【发布时间】:2021-01-19 13:10:16
【问题描述】:
我有一个新近启动的 Rails 应用程序,并且我也使用 Rspec 构建了该项目,因此它生成了大量测试。但是spec/routing 文件夹中的所有这些测试都失败了。
这是我的my_models_routing_spec.rb 文件:
RSpec.describe MyModelController, type: :routing do
describe "routing" do
it "routes to #index" do
expect(get: "/my_models").to route_to("my_models#index")
end
end
end
这是错误信息:
1) MyModelController routing routes to #index
Failure/Error: expect(get: "/my_model").to route_to("my_model#index")
No route matches "/my_model"
# ./spec/routing/my_model_routing_spec.rb:6:in `block (3 levels) in <main>'
我认为这是因为我的路线被限定在语言环境中:
Rails.application.routes.draw do
scope "/:locale", locale: /#{I18n.available_locales.join("|")}/ do
root to: "home#index"
resources :my_models
end
get "/*path", to: redirect("/#{I18n.default_locale}/%{path}", status: 302),
constraints: { path: /(?!(#{I18n.available_locales.join("|")})\/).*/ },
format: false
end
这是所有测试的情况。有没有办法配置 Rspec 以考虑语言环境?提前致谢。
【问题讨论】:
标签: ruby-on-rails rspec