Minitest 中的匿名控制器 w/Rails [英] Anonymous controller in Minitest w/ Rails
本文介绍了Minitest 中的匿名控制器 w/Rails的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在从 RSpec 转换到 Minitest 时,我遇到了一个小问题,Google 没有提供任何帮助,那就是弄清楚如何做这样的事情:
While converting from RSpec to Minitest I ran into a slight issue that Google has not helped with one bit, and that's figuring out how to do something like this:
describe ApplicationController do
controller do
def index
render nothing: true
end
end
it "should catch bad slugs" do
get :index, slug: "bad%20slug"
response.code.should eq("403")
end
end
使用 Minitest.有没有办法在 Minitest 内部创建这样的匿名控制器,或者是否有文档可以帮助我学习如何使用 minitest 测试控制器?
with Minitest. Is there a way to create anonymous controllers like this inside of Minitest or is there documentation that could help me learn how to test controllers with minitest?
推荐答案
我认为不支持匿名控制器.不要使用 DSL 创建控制器,而是尝试在测试中定义控制器.
I don't think anonymous controllers are supported. Instead of using a DSL to create a controller, try defining a controller in your test.
class SlugTestController < ApplicationController
def index
render nothing: true
end
end
describe SlugTestController do
it "should catch bad slugs" do
get :index, slug: "bad%20slug"
response.code.must_equal "403"
end
end
这篇关于Minitest 中的匿名控制器 w/Rails的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文