我在 Rails 中创建一个 API,并使用versionist来处理版本。我想测试 API 控制器,但无法创建有效请求。
我的控制器:
class Api::V1::ItemsController < Api::V1::BaseController
def index
render json:'anything'
end
end
我的规格:
describe Api::V1::ItemsController do
describe "#create" do
it "shows items" do
get :index, format: :json
end
end
end
路线.rb:
scope '/api' do
api_version(:module => "Api::V1", :path => {:value => "v1"}, :default => true) do
resources :items
end
end
测试不检查任何东西。尽管如此,它还是引发了一个错误:
Failure/Error: get :index, format: :json
ActionController::RoutingError:
No route matches {:format=>:json, :controller=>"api/v1/items", :action=>"index"}
我想:controller
请求中的密钥有问题,但我不知道如何修复它......