gpt4 book ai didi

ruby-on-rails - 测试一条路线时 Rspec 未定义方法 `route_to'?

转载 作者:数据小太阳 更新时间:2023-10-29 07:44:55 24 4
gpt4 key购买 nike

我是 Rspec 的新手,正在尝试测试我的应用程序中的一条路线。我已经安装了 Rspec 并将路由文件包含在 spec/routing/routes_spec.rb 中。

我的规范如下:

require "spec_helper"

describe "Routes" do
it "routes get index" do
expect(:get => "simulations").to route_to(
:controller => "simulations",
:action => "index"
)
end
end

我收到这个错误:

Routes routes get index
Failure/Error: expect(:get => "simulations").to route_to(
NoMethodError:
undefined method `route_to' for #<RSpec::ExampleGroups::Routes:0x007fc32d2f70b8 @__memoized=nil>
# ./spec/routing/routes_spec.rb:6:in `block (2 levels) in <top (required)>'

关于为什么 route_to 未定义的任何想法?我已验证该路线确实有效。

最佳答案

在 Rspec 3 中你应该require 'rails_helper' 而不是 require 'spec_helper'

关于ruby-on-rails - 测试一条路线时 Rspec 未定义方法 `route_to'?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31734826/

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