问:我做错了route_to方法仍然是不确定的?
我很新的这一点,但我想开发通过RSpec的宝石的一些路线测试。
我的问题是,我得到了错误:
undefined method `route_to' for #<RSpec::ExampleGroups::RouteToHomepage
我已经通过此查询的API一看,我已经做了以下内容:
Install gem 'rspec-rails'
在rails_helper.rb
require 'rspec/rails'
在我routing_spec.rb(我在哪里写的路由)
require 'rails_helper'
describe "route to homepage" do
it "routes /home to index" do
expect(:get => "/homes").to route_to(
action: "index"
)
end
end
究竟是什么,我需要更换或添加,所以在定义“route_to”的方法?我已经读左右,显然它在“RSpec的护栏”的宝石,这是我定义的,并且已经包括在内。
路由功能是由
:type => :routing
标记,或者如果您已设置config.infer_spec_type_from_file_location!
通过将它们放置在spec/routing
。
你没有说在routing_spec.rb
的位置,但如果它的文件夹里面spec/routing/
,那么你可以选择启用上面的配置选项。
否则,或在一般情况下,你必须这样做:
require 'rails_helper'
describe "route to homepage", type: :routing do
it "routes /home to index" do
expect(:get => "/homes").to route_to(
action: "index"
)
end
end
这样做将包括必要的RSpec的助手定义route_to
,其他方法之一。