gpt4 book ai didi

ruby-on-rails - 如何让 RSpec 测试子目录中的 Controller ?

转载 作者:行者123 更新时间:2023-12-04 03:00:43 24 4
gpt4 key购买 nike

我有一些 Controller 位于 Controller 文件夹的子域中。

例如,我在 app/controllers/api/v1/offers_controller.rb 中有一个 Controller ,如下所示:

class Api::V1::OffersController < ApplicationController
respond_to :json

def index
...some code here
end
end

我尝试在 spec/controllers/api/v1/offers_controller.rb 中放置一个 Controller ,如下所示:

需要'spec_helper'

descripe Api::V1::OffersController do
describe "GET 'index'" do
it "returns http success" do
get 'index'
response.should be_success
end
end
end

但是,当我运行 rspec spec 时,这个测试根本没有运行。我也试过把它放在spec/controllers目录下,命名为api_v1_offers_controller.rb,还是测试不了。

如何为这些类型的 Controller 编写 RSpec 测试?

最佳答案

实际上我给文件命名的方式似乎是个错误。似乎所有 RSpec 测试都需要结束它 _spec

关于ruby-on-rails - 如何让 RSpec 测试子目录中的 Controller ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14737717/

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